@@ -36,17 +36,80 @@ while getopts ":i:a:b:" opt; do
3636done
3737shift $(( OPTIND - 1 ))
3838
39+ SCRIPT_DIR=" "
40+ LOCAL_INIT_ZSH=" "
41+ LOCAL_INSTALL_ZPMOD=" "
42+ case " $0 " in
43+ * /?* )
44+ SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " 2> /dev/null && pwd) " || SCRIPT_DIR=" "
45+ ;;
46+ * ) ;;
47+ esac
48+
49+ if [ -n " ${SCRIPT_DIR} " ]; then
50+ if [ -f " ${SCRIPT_DIR} /../zsh/init.zsh" ]; then
51+ LOCAL_INIT_ZSH=" ${SCRIPT_DIR} /../zsh/init.zsh"
52+ fi
53+ if [ -f " ${SCRIPT_DIR} /install_zpmod.sh" ]; then
54+ LOCAL_INSTALL_ZPMOD=" ${SCRIPT_DIR} /install_zpmod.sh"
55+ fi
56+ fi
57+
58+ fetch_to_file () {
59+ _dest=" $1 "
60+ shift
61+ _has_fetcher=0
62+
63+ for _src; do
64+ [ -n " ${_src} " ] || continue
65+ case " ${_src} " in
66+ http://* | https://* )
67+ if command -v curl > /dev/null 2>&1 ; then
68+ _has_fetcher=1
69+ if command curl -fsSL " ${_src} " -o " ${_dest} " 2> /dev/null; then
70+ return 0
71+ fi
72+ elif command -v wget > /dev/null 2>&1 ; then
73+ _has_fetcher=1
74+ if command wget -qO " ${_dest} " " ${_src} " 2> /dev/null; then
75+ return 0
76+ fi
77+ fi
78+ ;;
79+ * )
80+ if [ -r " ${_src} " ]; then
81+ command cp " ${_src} " " ${_dest} "
82+ return 0
83+ fi
84+ ;;
85+ esac
86+ done
87+
88+ if [ " ${_has_fetcher} " -eq 0 ]; then
89+ printf ' %s\n' " -- ERROR -- curl or wget is required to download installer assets" >&2
90+ fi
91+ return 1
92+ }
93+
3994if [ " ${AOPT} " = loader ]; then
4095 ZI_CONFIG_DIR=" ${XDG_CONFIG_HOME:- ${HOME} / .config} /zi"
96+ loader_tmp=" ${WORKDIR} /init.zsh.tmp"
4197 command mkdir -p " ${ZI_CONFIG_DIR} "
42- if command -v curl > /dev/null 2>&1 ; then
43- command curl -fsSL https://raw.githubusercontent.com/z-shell/zi-src/main/public/zsh/init.zsh -o " ${ZI_CONFIG_DIR} /init.zsh"
44- elif command -v wget > /dev/null 2>&1 ; then
45- command wget -qO " ${ZI_CONFIG_DIR} /init.zsh" https://raw.githubusercontent.com/z-shell/zi-src/main/public/zsh/init.zsh
98+ set +e
99+ fetch_to_file " ${ZI_CONFIG_DIR} /init.zsh" \
100+ " ${LOCAL_INIT_ZSH} " \
101+ " https://raw.githubusercontent.com/z-shell/src/main/public/zsh/init.zsh" \
102+ " https://raw.githubusercontent.com/z-shell/src/main/lib/zsh/init.zsh"
103+ fetch_status=$?
104+ set -e
105+ if [ " ${fetch_status} " -ne 0 ]; then
106+ printf ' %s\n' " -- ERROR -- failed to retrieve init.zsh" >&2
107+ exit 1
46108 fi
47- command chmod go-w " ${ZI_CONFIG_DIR} " && command chmod a+x " ${ZI_CONFIG_DIR} /init.zsh"
48109 # shellcheck disable=SC2016
49- command sed -i ' s|: ${ZI\[STREAM\]:="main"}|: ${ZI[STREAM]:="' " ${BOPT} " ' "}|' " ${ZI_CONFIG_DIR} /init.zsh"
110+ command sed ' s|: ${ZI\[STREAM\]:="main"}|: ${ZI[STREAM]:="' " ${BOPT} " ' "}|' " ${ZI_CONFIG_DIR} /init.zsh" > " ${loader_tmp} " &&
111+ command mv " ${loader_tmp} " " ${ZI_CONFIG_DIR} /init.zsh"
112+ command chmod go-w " ${ZI_CONFIG_DIR} " && command chmod a+x " ${ZI_CONFIG_DIR} /init.zsh"
50113fi
51114
52115if [ -z " ${ZI_HOME-} " ]; then
@@ -58,7 +121,7 @@ if [ -z "${ZI_BIN_DIR_NAME-}" ]; then
58121fi
59122
60123if ! test -d " ${ZI_HOME} " ; then
61- command mkdir " ${ZI_HOME} "
124+ command mkdir -p " ${ZI_HOME} "
62125 command chmod go-w " ${ZI_HOME} "
63126fi
64127
@@ -68,17 +131,20 @@ if ! command -v git >/dev/null 2>&1; then
68131fi
69132
70133# Get the download-progress bar tool
71- if command -v curl > /dev/null 2>&1 ; then
72- command mkdir -p /tmp/zi
73- cd /tmp/zi || exit 1
74- command curl -fsSLO https://raw.githubusercontent.com/z-shell/zi/main/public/zsh/git-process-output.zsh &&
75- command chmod a+x /tmp/zi/git-process-output.zsh
76- elif command -v wget > /dev/null 2>&1 ; then
77- command mkdir -p /tmp/zi
78- cd /tmp/zi || exit 1
79- command wget -q https://raw.githubusercontent.com/z-shell/zi/main/public/zsh/git-process-output.zsh &&
80- command chmod a+x /tmp/zi/git-process-output.zsh
134+ command mkdir -p /tmp/zi
135+ cd /tmp/zi || exit 1
136+ set +e
137+ fetch_to_file /tmp/zi/git-process-output.zsh \
138+ " " \
139+ " https://raw.githubusercontent.com/z-shell/zi/main/public/zsh/git-process-output.zsh" \
140+ " https://raw.githubusercontent.com/z-shell/zi/main/lib/zsh/git-process-output.zsh"
141+ fetch_status=$?
142+ set -e
143+ if [ " ${fetch_status} " -ne 0 ]; then
144+ printf ' %s\n' " -- ERROR -- failed to retrieve git-process-output.zsh" >&2
145+ exit 1
81146fi
147+ command chmod a+x /tmp/zi/git-process-output.zsh
82148
83149if test -d " ${ZI_HOME} /${ZI_BIN_DIR_NAME} /.git" ; then
84150 cd " ${ZI_HOME} /${ZI_BIN_DIR_NAME} " || exit 1
@@ -168,29 +234,18 @@ EOF
168234
169235ZPMOD_PROFILE () {
170236 _zpmod_sh=" "
171- case " $0 " in
172- * /* )
173- _script_dir=" $( cd " $( dirname " $0 " ) " 2> /dev/null && pwd) " || _script_dir=" "
174- ;;
175- * )
176- _script_dir=" "
177- ;;
178- esac
179-
180- if [ -n " ${_script_dir} " ] && [ -f " ${_script_dir} /install_zpmod.sh" ]; then
181- _zpmod_sh=" ${_script_dir} /install_zpmod.sh"
237+ if [ -n " ${LOCAL_INSTALL_ZPMOD} " ]; then
238+ _zpmod_sh=" ${LOCAL_INSTALL_ZPMOD} "
182239 else
183240 _zpmod_sh=" ${WORKDIR} /install_zpmod.sh"
184- _zpmod_url=" https://raw.githubusercontent.com/z-shell/zi-src/main/public/sh/install_zpmod.sh"
185- if command -v curl > /dev/null 2>&1 ; then
186- command curl -fsSL " ${_zpmod_url} " -o " ${_zpmod_sh} "
187- elif command -v wget > /dev/null 2>&1 ; then
188- command wget -qO " ${_zpmod_sh} " " ${_zpmod_url} "
189- else
190- printf ' %s\n' " -- ERROR -- curl or wget is required to download install_zpmod.sh" >&2
191- exit 1
192- fi
193- if [ ! -s " ${_zpmod_sh} " ]; then
241+ set +e
242+ fetch_to_file " ${_zpmod_sh} " \
243+ " " \
244+ " https://raw.githubusercontent.com/z-shell/src/main/public/sh/install_zpmod.sh" \
245+ " https://raw.githubusercontent.com/z-shell/src/main/lib/sh/install_zpmod.sh"
246+ fetch_status=$?
247+ set -e
248+ if [ " ${fetch_status} " -ne 0 ]; then
194249 printf ' %s\n' " -- ERROR -- failed to download install_zpmod.sh" >&2
195250 exit 1
196251 fi
0 commit comments