X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=_webi%2Ftemplate.sh;h=643be6ccaa1852fe81312b45857c4aecfdd83327;hb=23070c23f616758660b7acfaec7746c8a4dafabb;hp=ed590c154a6c2040cc849475f4fc7fc3abea16f3;hpb=f9f280f724f8bad9eb00440c9dbb81d62a78ee01;p=webi-installers%2F.git diff --git a/_webi/template.sh b/_webi/template.sh index ed590c1..643be6c 100644 --- a/_webi/template.sh +++ b/_webi/template.sh @@ -1,6 +1,6 @@ #!/bin/bash -{ +function __bootstrap_webi() { set -e set -u @@ -147,7 +147,8 @@ webi_download() { return 0 fi - echo "Downloading $PKG_NAME to $my_dl" + echo "Downloading $PKG_NAME from" + echo "$my_url" # It's only 2020, we can't expect to have reliable CLI tools # to tell us the size of a file as part of a base system... @@ -155,7 +156,11 @@ webi_download() { # wget has resumable downloads # TODO wget -c --content-disposition "$my_url" set +e - wget -q --show-progress --user-agent="wget $WEBI_UA" -c "$my_url" -O "$my_dl.part" + my_show_progress="" + if [[ $- == *i* ]]; then + my_show_progress="--show-progress" + fi + wget -q $my_show_progress --user-agent="wget $WEBI_UA" -c "$my_url" -O "$my_dl.part" if ! [ $? -eq 0 ]; then >&2 echo "failed to download from $WEBI_PKG_URL" exit 1 @@ -164,10 +169,16 @@ webi_download() { else # Neither GNU nor BSD curl have sane resume download options, hence we don't bother # TODO curl -fsSL --remote-name --remote-header-name --write-out "$my_url" - curl -fSL -H "User-Agent: curl $WEBI_UA" "$my_url" -o "$my_dl.part" + my_show_progress="-#" + if [[ $- == *i* ]]; then + my_show_progress="" + fi + curl -fSL $my_show_progress -H "User-Agent: curl $WEBI_UA" "$my_url" -o "$my_dl.part" fi - mv "$my_dl.part" "$my_dl" + + echo "" + echo "Saved as $my_dl" } # detect which archives can be used @@ -180,8 +191,8 @@ webi_extract() { echo "Extracting $HOME/Downloads/$WEBI_PKG_FILE" unzip "$HOME/Downloads/$WEBI_PKG_FILE" > __unzip__.log elif [ "exe" == "$WEBI_EXT" ]; then - # do nothing (but don't leave an empty if block either) - true + echo "Moving $HOME/Downloads/$WEBI_PKG_FILE" + mv "$HOME/Downloads/$WEBI_PKG_FILE" . elif [ "xz" == "$WEBI_EXT" ]; then echo "Inflating $HOME/Downloads/$WEBI_PKG_FILE" unxz -c "$HOME/Downloads/$WEBI_PKG_FILE" > $(basename "$WEBI_PKG_FILE") @@ -208,7 +219,8 @@ webi_path_add() { # in case pathman was recently installed and the PATH not updated mkdir -p "$_webi_tmp" - "$HOME/.local/bin/pathman" add "$1" | grep "export" >> "$_webi_tmp/.PATH.env" || true + # prevent "too few arguments" output on bash when there are 0 lines of stdout + "$HOME/.local/bin/pathman" add "$1" | grep "export" 2>/dev/null >> "$_webi_tmp/.PATH.env" || true } # group common pre-install tasks as default @@ -223,7 +235,6 @@ webi_install() { if [ -n "$WEBI_SINGLE" ] || [ "single" == "${1:-}" ]; then mkdir -p "$(dirname $pkg_src_cmd)" mv ./"$pkg_cmd_name"* "$pkg_src_cmd" - chmod a+x "$pkg_src_cmd" else rm -rf "$pkg_src" mv ./"$pkg_cmd_name"* "$pkg_src" @@ -235,6 +246,33 @@ webi_post_install() { webi_path_add "$(dirname "$pkg_dst_cmd")" } +_webi_enable_exec() { + if [ -n "$(command -v spctl)" ] && [ -n "$(command -v xattr)" ] ; then + # note: some packages contain files that cannot be affected by xattr + xattr -r -d com.apple.quarantine "$pkg_src" || true + return 0 + fi + # TODO need to test that the above actually worked + # (and proceed to this below if it did not) + if [ -n "$(command -v spctl)" ]; then + echo "Checking permission to execute '$pkg_cmd_name' on macOS 11+" + set +e + is_allowed="$(spctl -a "$pkg_src_cmd" 2>&1 | grep valid)" + set -e + if [ -z "$is_allowed" ]; then + echo "" + echo "##########################################" + echo "# IMPORTANT: Permission Grant Required #" + echo "##########################################" + echo "" + echo "Requesting permission to execute '$pkg_cmd_name' on macOS 10.14+" + echo "" + sleep 3 + spctl --add "$pkg_src_cmd" + fi + fi +} + # a friendly message when all is well, showing the final install path in $HOME/.local _webi_done_message() { echo "Installed $(_webi_canonical_name) as $pkg_dst_cmd" @@ -248,12 +286,20 @@ _webi_done_message() { WEBI_SINGLE= -{ +echo "" +echo "Thanks for using webi to install '$PKG_NAME' on '$WEBI_OS/$WEBI_ARCH'." +echo "Have a problem? Experience a bug? Please let us know:" +echo " https://github.com/webinstall/packages/issues" +echo "" + +function __init_installer() { {{ installer }} } +__init_installer + ## ## ## END custom override functions @@ -268,7 +314,8 @@ if [ -n "$(command -v pkg_get_current_version)" ]; then pkg_dst_cmd="${pkg_dst_cmd:-$HOME/.local/bin/$pkg_cmd_name}" pkg_dst="$pkg_dst_cmd" # "$(dirname "$(dirname $pkg_dst_cmd)")" - pkg_src_cmd="${pkg_src_cmd:-$HOME/.local/xbin/$pkg_cmd_name-$WEBI_VERSION}" + #pkg_src_cmd="${pkg_src_cmd:-$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION/bin/$pkg_cmd_name-v$WEBI_VERSION}" + pkg_src_cmd="${pkg_src_cmd:-$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION/bin/$pkg_cmd_name}" pkg_src="$pkg_src_cmd" # "$(dirname "$(dirname $pkg_src_cmd)")" else pkg_dst="${pkg_dst:-$HOME/.local/opt/$pkg_cmd_name}" @@ -285,10 +332,13 @@ if [ -n "$(command -v pkg_get_current_version)" ]; then pushd "$WEBI_TMP" 2>&1 >/dev/null echo "Installing to $pkg_src_cmd" [ -n "$(command -v pkg_install)" ] && pkg_install || webi_install + chmod a+x "$pkg_src" + chmod a+x "$pkg_src_cmd" popd 2>&1 >/dev/null webi_link + _webi_enable_exec pushd "$WEBI_TMP" 2>&1 >/dev/null [ -n "$(command -v pkg_post_install)" ] && pkg_post_install || webi_post_install popd 2>&1 >/dev/null @@ -314,3 +364,5 @@ rm -rf "$WEBI_TMP" # See? No magic. Just downloading and moving files. } + +__bootstrap_webi