Skip to content

Commit 9d9b29b

Browse files
committed
fix(ci): finish PR 163 portability fixes
1 parent 244afd4 commit 9d9b29b

6 files changed

Lines changed: 163 additions & 51 deletions

File tree

.github/workflows/check-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ jobs:
6666
zpmod source-study -l
6767
shell: zsh {0}
6868
- name: "⚙️ Check: init.zsh sync drift"
69-
run: sh public/sh/sync-init.sh
69+
run: sh public/sh/sync-init.sh --local ./public/zsh/init.zsh --remote ./public/zsh/init.zsh --checksum-url ./public/checksum.txt

public/checksum.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
5d8fdd881b84548f38c1d5ffc6d5f46a18919d8dd6c1398d69abe055dd76ef98 public/sh/install_zpmod.sh
2-
04155daa5bbf3a1189ec31f5db72a27b36b1c328769216477ea1efd893fbd23c public/sh/install.sh
3-
4d8ff8ba526be8a2abc484cd6455201e2e0fea23eafb7f487e83cac403a92a56 public/sh/sync-init.sh
2+
ff998db4039562ec89751bc9460787520e238d26397287e453ed6867859ac778 public/sh/install.sh
3+
f8519bf7e3e42ad67cc9cff6d82a8367641611fc687b2f6793e26bd55dbbb553 public/sh/sync-init.sh
44
98f54a779985719e390b3e4559b7b0ac22101caac91d0569d41cd9229a05c6de public/zsh/init.zsh

public/sh/install.sh

Lines changed: 93 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,80 @@ while getopts ":i:a:b:" opt; do
3636
done
3737
shift $((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+
3994
if [ "${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"
50113
fi
51114

52115
if [ -z "${ZI_HOME-}" ]; then
@@ -58,7 +121,7 @@ if [ -z "${ZI_BIN_DIR_NAME-}" ]; then
58121
fi
59122

60123
if ! test -d "${ZI_HOME}"; then
61-
command mkdir "${ZI_HOME}"
124+
command mkdir -p "${ZI_HOME}"
62125
command chmod go-w "${ZI_HOME}"
63126
fi
64127

@@ -68,17 +131,20 @@ if ! command -v git >/dev/null 2>&1; then
68131
fi
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
81146
fi
147+
command chmod a+x /tmp/zi/git-process-output.zsh
82148

83149
if 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

169235
ZPMOD_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

public/sh/sync-init.sh

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
2929
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
3030

3131
DEFAULT_LOCAL="${REPO_ROOT}/public/zsh/init.zsh"
32-
DEFAULT_REMOTE="https://raw.githubusercontent.com/z-shell/zi-src/main/public/zsh/init.zsh"
33-
DEFAULT_CHECKSUM_URL="https://raw.githubusercontent.com/z-shell/zi-src/main/public/checksum.txt"
32+
DEFAULT_REMOTE="https://raw.githubusercontent.com/z-shell/src/main/public/zsh/init.zsh"
33+
DEFAULT_CHECKSUM_URL="https://raw.githubusercontent.com/z-shell/src/main/public/checksum.txt"
3434
CHECKSUM_KEY="public/zsh/init.zsh"
3535

3636
OPT_LOCAL="${DEFAULT_LOCAL}"
@@ -63,19 +63,59 @@ Exit codes:
6363
EOF
6464
}
6565

66+
_fetch_url() {
67+
_url="$1"
68+
if command -v curl >/dev/null 2>&1; then
69+
command curl -fsSL "${_url}"
70+
elif command -v wget >/dev/null 2>&1; then
71+
command wget -qO- "${_url}"
72+
else
73+
printf '%s\n' "[1;31m▓▒░[0m No curl or wget available." >&2
74+
return 1
75+
fi
76+
}
77+
78+
_legacy_url() {
79+
_url="$1"
80+
case "${_url}" in
81+
https://raw.githubusercontent.com/z-shell/src/main/public/*)
82+
printf '%s\n' "https://raw.githubusercontent.com/z-shell/src/main/lib/${_url#https://raw.githubusercontent.com/z-shell/src/main/public/}"
83+
;;
84+
*)
85+
return 1
86+
;;
87+
esac
88+
}
89+
6690
# Fetch a URL or copy a local readable path to stdout.
6791
_fetch() {
6892
_src="$1"
93+
_legacy_src=""
94+
_fetch_status=0
6995
case "${_src}" in
7096
http://* | https://*)
71-
if command -v curl >/dev/null 2>&1; then
72-
command curl -fsSL "${_src}"
73-
elif command -v wget >/dev/null 2>&1; then
74-
command wget -qO- "${_src}"
75-
else
76-
printf '%s\n' "[1;31m▓▒░[0m No curl or wget available." >&2
77-
return 1
97+
set +e
98+
_fetch_url "${_src}"
99+
_fetch_status=$?
100+
set -e
101+
if [ "${_fetch_status}" -eq 0 ]; then
102+
return 0
78103
fi
104+
set +e
105+
_legacy_src="$(_legacy_url "${_src}" 2>/dev/null)"
106+
_legacy_status=$?
107+
set -e
108+
if [ "${_legacy_status}" -eq 0 ] && [ -n "${_legacy_src}" ]; then
109+
set +e
110+
_fetch_url "${_legacy_src}"
111+
_fetch_status=$?
112+
set -e
113+
if [ "${_fetch_status}" -eq 0 ]; then
114+
return 0
115+
fi
116+
fi
117+
printf '%s\n' "[1;31m▓▒░[0m Failed to fetch: ${_src}" >&2
118+
return 1
79119
;;
80120
*)
81121
if [ -r "${_src}" ]; then

public/zsh/snippets/welcome.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
+zi-message "{auto}\`Welcome to Zi :)\`"
22
sleep 1
33
+zi-message "{hi}I am the snippet\!"
4-
zi delete https://raw.githubusercontent.com/z-shell/zi-src/main/public/zsh/snippets/welcome.zsh
4+
zi delete https://raw.githubusercontent.com/z-shell/src/main/public/zsh/snippets/welcome.zsh

tests/installers.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,22 @@ test_loader_install() {
190190
pass "loader install uses XDG paths and branch override"
191191
}
192192

193+
test_xdg_data_home_install() {
194+
home="${TMP_ROOT}/default-home"
195+
data="${TMP_ROOT}/missing-root/data-home"
196+
command mkdir -p "${home}"
197+
198+
HOME="${home}" \
199+
ZDOTDIR="${home}" \
200+
XDG_DATA_HOME="${data}" \
201+
ZI_SRC_TEST_ROOT="${ROOT}" \
202+
PATH="${FAKE_BIN}:${PATH}" \
203+
sh "${ROOT}/public/sh/install.sh" -i skip >/dev/null
204+
205+
[ -f "${data}/zi/bin/zi.zsh" ] || fail "install did not create the XDG data home"
206+
pass "XDG data home install creates parent directories"
207+
}
208+
193209
test_standalone_zpmod_delegation() {
194210
standalone_dir="${TMP_ROOT}/standalone"
195211
home="${TMP_ROOT}/zpmod-home"
@@ -247,5 +263,6 @@ check_syntax
247263
check_checksums
248264
write_fake_tools
249265
test_loader_install
266+
test_xdg_data_home_install
250267
test_standalone_zpmod_delegation
251268
test_sync_init

0 commit comments

Comments
 (0)