diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..0a222fd --- /dev/null +++ b/start.sh @@ -0,0 +1,113 @@ +#!/usr/bin/bash + +PACK_LIST=("wget" "git" "zsh") +ROOT_URL="https://gitea.whlug.cn/xunmi/getLinux/" +ROOT_TMP=/tmp/xunmi +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() { + # 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" + fi +} + +Warn() { + echo -e "${aCOLOUR[3]}$1$COLOUR_RESET" +} + +GreyStart() { + echo -e "${aCOLOUR[2]}\c" +} + +ColorReset() { + echo -e "$COLOUR_RESET\c" +} + +############################################################################### +# 函数 # +############################################################################### + +# 更新包管理器 +Update_Package_Resource() { + Show 2 "更新包管理器..." + GreyStart + if [ -x "$(command -v apt)" ]; then + ${sudo_cmd} apt update + elif [ -x "$(command -v yum)" ]; then + ${sudo_cmd} yum update + fi + ColorReset + Show 0 "包管理器更新完毕" +} + +# 安装Zsh +Install_Zsh() { + for ((i = 0; i < ${#PACK_LIST[@]}; i++)); do + pack=${PACK_LIST[i]} + Show 2 "安装必要的依赖项: ${aCOLOUR[4]} $pack $COLOUR_RESET" + Update_Package_Resource + GreyStart + if [ -x "$(command -v apt)" ]; then + 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 paru)" ]; then + # paru -S zsh + else + Show 1 "未找到包管理器, 您需要手动安装: ${aCOLOUR[5]} $pack $COLOUR_RESET" + fi + ColorReset + done + Show 0 "依赖安装完成" +} + +Download_Config() { + # 创建下载文件的临时目录 + GreyStart + sudo rm -rf -v ${TMP_ROOT} + mkdir -p -v ${TMP_ROOT} || Show 1 "无法创建临时目录" + tmp_dir=$(mktemp -d -p -v ${TMP_ROOT} || Show 1 "无法创建临时目录") + + # 下载配置 + config_url=${ROOT_URL}/src/默认分支/配置/zshrc + wget -t 3 -q --show-progress -c "${config_url}" || Show 1 "无法下载配置" + # 下载zsh扩展 + ohmyzsh_dir=${ROOT_INSTALL}/oh-my-zsh + git clone https://gitcode.com/mirrors/ohmyzsh/ohmyzsh.git ${ohmyzsh_dir} + cd -v ${ohmyzsh_dir}/custom/plugins/ + git clone https://gitcode.com/mirrors/zsh-users/zsh-autosuggestions.git + git clone https://gitcode.com/mirrors/zsh-users/zsh-syntax-highlighting.git + sudo cp -v ${tmp_dir}/zshrc /etc/skel/.zshrc + sudo cp -v /etc/skel/.zshrc $HOME + ColorReset +} + +Install_Zsh +Download_Config diff --git a/配置/zshrc b/配置/zshrc index 2228ea9..0e5d522 100644 --- a/配置/zshrc +++ b/配置/zshrc @@ -1,9 +1,6 @@ export ZSH=/etc/oh-my-zsh # 添加环境变量 -export PATH=/home/xunmi/.go_env/bin:/home/xunmi/.cargo/bin:$HOME/bin:/usr/local/bin:/home/xunmi/.local/bin:$PATH -# GO默认缓存路径 -export GOPATH=/home/xunmi/.go_env - +# export PATH=$HOME/bin:/usr/local/bin:$HOME/.local/bin:$PATH # zsh 主题,在线预览 https://github.com/ohmyzsh/ohmyzsh/wiki/Themes # 推荐主题: gnzh、jispwoso[双行: 1 用户名-目录-Git] @@ -86,9 +83,4 @@ export LC_ALL="zh_CN.UTF-8" # 别名 alias ls='lsd' alias zshconfig="vim ~/.zshrc" -alias 安装="sudo pacman -Sy --needed" -alias 更新="sudo pacman -Syu" -alias 搜索_包仓库="sudo pkgfile" - -JAVA_HOME="/usr/lib/jvm/java-20-openjdk"