Skip to content

Commit

Permalink
fix: command line arguments parse
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-luke committed Sep 3, 2023
1 parent 5fb9757 commit ba90e97
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh)"
```

国内用户存在网络问题时,可以尝试使用以下命令。同时,在提示 `是否存在网络连通问题? [y/n]` 时,输入 `y`,然后按**回车**
国内用户存在网络问题时,可以尝试使用以下命令。同时,在提示 `网络是否顺畅? 默认y [y/n]` 时,输入 `n`,然后按**回车**

```bash
/bin/bash -c "$(curl -fsSL https://raw.fastgit.org/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh)"
Expand Down
100 changes: 50 additions & 50 deletions sd-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,14 @@ net_connected=true
brew_installer_path="$tmp_path/brew_installer.sh"
test_mode=0 # Only for test. 0 for no test, 1 for yes-test, 2 for no-test

# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-0 | -1 | -2)
test_mode=${1:0}
shift
;;
# -h | --help)
# show_help
# exit 0
# ;;
*)
echo_red "未知选项: $1"
# show_help
exit 1
;;
esac
done

if [$test_mode != 0]; then
if [$test_mode == 1]; then
net_connected=true
echo_green "Yes-test"
else
net_connected=false
echo_green "No-test"
fi
else
echo_green "For non-Chinese users, you could just ignore this and press the Enter key"
read -rp "是否存在网络连通问题? 默认n [y/n] " net_choice
net_choice=${net_choice:-n}
if [[ $net_choice == [yY] ]]; then
net_connected=false
echo_green "将会设置国内镜像源"
else
echo_green "网络通畅, 正常安装"
fi
fi

brew_installer_url="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
sd_installer_url="https://raw.githubusercontent.com/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh"
sd_webui_url="https://github.com/AUTOMATIC1111/stable-diffusion-webui.git"

if ! $net_connected; then
brew_installer_url="https://raw.fastgit.org/Homebrew/install/HEAD/install.sh"
sd_installer_url="https://raw.fastgit.org/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh"
sd_webui_url="https://hub.fastgit.xyz/AUTOMATIC1111/stable-diffusion-webui.git"
fi

function clean_up {
echo "############ Clean ###################################"
rm -rf $tmp_path
}

# Define a function to handle errors
function handle_error {
if [$test_mode != 0]; then
if ["$test_mode" != 0]; then
echo_red "测试失败, 不重试"
exit 1
fi
Expand Down Expand Up @@ -106,6 +57,55 @@ function echo_red {
echo -e "\033[31m$1\033[0m"
}

# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-1 | -2)
test_mode=${1:1}
shift
;;
# -h | --help)
# show_help
# exit 0
# ;;
*)
echo_red "未知选项: $1"
# show_help
exit 1
;;
esac
done

if ["$test_mode" != 0]; then
if ["$test_mode" == 1]; then
net_connected=true
echo_green "Yes-test"
else
net_connected=false
echo_green "No-test"
fi
else
echo_green "For non-Chinese users, you could just ignore this and press the Enter key"
read -rp "网络是否顺畅? 默认y [y/n] " net_choice
net_choice=${net_choice:-y}
if [[ $net_choice == [nN] ]]; then
net_connected=false
echo_green "将会设置国内镜像源"
else
echo_green "网络通畅, 正常安装"
fi
fi

brew_installer_url="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
sd_installer_url="https://raw.githubusercontent.com/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh"
sd_webui_url="https://github.com/AUTOMATIC1111/stable-diffusion-webui.git"

if ! $net_connected; then
brew_installer_url="https://raw.fastgit.org/Homebrew/install/HEAD/install.sh"
sd_installer_url="https://raw.fastgit.org/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh"
sd_webui_url="https://hub.fastgit.xyz/AUTOMATIC1111/stable-diffusion-webui.git"
fi

echo "############ 开始安装 Stable Diffusion web UI #########" && echo

if [ ! -d $tmp_path ]; then
Expand Down

0 comments on commit ba90e97

Please sign in to comment.