12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/bin/bash
- function cd_dir {
- local dir_path=$1
- # 检查目录是否存在
- if [ ! -d "$dir_path" ]; then
- echo "Directory $dir_path does not exist. Creating..."
- mkdir -p "$dir_path"
- fi
- cd "$dir_path" || exit
- }
- # 定义一个函数,用于执行安装脚本
- execute_install_script() {
- if [ -e "install.sh" ] && [ -x "install.sh" ]; then
- echo "Executing install.sh in $PWD ..."
- chmod +x install.sh
- # ./install.sh
- fi
- }
- # 安装包检测
- function check_and_install {
- for package_name in "$@"
- do
- if ! dpkg -l $package_name &> /dev/null
- then
- echo "$package_name not found. Installing..."
- sudo apt-get update
- sudo apt-get install $package_name -y
- else
- echo "$package_name already installed."
- fi
- done
- }
- # 定义函数,根据路径执行install.sh脚本
- run_install() {
- echo "------------------Installing $1------------------"
- now_path=$(pwd)
- dir="$1" # 获取install.sh所在的目录名
- sh_name=$2
- cd "$dir" || exit # 进入该目录
- ./"$sh_name" # 执行配置的安装脚本
- cd "$now_path" || exit # 回到上一级目录
- }
- check_and_install g++ gcc make autoconf automake libunwind-dev libpcl-dev libopencv-dev libpcap-dev
- # 逐行读取文件内容,根据=后面的值执行相应操作
- while read line
- do
- var=$(echo "$line" | cut -d ':' -f 2) # 提取=后面的值
- if [ "$var" = "ON" ]
- then
- key=$(echo "$line" | cut -d ':' -f 1) # 提取=前面的键
- sh_name=$(echo "$line" | cut -d ':' -f 3) # 提取=前面的键
- if [ -d "$key" ]
- then
- run_install "$key" "$sh_name" # 根据路径执行install.sh脚本
- else
- echo "dir not exist:$key"
- fi
- elif [ "$var" != "" ]
- then
- echo "Unknow status: $var"
- fi
- done < config.txt
- exit
|