linuxtool/Config/Manage/install.sh

93 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/bash
2024-09-24 18:29:44 +08:00
if [[ $UID != 0 ]]; then
echo "请以root权限执行该脚本"
exit
fi
2024-09-24 01:48:30 +08:00
if ! command -v git &> /dev/null; then
if [[ -f "/usr/bin/apt-get" ]];then
apt-get update -y
2024-09-24 18:29:44 +08:00
apt-get install git -y
2024-09-24 01:48:30 +08:00
elif [[ -f "/usr/bin/apt" ]];then
apt update -y
2024-09-24 18:29:44 +08:00
apt install git -y
2024-09-24 01:48:30 +08:00
elif [[ -f "/usr/bin/pacman" ]];then
pacman -Syu --noconfirm
pacman -Sy --noconfirm git
else
echo "git未安装"
exit
fi
fi
declare path
echo "请输入脚本的安装位置"
read -p "默认 /var/script" path
if [[ -z $path ]];then
path="/var/script"
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-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'
url_dick['gitlsy']='https://g.lsy22.com/lsy/linuxtool.git'
for i in "${!url_dick[@]}" ; do
url_number=$(( url_number+1 ))
url_arr[$url_number]=$i
echo "${url_number}.${i}"
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
url=${url_dick[${url_arr[$url_pick]}]}
else
url='https://github.com/lsy2246/linuxtool.git'
fi
echo "正在下载脚本中"
2024-09-24 01:48:30 +08:00
git clone "$url" "$path/linuxtool" &> /dev/null
if ! [[ -d "${path}/linuxtool" ]];then
2024-09-23 14:57:22 +08:00
echo "脚本下载失败"
exit
fi
2024-09-24 01:48:30 +08:00
2024-09-26 16:20:14 +08:00
chmod +x "$path/linuxtool/run.sh" &> /dev/null
2024-09-23 20:57:18 +08:00
if [[ -e "${HOME}/.bashrc" ]];then
sed -i '/alias tool.*/d' "${HOME}/.bashrc"
2024-09-26 16:20:14 +08:00
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "${HOME}/.bashrc"
2024-09-23 21:03:09 +08:00
source "${HOME}/.bashrc" &> /dev/null
2024-09-23 20:57:18 +08:00
fi
if [[ -e "${HOME}/.profile" ]];then
sed -i '/alias tool.*/d' "${HOME}/.profile"
2024-09-26 16:20:14 +08:00
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "${HOME}/.profile"
2024-09-23 21:03:09 +08:00
source "${HOME}/.profile" &> /dev/null
2024-09-23 20:57:18 +08:00
fi
2024-09-23 17:02:52 +08:00
2024-09-23 20:57:18 +08:00
if [[ -e "${HOME}/.zshrc" ]];then
sed -i '/alias tool.*/d' "${HOME}/.zshrc"
2024-09-26 16:20:14 +08:00
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "${HOME}/.zshrc"
2024-09-23 21:03:09 +08:00
source "${HOME}/.zshrc" &> /dev/null
2024-09-23 20:57:18 +08:00
fi
2024-09-24 18:08:50 +08:00
sed -i '/alias tool.*/d' "/etc/profile"
2024-09-26 16:20:14 +08:00
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "/etc/profile"
2024-09-24 18:08:50 +08:00
2024-09-26 16:20:14 +08:00
alias tool="$path/linuxtool/run.sh"
2024-09-23 17:02:52 +08:00
2024-09-23 13:43:09 +08:00
echo "工具箱已经安装成功"
echo "位置:${path}/linuxtool"
echo "命令tool"