2024-01-24 15:32:16 +08:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
2024-01-25 17:57:48 +08:00
|
|
|
# wget -qO- https://gitea.whlug.cn/xunmi/getLinux/raw/start.sh | bash
|
2024-01-24 15:32:16 +08:00
|
|
|
PACK_LIST=("wget" "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-01-25 15:23:41 +08:00
|
|
|
# 插件和依赖安装的路径
|
2024-01-24 15:32:16 +08:00
|
|
|
ROOT_INSTALL=/opt/xunmi
|
|
|
|
###############################################################################
|
|
|
|
# 终端配色 #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
readonly COLOUR_RESET='\e[0m'
|
|
|
|
readonly aCOLOUR=(
|
|
|
|
'\e[38;5;154m' # 0: 亮绿
|
|
|
|
'\e[1m' # 1: 白
|
|
|
|
'\e[90m' # 2: 灰
|
|
|
|
'\e[91m' # 3: 红
|
|
|
|
'\e[32m' # 4: 绿
|
|
|
|
'\e[33m' # 5: 黄
|
|
|
|
)
|
|
|
|
|
|
|
|
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"
|
|
|
|
elif (($1 == 3)); then
|
2024-02-02 00:15:11 +08:00
|
|
|
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[5]} 通知 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
|
2024-01-24 15:32:16 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
Warn() {
|
|
|
|
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
|
|
|
|
}
|
|
|
|
|
|
|
|
GreyStart() {
|
|
|
|
echo -e "${aCOLOUR[2]}\c"
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorReset() {
|
|
|
|
echo -e "$COLOUR_RESET\c"
|
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# 函数 #
|
|
|
|
###############################################################################
|
|
|
|
|
2024-01-25 15:23:41 +08:00
|
|
|
# 选择判断器
|
|
|
|
Select_Continue() {
|
2024-02-02 00:15:11 +08:00
|
|
|
Show 3 "$1((是/否 Yes/No))"
|
2024-01-25 15:23:41 +08:00
|
|
|
read r
|
|
|
|
if echo "$r" | grep -Eq "^[是Yy][Ee]?[Ss]?$";then
|
|
|
|
return 0
|
2024-01-25 17:41:32 +08:00
|
|
|
else
|
|
|
|
return 1
|
2024-01-25 15:23:41 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-01-24 15:32:16 +08:00
|
|
|
# 更新包管理器
|
|
|
|
Update_Package_Resource() {
|
|
|
|
Show 2 "更新包管理器..."
|
2024-01-25 15:23:41 +08:00
|
|
|
GreyStart
|
2024-01-24 15:32:16 +08:00
|
|
|
if [ -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 "包管理器更新完毕"
|
|
|
|
}
|
|
|
|
|
|
|
|
# 安装Zsh
|
|
|
|
Install_Zsh() {
|
2024-01-25 15:23:41 +08:00
|
|
|
Update_Package_Resource
|
2024-01-24 15:32:16 +08:00
|
|
|
for ((i = 0; i < ${#PACK_LIST[@]}; i++)); do
|
|
|
|
pack=${PACK_LIST[i]}
|
|
|
|
Show 2 "安装必要的依赖项: ${aCOLOUR[4]} $pack $COLOUR_RESET"
|
|
|
|
GreyStart
|
|
|
|
if [ -x "$(command -v apt)" ]; then
|
|
|
|
sudo apt -y install $pack
|
|
|
|
elif [ -x "$(command -v yum)" ]; then
|
|
|
|
sudo yum install -y $pack
|
2024-02-02 00:15:11 +08:00
|
|
|
elif [ -x "$(command -v pacman)" ]; then
|
|
|
|
sudo pacman -Sy --needed $pack
|
2024-01-24 15:32:16 +08:00
|
|
|
#elif [ -x "$(command -v paru)" ]; then
|
|
|
|
# paru -S zsh
|
|
|
|
else
|
|
|
|
Show 1 "未找到包管理器, 您需要手动安装: ${aCOLOUR[5]} $pack $COLOUR_RESET"
|
|
|
|
fi
|
|
|
|
ColorReset
|
|
|
|
done
|
|
|
|
Show 0 "依赖安装完成"
|
|
|
|
}
|
|
|
|
|
2024-01-25 15:23:41 +08:00
|
|
|
# 下载配置
|
2024-01-24 15:32:16 +08:00
|
|
|
Download_Config() {
|
|
|
|
# 创建下载文件的临时目录
|
2024-01-25 15:23:41 +08:00
|
|
|
Show 0 "正在进行插件下载与配置"
|
2024-01-24 15:32:16 +08:00
|
|
|
# 下载zsh扩展
|
2024-01-25 17:41:32 +08:00
|
|
|
GreyStart
|
2024-01-24 15:32:16 +08:00
|
|
|
ohmyzsh_dir=${ROOT_INSTALL}/oh-my-zsh
|
2024-02-02 00:15:11 +08:00
|
|
|
sudo rm -vrf $ohmyzsh_dir
|
|
|
|
sudo git clone https://gitcode.com/mirrors/ohmyzsh/ohmyzsh.git ${ohmyzsh_dir} || Show 1 "关键依赖下载失败"
|
2024-01-25 15:23:41 +08:00
|
|
|
cd ${ohmyzsh_dir}/custom/plugins/
|
|
|
|
sudo git clone https://gitcode.com/mirrors/zsh-users/zsh-autosuggestions.git
|
|
|
|
sudo git clone https://gitcode.com/mirrors/zsh-users/zsh-syntax-highlighting.git
|
|
|
|
# 下载预设配置
|
2024-02-02 00:15:11 +08:00
|
|
|
config_url=${ROOT_URL}raw/配置/zshrc
|
|
|
|
sudo wget -t 3 -q --show-progress -c "${config_url}" || Show 1 "无法下载预设配置( ${config_url} )"
|
2024-01-25 17:41:32 +08:00
|
|
|
sudo sed -i "s:export ZSH=/etc/oh-my-zsh:export ZSH=$ohmyzsh_dir:" zshrc
|
2024-01-25 15:23:41 +08:00
|
|
|
sudo mv zshrc /etc/skel/.zshrc
|
|
|
|
cp -v /etc/skel/.zshrc $HOME
|
2024-02-02 00:15:11 +08:00
|
|
|
cd $HOME
|
2024-01-24 15:32:16 +08:00
|
|
|
ColorReset
|
2024-01-24 17:41:15 +08:00
|
|
|
Show 2 "寻觅基础环境安装完成"
|
2024-01-24 15:32:16 +08:00
|
|
|
}
|
|
|
|
|
2024-01-25 15:23:41 +08:00
|
|
|
# 选配
|
|
|
|
Select_Config(){
|
|
|
|
if Select_Continue "将Zsh设置为默认命令行"; then
|
2024-01-25 17:41:32 +08:00
|
|
|
chsh -s /usr/bin/zsh
|
2024-02-02 00:15:11 +08:00
|
|
|
Show 0 "已将zsh设置为默认命令行"
|
|
|
|
else
|
|
|
|
Show 2 "如需将zsh设置为默认命令行请执行: 'chsh -s /usr/bin/zsh' "
|
2024-01-25 15:23:41 +08:00
|
|
|
fi
|
2024-02-02 00:15:11 +08:00
|
|
|
|
|
|
|
if Select_Continue "启动zsh"; then
|
|
|
|
Show 0 "将在程序结束后启动zsh"
|
|
|
|
ZSH_START=1
|
|
|
|
else
|
|
|
|
Show 2 "zsh未启动, 如需启动请执行: 'zsh' "
|
|
|
|
fi
|
|
|
|
|
2024-01-25 15:23:41 +08:00
|
|
|
}
|
|
|
|
|
2024-01-24 15:32:16 +08:00
|
|
|
Install_Zsh
|
|
|
|
Download_Config
|
2024-01-25 15:23:41 +08:00
|
|
|
Select_Config
|
2024-02-02 00:15:11 +08:00
|
|
|
|
|
|
|
if [ "$ZSH_START" ]; then
|
|
|
|
exec zsh
|
|
|
|
fi
|