diff --git a/bin/untar.sh b/bin/untar.sh new file mode 100755 index 0000000..fc38a9e --- /dev/null +++ b/bin/untar.sh @@ -0,0 +1,54 @@ +#!/bin/zsh + + +# 这个脚本可以根据文件 16 进制判断压缩格式,然后通过对应命令解压 +# 解压函数:file 接收文件名,cmd 接收命令,opt 参数选项 +decompress() { + file=$1 + cmd=$2 + opt=$3 + $cmd $opt $file +} + + +# 数组:存储支持的压缩格式和对应的文件头和解压命令 +# 每个元素的格式为:文件 16 进制头:解压命令:选项 +formats=( +377abcaf:7z:x +213c6172:ar:x +425a6839:bunzip2: +504b0304:unzip: +7f454c46:7z:x +1f8b0808:gunzip: +5d000080:unlzma: +1f8b0800:tar:-zxvf +fd377a58:unxz: +) +#判断是否为 tar +filesion=$(file $1 | cut -d':' -f2-) +if [[ "$filesion" == *tar* ]]; then + tar -xvf "$1" +#判断是否为文件 +elif [[ -f $1 ]]; then + header=$(xxd -p -l 4 $1) + # 定义一个变量,表示是否找到匹配的格式 + found=0 + # 遍历数组,匹配文件头和解压命令 + for format in $formats; do + # 使用 IFS 分隔数组元素的各个字段 + IFS=: read head cmd opt <<< $format + # 如果文件头匹配,调用解压函数,并设置 found 为 1 + if [[ $header == $head* ]]; then + decompress $1 $cmd $opt + found=1 + break + fi + done + # 如果没有找到匹配的格式,打印提示信息 + if [[ $found == 0 ]]; then + echo "无法识别的压缩格式" + fi +else + echo "不是一个文件" + fi + diff --git a/start.sh b/start.sh index c4b6616..1ef82c5 100755 --- a/start.sh +++ b/start.sh @@ -119,6 +119,16 @@ Download_Config() { Show 2 "寻觅基础环境安装完成" } +Download_X(){ + Show 0 "正在下载配置言灵" + GreyStart + x_dir=$ROOT_INSTALL/x + sudo rm -vrf $x_dir + sudo git clone $ROOT_URL $x_dir || Show 1 "言灵拉去失败" + ColorReset + X_START=1 +} + # 选配 Select_Config(){ if Select_Continue "将Zsh设置为默认命令行"; then @@ -132,15 +142,24 @@ Select_Config(){ Show 0 "将在程序结束后启动zsh" ZSH_START=1 else - Show 2 "zsh未启动, 如需启动请执行: 'zsh' " + Show 2 "zsh未启动, 如需启动请执行: 'zsh' 或 'exec zsh'" fi } + + Install_Zsh -Download_Config +# 如果携带 -c 则不下载安装ohmyzsh +[[ "$@" == *-c* ]] || Download_Config +# 如果携带 -x 则不下载安装言灵 +[[ "$@" == *-x* ]] || Download_X Select_Config if [ "$ZSH_START" ]; then exec zsh fi +if [ "$X_START" ]; then + zsh $x_dir/安装.zsh +fi + diff --git a/安装.zsh b/安装.zsh index 3c2b897..d4302d1 100755 --- a/安装.zsh +++ b/安装.zsh @@ -103,7 +103,7 @@ readonly 色彩=( 检查_发行版() { 未知=0 case ${系统_发行版} in -# *arch*) ;; + *arch*) ;; *Loongnix*);; *openwrt*) 输出 1 "暂不支持openwrt" @@ -140,3 +140,4 @@ readonly 色彩=( ############################################################################### 输出_主机配置 +