2024-01-24 15:32:16 +08:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
2024-02-20 19:24:56 +08:00
|
|
|
PACK_LIST=("git" "zsh")
|
2024-01-25 15:23:41 +08:00
|
|
|
# 脚本根地址
|
2024-02-02 00:15:11 +08:00
|
|
|
ROOT_URL="https://gitea.whlug.cn/xunmi/x/"
|
2024-03-12 01:00:21 +08:00
|
|
|
# 脚本安装默认路径
|
|
|
|
ROOT_INSTALL="/opt/xunmi"
|
|
|
|
|
2024-01-24 15:32:16 +08:00
|
|
|
###############################################################################
|
|
|
|
# 终端配色 #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
readonly COLOUR_RESET='\e[0m'
|
|
|
|
readonly aCOLOUR=(
|
|
|
|
'\e[38;5;154m' # 0: 亮绿
|
|
|
|
'\e[1m' # 1: 白
|
|
|
|
'\e[90m' # 2: 灰
|
|
|
|
'\e[91m' # 3: 红
|
|
|
|
'\e[32m' # 4: 绿
|
|
|
|
)
|
|
|
|
Show() {
|
|
|
|
if (($1 == 0)); then
|
|
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} 成功 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
|
|
elif (($1 == 1)); then
|
|
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]} 失败 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
|
|
exit 1
|
|
|
|
elif (($1 == 2)); then
|
|
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]} 信息 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
GreyStart() {
|
|
|
|
echo -e "${aCOLOUR[2]}\c"
|
|
|
|
}
|
|
|
|
ColorReset() {
|
|
|
|
echo -e "$COLOUR_RESET\c"
|
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# 函数 #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# 更新包管理器
|
2024-03-12 01:00:21 +08:00
|
|
|
Update_PKG() {
|
2024-01-24 15:32:16 +08:00
|
|
|
Show 2 "更新包管理器..."
|
2024-01-25 15:23:41 +08:00
|
|
|
GreyStart
|
2024-02-20 17:52:10 +08:00
|
|
|
if [ -x "$(command -v oma)" ]; then
|
|
|
|
sudo oma refresh
|
|
|
|
elif [ -x "$(command -v apt)" ]; then
|
2024-01-25 15:23:41 +08:00
|
|
|
sudo apt-get update -qq
|
2024-01-24 15:32:16 +08:00
|
|
|
elif [ -x "$(command -v yum)" ]; then
|
2024-01-25 15:23:41 +08:00
|
|
|
sudo yum update
|
2024-01-24 15:32:16 +08:00
|
|
|
fi
|
|
|
|
ColorReset
|
|
|
|
Show 0 "包管理器更新完毕"
|
|
|
|
}
|
|
|
|
|
2024-02-20 19:24:56 +08:00
|
|
|
# 安装依赖
|
|
|
|
Install_PKG() {
|
2024-03-12 01:00:21 +08:00
|
|
|
Update_PKG
|
2024-01-24 15:32:16 +08:00
|
|
|
for ((i = 0; i < ${#PACK_LIST[@]}; i++)); do
|
|
|
|
pack=${PACK_LIST[i]}
|
2024-03-12 01:00:21 +08:00
|
|
|
[ -x "$(command -v $pack)" ] && continue
|
2024-01-24 15:32:16 +08:00
|
|
|
Show 2 "安装必要的依赖项: ${aCOLOUR[4]} $pack $COLOUR_RESET"
|
|
|
|
GreyStart
|
2024-02-20 17:52:10 +08:00
|
|
|
if [ -x "$(command -v oma)" ]; then
|
2024-02-20 19:24:56 +08:00
|
|
|
sudo oma install -y $pack
|
2024-02-20 17:52:10 +08:00
|
|
|
elif [ -x "$(command -v apt)" ]; then
|
2024-01-24 15:32:16 +08:00
|
|
|
sudo apt -y install $pack
|
|
|
|
elif [ -x "$(command -v yum)" ]; then
|
|
|
|
sudo yum install -y $pack
|
2024-02-20 17:52:10 +08:00
|
|
|
elif [ -x "$(command -v pacman)" ]; then
|
|
|
|
sudo pacman -Sy --needed $pack
|
2024-01-24 15:32:16 +08:00
|
|
|
else
|
|
|
|
Show 1 "未找到包管理器, 您需要手动安装: ${aCOLOUR[5]} $pack $COLOUR_RESET"
|
|
|
|
fi
|
|
|
|
ColorReset
|
|
|
|
done
|
|
|
|
Show 0 "依赖安装完成"
|
|
|
|
}
|
|
|
|
|
2024-02-04 17:56:33 +08:00
|
|
|
Download_X(){
|
2024-02-20 17:52:10 +08:00
|
|
|
Show 0 "开始下载配置言灵"
|
2024-02-04 17:56:33 +08:00
|
|
|
GreyStart
|
|
|
|
x_dir=$ROOT_INSTALL/x
|
|
|
|
sudo rm -vrf $x_dir
|
|
|
|
sudo git clone $ROOT_URL $x_dir || Show 1 "言灵拉去失败"
|
2024-03-12 01:00:21 +08:00
|
|
|
mkdir -vp $HOME/.config/xunmi
|
|
|
|
echo "言灵一路径=$ROOT_INSTALL" >> $HOME/.config/xunmi/信息
|
2024-02-04 17:56:33 +08:00
|
|
|
ColorReset
|
|
|
|
}
|
|
|
|
|
2024-02-20 17:52:10 +08:00
|
|
|
#################################################################
|
2024-02-20 19:24:56 +08:00
|
|
|
# 主函数(main) #
|
2024-02-20 17:52:10 +08:00
|
|
|
#################################################################
|
2024-02-04 17:56:33 +08:00
|
|
|
|
2024-03-12 01:00:21 +08:00
|
|
|
Install_PKG
|
|
|
|
Download_X
|
|
|
|
sudo chown -R $USER:$USER $ROOT_INSTALL
|
|
|
|
[ -f "安装.zsh" ] && zsh 安装.zsh || zsh $x_dir/安装.zsh
|
2024-02-20 19:24:56 +08:00
|
|
|
exec zsh
|