Skip to content

Commit

Permalink
feat: add -c argument
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-luke committed Sep 14, 2023
1 parent 25db1bd commit 50fc614
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 32 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@ name: Test
on:
workflow_dispatch:
push:
branches: [main]
branches: [main, dev]

jobs:
Yes-Test:
runs-on: macos-latest
Network-Connected-Test-13:
runs-on: macOS-13
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: sd-installer.sh
sparse-checkout-cone-mode: false
- name: Yes
run: bash sd-installer.sh -1 | grep -q 'Launching Web UI with arguments' && echo "成功 Success" && exit 0
- name: Install
run: bash sd-installer.sh -t -1 | grep -q 'Launching Web UI with arguments' && echo "成功 Success" && exit 0
shell: /bin/bash --noprofile --norc -e {0}

No-Test:
runs-on: macos-latest
Network-Connected-Test-12:
runs-on: macos-12
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: sd-installer.sh
sparse-checkout-cone-mode: false
- name: No
run: bash sd-installer.sh -2 | grep -q 'Launching Web UI with arguments' && echo "成功 Success" && exit 0
- name: Install
run: bash sd-installer.sh -t -1 | grep -q 'Launching Web UI with arguments' && echo "成功 Success" && exit 0
shell: /bin/bash --noprofile --norc -e {0}

Network-Not-Connected-Test:
runs-on: macos-latest
steps:
- name: Install
run: curl -fsSL https://raw.fastgit.org/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh | /bin/bash -s -- -c -t -2 | grep -q 'Launching Web UI with arguments' && echo "成功 Success" && exit 0
shell: /bin/bash --noprofile --norc -e {0}
6 changes: 4 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh)"
```

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

```bash
/bin/bash -c "$(curl -fsSL https://raw.fastgit.org/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh)"
curl -fsSL https://raw.fastgit.org/wy-luke/StableDiffusion-Installer-For-Mac/main/sd-installer.sh | /bin/bash -s -- -c
```

该命令为安装脚本添加 `-c` 参数,会在安装时自动切换为国内源,进行网络加速,包括 homebrew、conda-forge、pip、github 等, 但链接可能会不稳定或失效, 若安装失败可以重试。

3. 在安装开始时,会提示您输入密码,只需输入您的登录密码即可。

> 注意:您的密码在输入时是不可见的,只需正常输入,完成后按 Enter 键。
Expand Down
63 changes: 42 additions & 21 deletions sd-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -u
installation_path=$HOME
tmp_path="$HOME/.sd-installer"
mamba_root_path="~/micromamba"
net_connected=true
network_connected=true

# Other variables
code_path="$installation_path/stable-diffusion-webui"
Expand All @@ -20,7 +20,7 @@ fi
brew_path="$brew_pkg_path/bin/brew"
mamba_path="$brew_pkg_path/opt/micromamba/bin/micromamba"

test_mode=0 # Only for test. 0 for no test, 1 for yes-test, 2 for no-test
test_mode=0 # Only for test. 0 for no test, 1 for Network-Connected-Test, 2 for Network-Not-Connected-Test

function clean_up {
echo "############ Clean ###################################"
Expand All @@ -47,7 +47,12 @@ function handle_error {
error_choice=${error_choice:-y}
if [[ $error_choice == [yY] ]]; then
# Retry the command
/bin/bash -c "$(curl -fsSL $sd_installer_url)"

if [[ $network_connected == false ]]; then
/bin/bash -c "$(curl -fsSL $sd_installer_url)" -c
else
/bin/bash -c "$(curl -fsSL $sd_installer_url)"
fi
else
clean_up
# Exit the script
Expand All @@ -70,8 +75,18 @@ function verify_installation {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-1 | -2)
test_mode=${1:1}
-test | -t)
value =${2:1}
if value != 1 && value != 2; then
echo_red "未知选项: $1 $2"
exit 1
fi
test_mode=value
shift # past argument
shift # past value
;;
-c)
network_connected=false
shift
;;
# -h | --help)
Expand All @@ -88,29 +103,35 @@ done

if [ "$test_mode" != 0 ]; then
if [ "$test_mode" == 1 ]; then
net_connected=true
network_connected=true
echo_green "Yes-test"
else
net_connected=false
network_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 "将设置国内镜像源安装, 包括 homebrew、conda-forge、pip、github 等, 但链接可能会不稳定/失效, 若失败可以重试"
# echo_green "For non-Chinese users, you could just ignore this and press the Enter key"
# read -rp "网络是否顺畅? 默认y [y/n] " network_choice
# network_choice=${network_choice:-y}
# if [[ $network_choice == [nN] ]]; then
# network_connected=false
# echo_green "将设置国内镜像源安装, 包括 homebrew、conda-forge、pip、github 等, 但链接可能会不稳定/失效, 若失败可以重试"
# else
# echo_green "网络通畅, 正常安装"
# fi

if [[ $network_connected == false ]]; then
echo_green "将设置国内镜像源安装, 包括 homebrew、conda-forge、pip、github 等, 但链接可能会不稳定或失效, 若安装失败可以重试"
else
echo_green "网络通畅, 正常安装"
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
if ! $network_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://ghproxy.com/github.com/AUTOMATIC1111/stable-diffusion-webui.git"
Expand Down Expand Up @@ -139,7 +160,7 @@ if ! command -v brew &>/dev/null; then
# Grant the permission to execute the installation script
chmod +x $brew_installer_path

if ! $net_connected; then
if ! $network_connected; then
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
Expand All @@ -149,7 +170,7 @@ if ! command -v brew &>/dev/null; then
eval "$($brew_path shellenv)"
verify_installation brew

if ! $net_connected; then
if ! $network_connected; then
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
Expand Down Expand Up @@ -193,7 +214,7 @@ else
fi

# Set default channels for micromamba
if ! $net_connected; then
if ! $network_connected; then
micromamba config prepend channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# micromamba config prepend channels http://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
else
Expand Down Expand Up @@ -230,7 +251,7 @@ fi
# Enter the SD's folder
cd $code_path

if ! $net_connected; then
if ! $network_connected; then
sed -i '' "s/https:\/\/github.com/https:\/\/ghproxy.com\/github.com/g" modules/launch_utils.py
else
sed -i '' "s/https:\/\/ghproxy.com\/github.com/https:\/\/github.com/g" modules/launch_utils.py
Expand Down Expand Up @@ -263,7 +284,7 @@ source venv/bin/activate
# Delete pip cache to avoid some errors
pip cache purge

if ! $net_connected; then
if ! $network_connected; then
# Tsinghua mirror has no tb-nightly package, which is needed by basicsr
# TODO: reset in clean_up
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
Expand All @@ -283,7 +304,7 @@ fi
# micromamba install --yes --file requirements_versions.txt

# Fix issue https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/12210
if ! $net_connected; then
if ! $network_connected; then
echo >>webui-macos-env.sh
echo "export TORCH_COMMAND=\"pip install wheel==0.41.1 torch==2.0.1 torchvision==0.15.2 cython && pip install git+https://ghproxy.com/https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 --prefer-binary\"" >>webui-macos-env.sh
fi
Expand Down

0 comments on commit 50fc614

Please sign in to comment.