[优化] 优化 start.sh 安装脚本, 修复可能出现的异常

This commit is contained in:
寻觅(樊旭东) 2024-02-02 00:15:11 +08:00
parent 51d5224e2d
commit a6d3494fc5
3 changed files with 40 additions and 31 deletions

View File

@ -2,4 +2,4 @@
寻觅使用的Linux配置脚本
如无zsh请先使用 `wget -qO- https://gitea.whlug.cn/xunmi/getLinux/raw/start.sh | bash` 命令安装基础模块
如无zsh请先使用 `wget -O- https://gitea.whlug.cn/xunmi/x/raw/start.sh | bash` 命令安装基础模块

View File

@ -3,10 +3,9 @@
# wget -qO- https://gitea.whlug.cn/xunmi/getLinux/raw/start.sh | bash
PACK_LIST=("wget" "git" "zsh")
# 脚本根地址
ROOT_URL="https://gitea.whlug.cn/xunmi/getLinux/"
ROOT_URL="https://gitea.whlug.cn/xunmi/x/"
# 插件和依赖安装的路径
ROOT_INSTALL=/opt/xunmi
###############################################################################
# 终端配色 #
###############################################################################
@ -22,19 +21,15 @@ readonly aCOLOUR=(
)
Show() {
# OK
if (($1 == 0)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} 成功 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# FAILED
elif (($1 == 1)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]} 失败 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
exit 1
# INFO
elif (($1 == 2)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]} 信息 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# NOTICE
elif (($1 == 3)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[5]} 警告 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[5]} 通知 $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
fi
}
@ -56,7 +51,7 @@ ColorReset() {
# 选择判断器
Select_Continue() {
Show 0 "$1((是/否 Yes/No))"
Show 3 "$1((是/否 Yes/No))"
read r
if echo "$r" | grep -Eq "^[是Yy][Ee]?[Ss]?$";then
return 0
@ -89,8 +84,8 @@ Install_Zsh() {
sudo apt -y install $pack
elif [ -x "$(command -v yum)" ]; then
sudo yum install -y $pack
elif [ -x "$(command -v pacman)" ]; then
sudo -Sy --needed $pack
elif [ -x "$(command -v pacman)" ]; then
sudo pacman -Sy --needed $pack
#elif [ -x "$(command -v paru)" ]; then
# paru -S zsh
else
@ -108,32 +103,44 @@ Download_Config() {
# 下载zsh扩展
GreyStart
ohmyzsh_dir=${ROOT_INSTALL}/oh-my-zsh
sudo git clone https://gitcode.com/mirrors/ohmyzsh/ohmyzsh.git ${ohmyzsh_dir} || Show 1 "关键依赖下载失败, 如${ohmyzsh_dir}已存在, 请先删除 \nsudo rm -rf ${ROOT_INSTALL}"
sudo rm -vrf $ohmyzsh_dir
sudo git clone https://gitcode.com/mirrors/ohmyzsh/ohmyzsh.git ${ohmyzsh_dir} || Show 1 "关键依赖下载失败"
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
# 下载预设配置
config_url=${ROOT_URL}/raw/配置/zshrc
sudo wget -t 3 -q --show-progress -c "${config_url}" || Show 1 "无法下载预设配置(${config_url})"
config_url=${ROOT_URL}raw/配置/zshrc
sudo wget -t 3 -q --show-progress -c "${config_url}" || Show 1 "无法下载预设配置( ${config_url} )"
sudo sed -i "s:export ZSH=/etc/oh-my-zsh:export ZSH=$ohmyzsh_dir:" zshrc
sudo mv zshrc /etc/skel/.zshrc
cp -v /etc/skel/.zshrc $HOME
cd $HOME
ColorReset
Show 2 "寻觅基础环境安装完成"
}
# 选配
Select_Config(){
if Select_Continue "启动zsh"; then
exec zsh
Show 2 "zsh启动完成"
fi
if Select_Continue "将Zsh设置为默认命令行"; then
chsh -s /usr/bin/zsh
Show 2 "已将zsh设置为默认命令行"
Show 0 "已将zsh设置为默认命令行"
else
Show 2 "如需将zsh设置为默认命令行请执行: 'chsh -s /usr/bin/zsh' "
fi
if Select_Continue "启动zsh"; then
Show 0 "将在程序结束后启动zsh"
ZSH_START=1
else
Show 2 "zsh未启动, 如需启动请执行: 'zsh' "
fi
}
Install_Zsh
Download_Config
Select_Config
if [ "$ZSH_START" ]; then
exec zsh
fi

26
安装.zsh Normal file → Executable file
View File

@ -72,6 +72,16 @@ readonly 色彩=(
###############################################################################
# 函数/方法 #
###############################################################################
是否() {
输出 3 "$1((是/否 Yes/No))"
read r
if echo "$r" | grep -Eq "^[是Yy][Ee]?[Ss]?$";then
return 0
else
return 1
fi
}
检查_架构() {
case ${CPU_架构} in
@ -104,18 +114,10 @@ readonly 色彩=(
esac
输出 2 "检测到 ${系统_发行版_名称} (${系统_发行版}) 系统"
if [[ ${未知} == 1 ]]; then
输出 3 "此发行版尚未被验证,是否继续尝试安装(请谨慎安装)"
select 是否 in "[是] Yes" "[否] No"; do
case ${是否} in [yY][eE][sS] | [yY] | [])
输出 2 "发行版检查已忽略"
break
;;
[nN][oO] | [nN] | [])
输出 1 "已退出安装"
exit 1
;;
esac
done < /dev/tty # < /dev/tty 用于从终端读取输入信息
if ! 是否 "此发行版尚未验证, 是否尝试继续安装"; then
输出 1 "已退出安装"
exit 1
fi
fi
}