🎉 feat: 添加初始化配置选项和帮助信息,优化克隆失败时的恢复逻辑,默认不初始化
This commit is contained in:
parent
fc2e8c7ccc
commit
da8bfaa008
|
@ -5,19 +5,30 @@
|
|||
|
||||
# 默认分支
|
||||
BRANCH="dev"
|
||||
# 是否直接初始化配置仓库
|
||||
# INIT=""
|
||||
|
||||
# 检查是否安装git
|
||||
command -v git >/dev/null 2>&1 || {
|
||||
echo "git命令未找到,请安装git"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 使用getopts处理参数
|
||||
while getopts ":hb:" opt; do
|
||||
while getopts ":hib:" opt; do
|
||||
case $opt in
|
||||
b) BRANCH="$OPTARG" ;;
|
||||
i) INIT="enable" ;;
|
||||
h)
|
||||
echo "使用方法: $0 [-d] [-h]"
|
||||
echo " -d 开发模式"
|
||||
echo " -h 显示帮助"
|
||||
echo "使用方法: $0 [-b <branch>] [-ih]"
|
||||
# echo " -d 开发模式"
|
||||
echo " -i 初始化配置仓库"
|
||||
echo " -b 指定分支,默认分支为 dev"
|
||||
echo " -h 显示帮助, 并退出. 建议放最后一个参数."
|
||||
exit 0
|
||||
;;
|
||||
\?)
|
||||
echo "无效选项: -$OPTARG" >&2
|
||||
echo "无效选项: -$opt $OPTARG" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
@ -29,17 +40,23 @@ test -f "$HOME"/.config/.bin/.Runtime/SELF_MARK_AS_INSTALLED_FROM_SCRIPT && {
|
|||
echo "local.env.ini already exists, end the install. please remove it first if need re-install."
|
||||
exit 1
|
||||
}
|
||||
# == 移走原有配置目录
|
||||
# == 移走原有配置目录~/.config到/tmp/.config
|
||||
[ -d "/tmp/.config" ] && rm -rf /tmp/.config # 如果存在, 删除 /tmp/.config
|
||||
[ -d "$HOME/.config" ] && mv "$HOME/.config" /tmp/.config # 移动原有 $HOME/.config 配置到 /tmp/.config
|
||||
# 克隆,如果失败则退出
|
||||
# 克隆,如果失败则退出并恢复原有配置
|
||||
git clone --depth 1 --branch "$BRANCH" --single-branch https://gitea.yever.top/Hawkin/.config.git "$HOME"/.config
|
||||
test $? -ne 0 && {
|
||||
echo "git clone failed, please check your network."
|
||||
# 恢复原有配置
|
||||
# 删除克隆的目录
|
||||
echo "delete the unfinished clone dir: $HOME/.config"
|
||||
[ -d "$HOME/.config" ] && rm -rf "$HOME/.config"
|
||||
# 恢复原有配置
|
||||
if test -d /tmp/.config; then
|
||||
echo "restoring the old config to $HOME/.config"
|
||||
mv /tmp/.config "$HOME/.config"
|
||||
echo "restored the old config to $HOME/.config"
|
||||
else
|
||||
echo "no old config found, skip restore config dir."
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -53,4 +70,6 @@ EOF
|
|||
echo "git clone success, init project by script itself..."
|
||||
|
||||
# = 通过目标仓库的初始化脚本进行初始化
|
||||
bash "$HOME"/.config/.bin/bin/Init.sh
|
||||
if test "$INIT" = "enable"; then
|
||||
bash "$HOME"/.config/.bin/bin/Init.sh
|
||||
fi
|
||||
|
|
10
readme.md
10
readme.md
|
@ -6,8 +6,16 @@
|
|||
|
||||
> 静默但输出错误信息,并跟随重定向
|
||||
|
||||
克隆 dev 分支(`-b`,默认)并进行初始化(`-i`):
|
||||
|
||||
```bash
|
||||
curl -sSL https://gitea.yever.top/Hawkin/setup-kit/raw/main/config-os-and-apps.sh | bash
|
||||
curl -sSL https://gitea.yever.top/Hawkin/setup-kit/raw/main/config-os-and-apps.sh | bash -- -ib dev
|
||||
```
|
||||
|
||||
指定分支(`-b`)但不进行初始化:
|
||||
|
||||
```bash
|
||||
curl -sSL https://gitea.yever.top/Hawkin/setup-kit/raw/main/config-os-and-apps.sh | bash -- -b dev
|
||||
```
|
||||
|
||||
或
|
||||
|
|
Loading…
Reference in New Issue