Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style+lint: webi_download should always use 2-3 args #721

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 28 additions & 36 deletions _webi/template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ __bootstrap_webi() {

# detect if this program is already installed
# or if an installed version may cause conflict
webi_check() {
webi_check_installed() {
# Test for existing version
set +e
my_path="$PATH"
Expand Down Expand Up @@ -157,6 +157,25 @@ __bootstrap_webi() {
export PATH="$my_path"
}

webi_check_available() {
if test "$WEBI_CHANNEL" != "error"; then
return 0
fi

echo >&2 "Error: no '$PKG_NAME' release for '${WEBI_OS-}' on '$WEBI_ARCH' as one of '$WEBI_FORMATS' by the tag '${WEBI_TAG-}'"
echo >&2 " '$PKG_NAME' is available for '$PKG_OSES' on '$PKG_ARCHES' as one of '$PKG_FORMATS'"
echo >&2 " (check that the package name and version are correct)"
echo >&2 ""
my_release_url="$(
echo "$WEBI_RELEASES" |
sed 's:\?.*::'
)"
echo >&2 " Double check at ${my_release_url}"
echo >&2 ""

exit 1
}

is_interactive_shell() {
# $- shows shell flags (error,unset,interactive,etc)
case $- in
Expand All @@ -179,39 +198,9 @@ __bootstrap_webi() {

# detect if file is downloaded, and how to download it
webi_download() {
# determine the url to download
if [ -n "${1-}" ]; then
my_url="${1}"
else
if [ "error" = "$WEBI_CHANNEL" ]; then
# TODO pass back requested OS / Arch / Version
echo >&2 "Error: no '$PKG_NAME' release for '${WEBI_OS-}' on '$WEBI_ARCH' as one of '$WEBI_FORMATS' by the tag '${WEBI_TAG-}'"
echo >&2 " '$PKG_NAME' is available for '$PKG_OSES' on '$PKG_ARCHES' as one of '$PKG_FORMATS'"
echo >&2 " (check that the package name and version are correct)"
echo >&2 ""
my_release_url="$(
echo "$WEBI_RELEASES" |
sed 's:\?.*::'
)"
echo >&2 " Double check at ${my_release_url}"
echo >&2 ""
exit 1
fi
my_url="$WEBI_PKG_URL"
fi

# determine the location to download to
if [ -n "${2-}" ]; then
my_dl="${2}"
else
my_dl="${WEBI_PKG_PATH}/$WEBI_PKG_FILE"
fi

if [ -n "${3-}" ]; then
my_dl_name="${3}"
else
my_dl_name="${PKG_NAME}"
fi
my_url="${1}"
my_dl="${2}"
my_dl_name="${3:-${PKG_NAME}}"

my_dl_rel="$(
webi_sub_home "${my_dl}"
Expand Down Expand Up @@ -465,8 +454,11 @@ __bootstrap_webi() {

# group common pre-install tasks as default
webi_pre_install() {
webi_check
webi_download
webi_check_installed
webi_check_available
webi_download \
"${WEBI_PKG_URL}" \
"${WEBI_PKG_PATH}/${WEBI_PKG_FILE}"
webi_extract
}

Expand Down
4 changes: 3 additions & 1 deletion git-config-gpg/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ __install_git_gpg_init() {
MY_CMD="git-config-gpg"

rm -f "$HOME/.local/bin/$MY_CMD"
webi_download "$WEBI_HOST/packages/$MY_CMD/$MY_CMD.sh" "$HOME/.local/bin/$MY_CMD"
webi_download \
"$WEBI_HOST/packages/$MY_CMD/$MY_CMD.sh" \
"$HOME/.local/bin/$MY_CMD"
chmod a+x "$HOME/.local/bin/$MY_CMD"
}

Expand Down
8 changes: 6 additions & 2 deletions gpg-pubkey/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ __install_gpg_pubkey() {
MY_CMD="gpg-pubkey"

rm -f "$HOME/.local/bin/$MY_CMD"
webi_download "$WEBI_HOST/packages/$MY_CMD/$MY_CMD.sh" "$HOME/.local/bin/$MY_CMD"
webi_download \
"$WEBI_HOST/packages/$MY_CMD/$MY_CMD.sh" \
"$HOME/.local/bin/$MY_CMD"
chmod a+x "$HOME/.local/bin/$MY_CMD"
}

Expand All @@ -15,7 +17,9 @@ __install_gpg_pubkey_id() {
MY_SUBCMD="gpg-pubkey-id"

rm -f "$HOME/.local/bin/$MY_SUBCMD"
webi_download "$WEBI_HOST/packages/$MY_CMD/$MY_SUBCMD.sh" "$HOME/.local/bin/$MY_SUBCMD"
webi_download \
"$WEBI_HOST/packages/$MY_CMD/$MY_SUBCMD.sh" \
"$HOME/.local/bin/$MY_SUBCMD"
chmod a+x "$HOME/.local/bin/$MY_SUBCMD"
}

Expand Down
4 changes: 3 additions & 1 deletion gpg/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ _install_gpg() {

# Download the latest LTS
#curl -fsSL -o ~/Downloads/webi/GnuPG-2.2.32.dmg 'https://sourceforge.net/projects/gpgosx/files/GnuPG-2.2.32.dmg/download'
webi_download
webi_download \
"${WEBI_PKG_URL}" \
"${WEBI_PKG_PATH}/${WEBI_PKG_FILE}"
chmod a-w "${WEBI_PKG_DOWNLOAD}"

# Mount the DMG in /Volumes
Expand Down
4 changes: 3 additions & 1 deletion iterm2/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ _install_iterm2() {
exit 1
fi

webi_download
webi_download \
"${WEBI_PKG_URL}" \
"${WEBI_PKG_PATH}/${WEBI_PKG_FILE}"
webi_extract

if [ ! -d "${WEBI_TMP}/iTerm.app" ]; then
Expand Down
4 changes: 3 additions & 1 deletion macos/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ set -e
set -u

main() {
webi_download
webi_download \
"${WEBI_PKG_URL}" \
"${WEBI_PKG_PATH}/${WEBI_PKG_FILE}"

(
cd ~/Downloads/webi
Expand Down
4 changes: 3 additions & 1 deletion myip/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set -u
__init_myip() {

rm -f "$HOME/.local/bin/myip"
webi_download "$WEBI_HOST/packages/myip/myip.sh" "$HOME/.local/bin/myip"
webi_download \
"$WEBI_HOST/packages/myip/myip.sh" \
"$HOME/.local/bin/myip"
chmod a+x "$HOME/.local/bin/myip"

"$HOME/.local/bin/myip"
Expand Down
12 changes: 9 additions & 3 deletions vps-utils/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ set -u
__init_vps_utils() {

rm -f "$HOME/.local/bin/myip" "$HOME/.local/bin/vps-myip" "$HOME/.local/bin/vps-addswap" "$HOME/.local/bin/cap-net-bind"
webi_download "$WEBI_HOST/packages/vps-utils/cap-net-bind.sh" "$HOME/.local/bin/cap-net-bind"
webi_download "$WEBI_HOST/packages/vps-utils/vps-addswap.sh" "$HOME/.local/bin/vps-addswap"
webi_download "$WEBI_HOST/packages/myip/myip.sh" "$HOME/.local/bin/myip"
webi_download \
"$WEBI_HOST/packages/vps-utils/cap-net-bind.sh" \
"$HOME/.local/bin/cap-net-bind"
webi_download \
"$WEBI_HOST/packages/vps-utils/vps-addswap.sh" \
"$HOME/.local/bin/vps-addswap"
webi_download \
"$WEBI_HOST/packages/myip/myip.sh" \
"$HOME/.local/bin/myip"
ln -s "$HOME/.local/bin/myip" "$HOME/.local/bin/vps-myip"
chmod a+x "$HOME/.local/bin/cap-net-bind"
chmod a+x "$HOME/.local/bin/myip"
Expand Down