# These are used for symlinks, PATH, and test commands
pkg_dst="$HOME/.local/opt/foobar"
-pkg_dst_bin="$HOME/.local/opt/foobar/bin"
pkg_dst_cmd="$HOME/.local/opt/foobar/bin/foobar"
+#pkg_dst_bin="$(dirname "$pkg_dst_cmd")"
# These are the _real_ locations for the above
pkg_src="$HOME/.local/opt/foobar-v$WEBI_VERSION"
-pkg_src_bin="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin"
pkg_src_cmd="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin/foobar"
+#pkg_src_bin="$(dirname "$pkg_src_cmd")"
```
(required) A version check function that strips all non-version junk
{
+set -e
+set -u
+
#WEBI_PKG=
#WEBI_HOST=https://webinstall.dev
export WEBI_HOST
{
-my_package="\${1:-}"
-if [ -z "\$my_package" ]; then
- echo "Usage: webi <package>@<version>"
- echo "Example: webi node@latest"
- exit 1
+export WEBI_TIMESTAMP=\$(date +%F_%H-%M-%S)
+export _webi_tmp="\${_webi_tmp:-\$(mktemp -d -t webi-\$WEBI_TIMESTAMP.XXXXXXXX)}"
+
+if [ -n "\${_WEBI_PARENT:-}" ]; then
+ export _WEBI_CHILD=true
+else
+ export _WEBI_CHILD=
fi
+export _WEBI_PARENT=true
##
## Detect acceptable package formats
set +e
# NOTE: the order here is least favorable to most favorable
if [ -n "\$(command -v pkgutil)" ]; then
- my_ext="pkg,\$my_ext"
+ my_ext="pkg,\$my_ext"
fi
# disable this check for the sake of building the macOS installer on Linux
#if [ -n "\$(command -v diskutil)" ]; then
- # note: could also detect via hdiutil
- my_ext="dmg,\$my_ext"
+ # note: could also detect via hdiutil
+ my_ext="dmg,\$my_ext"
#fi
if [ -n "\$(command -v git)" ]; then
- my_ext="git,\$my_ext"
+ my_ext="git,\$my_ext"
fi
if [ -n "\$(command -v unxz)" ]; then
- my_ext="xz,\$my_ext"
+ my_ext="xz,\$my_ext"
fi
if [ -n "\$(command -v unzip)" ]; then
- my_ext="zip,\$my_ext"
+ my_ext="zip,\$my_ext"
else
echo "WARN: 'unzip' not found"
fi
if [ -n "\$(command -v tar)" ]; then
- my_ext="tar,\$my_ext"
+ my_ext="tar,\$my_ext"
fi
my_ext="\$(echo "\$my_ext" | sed 's/,$//')" # nix trailing comma
set -e
+
##
## Detect http client
##
+
set +e
export WEBI_CURL="\$(command -v curl)"
export WEBI_WGET="\$(command -v wget)"
set -e
-export WEBI_BOOT="\$(mktemp -d -t "\$my_package-bootstrap.XXXXXXXX")"
export WEBI_HOST="\${WEBI_HOST:-https://webinstall.dev}"
export WEBI_UA="\$(uname -a)"
-my_installer_url="\$WEBI_HOST/api/installers/\$my_package.sh?formats=\$my_ext"
-set +e
-if [ -n "\$WEBI_CURL" ]; then
- curl -fsSL "\$my_installer_url" -H "User-Agent: curl \$WEBI_UA" \\
- -o "\$WEBI_BOOT/\$my_package-bootstrap.sh"
-else
- wget -q "\$my_installer_url" --user-agent="wget \$WEBI_UA" \\
- -O "\$WEBI_BOOT/\$my_package-bootstrap.sh"
-fi
-if ! [ \$? -eq 0 ]; then
- echo "error fetching '\$my_installer_url'"
- exit 1
-fi
-set -e
-pushd "\$WEBI_BOOT" 2>&1 > /dev/null
- bash "\$my_package-bootstrap.sh"
-popd 2>&1 > /dev/null
+webinstall() {
-rm -rf "\$WEBI_BOOT"
+ my_package="\${1:-}"
+ if [ -z "\$my_package" ]; then
+ echo "Usage: webi <package>@<version> ..."
+ echo "Example: webi node@lts rg"
+ exit 1
+ fi
+
+ export WEBI_BOOT="\$(mktemp -d -t "\$my_package-bootstrap.\$WEBI_TIMESTAMP.XXXXXXXX")"
+
+ my_installer_url="\$WEBI_HOST/api/installers/\$my_package.sh?formats=\$my_ext"
+ set +e
+ if [ -n "\$WEBI_CURL" ]; then
+ curl -fsSL "\$my_installer_url" -H "User-Agent: curl \$WEBI_UA" \\
+ -o "\$WEBI_BOOT/\$my_package-bootstrap.sh"
+ else
+ wget -q "\$my_installer_url" --user-agent="wget \$WEBI_UA" \\
+ -O "\$WEBI_BOOT/\$my_package-bootstrap.sh"
+ fi
+ if ! [ \$? -eq 0 ]; then
+ echo "error fetching '\$my_installer_url'"
+ exit 1
+ fi
+ set -e
+
+ pushd "\$WEBI_BOOT" 2>&1 > /dev/null
+ bash "\$my_package-bootstrap.sh"
+ popd 2>&1 > /dev/null
+
+ rm -rf "\$WEBI_BOOT"
+
+}
+
+show_path_updates() {
+
+ if ! [ -n "\${_WEBI_CHILD}" ]; then
+ if [ -f "\$_webi_tmp/.PATH.env" ]; then
+ my_paths=\$(cat "\$_webi_tmp/.PATH.env" | sort -u)
+ if [ -n "\$my_paths" ]; then
+ echo "IMPORTANT: You must update you PATH to use the installed program(s)"
+ echo ""
+ echo "You can CLOSE and REOPEN Terminal, or RUN these exports:"
+ echo ""
+ echo "\$my_paths"
+ echo ""
+ fi
+ rm -f "\$_webi_tmp/.PATH.env"
+ fi
+ fi
+
+}
+
+for pkgname in "\$@"
+do
+ webinstall "\$pkgname"
+done
+
+show_path_updates
}
+
EOF
chmod a+x "$HOME/.local/bin/webi"
##
WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-${WEBI_PKG:-}.XXXXXXXX)"}
+export _webi_tmp="${_webi_tmp:-"$HOME/.local/opt/webi-tmp.d"}"
mkdir -p "$HOME/Downloads"
mkdir -p "$HOME/.local/bin"
fi
if [ -n "$WEBI_SINGLE" ] || [ "single" == "${1:-}" ]; then
- if [ -L "$pkg_dst_cmd" ]; then
- rm -f "$pkg_dst_cmd"
- elif [ -e "$pkg_dst_cmd" ]; then
- echo "remove $pkg_dst_cmd?"
- rm -rf -i "$pkg_dst_cmd"
- fi
+ rm -rf "$pkg_dst_cmd"
ln -s "$pkg_src_cmd" "$pkg_dst_cmd"
else
- # 'pkg_dst' will default to $HOME/.local/opt/node
- # 'pkg_src' will be the installed version, such as to $HOME/.local/opt/node-v12.8.0
- if [ -L "$pkg_dst" ]; then
- rm -f "$pkg_dst"
- elif [ -e "$pkg_dst" ]; then
- echo "remove $pkg_dst?"
- rm -rf -i "$pkg_dst"
- fi
+ # 'pkg_dst' will default to $HOME/.local/opt/<pkg>
+ # 'pkg_src' will be the installed version, such as to $HOME/.local/opt/<pkg>-<version>
+ rm -rf "$pkg_dst"
ln -s "$pkg_src" "$pkg_dst"
fi
}
webi_check() {
# Test for existing version
set +e
+ my_path="$PATH"
+ export PATH="$(dirname "$pkg_dst_cmd"):$PATH"
my_current_cmd="$(command -v "$pkg_cmd_name")"
set -e
if [ -n "$my_current_cmd" ]; then
fi
fi
fi
+ export PATH="$my_path"
}
# detect if file is downloaded, and how to download it
tar xf "$HOME/Downloads/$WEBI_PKG_FILE"
elif [ "zip" == "$WEBI_EXT" ]; then
echo "Extracting $HOME/Downloads/$WEBI_PKG_FILE"
- unzip "$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)
- echo -n ""
+ true
elif [ "xz" == "$WEBI_EXT" ]; then
echo "Inflating $HOME/Downloads/$WEBI_PKG_FILE"
unxz -c "$HOME/Downloads/$WEBI_PKG_FILE" > $(basename "$WEBI_PKG_FILE")
# make sure that we don't recursively install pathman with webi
my_path="$PATH"
export PATH="$HOME/.local/bin:$PATH"
- set +e
- my_pathman=$(command -v pathman)
- set -e
- export PATH="$my_path"
# install pathman if not already installed
- if [ -z "$my_pathman" ]; then
- "$HOME/.local/bin/webi" pathman
- export PATH="$HOME/.local/bin:$PATH"
+ if [ -z "$(command -v pathman)" ]; then
+ "$HOME/.local/bin/webi" pathman > /dev/null
fi
+ export PATH="$my_path"
+
# in case pathman was recently installed and the PATH not updated
- "$HOME/.local/bin/pathman" add "$1"
+ mkdir -p "$_webi_tmp"
+ "$HOME/.local/bin/pathman" add "$1" | grep "export" >> "$_webi_tmp/.PATH.env"
}
# group common pre-install tasks as default
mv ./"$pkg_cmd_name"* "$pkg_src_cmd"
chmod a+x "$pkg_src_cmd"
else
- mkdir -p "$(dirname $pkg_src)"
- if [ -L "$pkg_src" ]; then
- rm -f "$pkg_src"
- elif [ -e "$pkg_src" ]; then
- echo "remove $pkg_src?"
- rm -rf -i "$pkg_src"
- fi
+ rm -rf "$pkg_src"
mv ./"$pkg_cmd_name"* "$pkg_src"
fi
}
# run post-install functions - just updating PATH by default
webi_post_install() {
- webi_path_add "$pkg_dst_bin"
+ webi_path_add "$(dirname "$pkg_dst_cmd")"
}
# a friendly message when all is well, showing the final install path in $HOME/.local
if [ -n "$WEBI_SINGLE" ]; then
pkg_dst_cmd="${pkg_dst_cmd:-$HOME/.local/bin/$pkg_cmd_name}"
- pkg_dst_bin="$(dirname $pkg_dst_cmd)"
- pkg_dst="$(dirname $pkg_dst_bin)"
+ 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_bin="$(dirname $pkg_src_cmd)"
- pkg_src="$(dirname $pkg_src_bin)"
+ pkg_src="$pkg_src_cmd" # "$(dirname "$(dirname $pkg_src_cmd)")"
else
pkg_dst="${pkg_dst:-$HOME/.local/opt/$pkg_cmd_name}"
- pkg_dst_bin="${pkg_dst_bin:-$pkg_dst/bin}"
- pkg_dst_cmd="${pkg_dst_cmd:-$pkg_dst_bin/$pkg_cmd_name}"
+ pkg_dst_cmd="${pkg_dst_cmd:-$pkg_dst/bin/$pkg_cmd_name}"
pkg_src="${pkg_src:-$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION}"
- pkg_src_bin="${pkg_src_bin:-$pkg_src/bin}"
- pkg_src_cmd="${pkg_src_cmd:-$pkg_src_bin/$pkg_cmd_name}"
+ pkg_src_cmd="${pkg_src_cmd:-$pkg_src/bin/$pkg_cmd_name}"
fi
+ pkg_src_bin="$(dirname "$pkg_src_cmd")"
+ pkg_dst_bin="$(dirname "$pkg_dst_cmd")"
[ -n "$(command -v pkg_pre_install)" ] && pkg_pre_install || webi_pre_install
echo ""
fi
+webi_path_add "$HOME/.local/bin"
+if [ -z "${_WEBI_CHILD:-}" ] && [ -f "\$_webi_tmp/.PATH.env" ]; then
+ echo "You need to update your PATH to use $WEBI_NAME:"
+ echo ""
+ cat "$_webi_tmp/.PATH.env" | sort -u
+ rm -f "$_webi_tmp/.PATH.env"
+fi
+
# cleanup the temp directory
rm -rf "$WEBI_TMP"
#!/bin/bash
-# title: Pathman
-# homepage: https://git.rootprojects.org/root/pathman
-# tagline: |
-# Pathman: cross-platform PATH management for bash, zsh, fish, cmd.exe, and PowerShell.
-# description: |
-# Manages PATH on various OSes and shells
-# - Mac, Windows, Linux
-# - Bash, Zsh, Fish
-# - Command, Powershell
-# examples: |
-# ```bash
-# pathman add ~/.local/bin
-# ```
-# <br/>
-#
-# ```bash
-# pathman remove ~/.local/bin
-# ```
-# <br/>
-#
-# ```bash
-# pathman list
-# ```
-
-
set -e
set -u
echo $(pathman version 2>/dev/null | head -n 1 | cut -d ' ' -f2 | sed 's:^v::')
}
-x_pkg_pre_install() {
- # Test if in PATH
- set +e
- my_pathman=$(command -v pathman)
- set -e
- if [ -n "$my_pathman" ]; then
- # TODO test pathman version
- # if [ "$WEBI_VERSION" == "$(pathman version | cut -d ' ' -f2)" ]; then
- if [ "$my_pathman" != "$HOME/.local/bin/pathman" ]; then
- echo "a pathman installation (which make take precedence) exists at:"
- echo " $my_pathman"
- echo ""
- fi
- echo "pathman already installed"
- exit 0
- fi
-}
-
-x_pkg_install() {
- # TODO use webi_download via releases.js
- mkdir -p "$HOME/.local/bin/"
- webi_check
- webi_download
- webi_download
- # webi_download "https://rootprojects.org/pathman/dist/$(uname -s)/$(uname -m)/pathman"
- mv "$HOME/Downloads/pathman-v0.5.2" "$HOME/.local/bin/pathman"
- chmod +x "$HOME/.local/bin/pathman"
-}
-
-x_pkg_link() {
- true
-}
-
-pkg_post_install() {
- # add to ~/.local/bin to PATH even if pathman is elsewhere
- # TODO pathman needs silent option and debug output (quiet "already exists" output)
- # TODO inform user to add to path, apart from pathman?
- "$HOME/.local/bin/pathman" add "$HOME/.local/bin"
-}
-
pkg_done_message() {
+ # no message
true
}
--- /dev/null
+# title: Pathman
+# homepage: https://git.rootprojects.org/root/pathman
+# tagline: |
+# Pathman: cross-platform PATH management for bash, zsh, fish, cmd.exe, and PowerShell.
+# description: |
+# Manages PATH on various OSes and shells
+# - Mac, Windows, Linux
+# - Bash, Zsh, Fish
+# - Command, Powershell
+# examples: |
+# ```bash
+# pathman add ~/.local/bin
+# ```
+# <br/>
+#
+# ```bash
+# pathman remove ~/.local/bin
+# ```
+# <br/>
+#
+# ```bash
+# pathman list
+# ```
+
+END