2024-09-23 13:22:40 +08:00
|
|
|
|
#!/bin/bash
|
2024-09-24 18:29:44 +08:00
|
|
|
|
if [[ $UID != 0 ]]; then
|
2025-06-06 01:25:11 +08:00
|
|
|
|
echo "请以root权限执行该脚本"
|
|
|
|
|
exit
|
2024-09-24 18:29:44 +08:00
|
|
|
|
fi
|
2024-09-24 01:48:30 +08:00
|
|
|
|
|
2025-06-06 01:25:11 +08:00
|
|
|
|
if ! command -v git &>/dev/null; then
|
|
|
|
|
if [[ -f "/usr/bin/apt-get" ]]; then
|
|
|
|
|
apt-get update -y
|
|
|
|
|
apt-get install git -y
|
|
|
|
|
elif [[ -f "/usr/bin/apt" ]]; then
|
|
|
|
|
apt update -y
|
|
|
|
|
apt install git -y
|
|
|
|
|
elif [[ -f "/usr/bin/pacman" ]]; then
|
|
|
|
|
pacman -Syu --noconfirm
|
|
|
|
|
pacman -Sy --noconfirm git
|
|
|
|
|
else
|
|
|
|
|
echo "git未安装"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
2024-09-24 01:48:30 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2024-09-23 13:22:40 +08:00
|
|
|
|
declare path
|
|
|
|
|
echo "请输入脚本的安装位置"
|
|
|
|
|
read -p "默认 /var/script:" path
|
2025-06-06 01:25:11 +08:00
|
|
|
|
if [[ -z $path ]]; then
|
|
|
|
|
path="/var/script"
|
2024-09-23 13:22:40 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2024-09-23 13:27:20 +08:00
|
|
|
|
mkdir -p "$path"
|
2024-09-23 17:07:33 +08:00
|
|
|
|
rm -rf "$path/linuxtool"
|
2024-09-23 13:22:40 +08:00
|
|
|
|
|
2024-09-24 01:48:30 +08:00
|
|
|
|
declare -A url_dick
|
|
|
|
|
declare -a url_arr
|
|
|
|
|
declare url_number=0
|
|
|
|
|
declare url_pick
|
|
|
|
|
declare url
|
|
|
|
|
echo "请选择脚本的下载地址"
|
|
|
|
|
url_dick['github(default)']='https://github.com/lsy2246/linuxtool.git'
|
|
|
|
|
url_dick['gitee']='https://gitee.com/lsy22/linuxtool.git'
|
|
|
|
|
|
2025-06-06 01:25:11 +08:00
|
|
|
|
for i in "${!url_dick[@]}"; do
|
|
|
|
|
url_number=$((url_number + 1))
|
|
|
|
|
url_arr[$url_number]=$i
|
|
|
|
|
echo "${url_number}.${i}"
|
2024-09-24 01:48:30 +08:00
|
|
|
|
done
|
2024-09-23 14:57:22 +08:00
|
|
|
|
|
2024-09-24 01:48:30 +08:00
|
|
|
|
read -p "请输入:" url_pick
|
|
|
|
|
|
|
|
|
|
if [[ $url_pick =~ [1-${#url_dick[@]}] ]]; then
|
2025-06-06 01:25:11 +08:00
|
|
|
|
url=${url_dick[${url_arr[$url_pick]}]}
|
2024-09-24 01:48:30 +08:00
|
|
|
|
else
|
|
|
|
|
url='https://github.com/lsy2246/linuxtool.git'
|
|
|
|
|
fi
|
|
|
|
|
|
2024-09-24 02:06:59 +08:00
|
|
|
|
echo "正在下载脚本中"
|
2025-06-06 01:25:11 +08:00
|
|
|
|
git clone "$url" "$path/linuxtool" &>/dev/null
|
2024-09-24 01:48:30 +08:00
|
|
|
|
|
2025-06-06 01:25:11 +08:00
|
|
|
|
if ! [[ -d "${path}/linuxtool" ]]; then
|
2024-09-23 14:57:22 +08:00
|
|
|
|
echo "脚本下载失败"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
2024-09-24 01:48:30 +08:00
|
|
|
|
|
2025-06-06 01:25:11 +08:00
|
|
|
|
chmod +x "$path/linuxtool/run.sh" &>/dev/null
|
2024-09-23 13:22:40 +08:00
|
|
|
|
|
2025-06-06 01:25:11 +08:00
|
|
|
|
# 创建软链接到 /usr/bin 目录
|
|
|
|
|
echo "正在创建软链接..."
|
|
|
|
|
ln -sf "$path/linuxtool/run.sh" "/usr/bin/tool"
|
|
|
|
|
chmod +x "/usr/bin/tool"
|
2024-11-19 00:00:28 +08:00
|
|
|
|
|
2025-06-06 01:25:11 +08:00
|
|
|
|
# 将工具路径写入环境变量配置
|
|
|
|
|
echo "tool='$path/linuxtool/run.sh'" >>/etc/profile
|
2024-09-24 18:08:50 +08:00
|
|
|
|
|
2024-09-23 13:43:09 +08:00
|
|
|
|
echo "工具箱已经安装成功"
|
|
|
|
|
echo "位置:${path}/linuxtool"
|
2024-09-26 19:31:17 +08:00
|
|
|
|
echo "命令:tool"
|
2024-11-22 20:10:11 +08:00
|
|
|
|
|
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
2025-06-06 01:25:11 +08:00
|
|
|
|
kill $PPID &>/dev/null
|
|
|
|
|
fi
|