pkg_cmd_name="foobar"
# These are used for symlinks, PATH, and test commands
-pkg_common_opt="$HOME/.local/opt/foobar"
-pkg_common_bin="$HOME/.local/opt/foobar/bin"
-pkg_common_cmd="$HOME/.local/opt/foobar/bin/foobar"
+pkg_dst="$HOME/.local/opt/foobar"
+pkg_dst_bin="$HOME/.local/opt/foobar/bin"
+pkg_dst_cmd="$HOME/.local/opt/foobar/bin/foobar"
# These are the _real_ locations for the above
-pkg_new_opt="$HOME/.local/opt/foobar-v$WEBI_VERSION"
-pkg_new_bin="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin"
-pkg_new_cmd="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin/foobar"
+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"
```
(required) A version check function that strips all non-version junk
For the rest of the functions you can like copy/paste from the examples:
```bash
-pkg_format_cmd_version() {} # Optional, pretty prints version
+pkg_format_cmd_version() {} # Optional, pretty prints version
-pkg_link_new_version() {} # Required, may be empty for $HOME/.local/bin commands
+pkg_link_src_dst() {} # Required, may be empty for $HOME/.local/bin commands
-pkg_pre_install() { # Required, runs any webi_* commands
- webi_check # for $HOME/.local/opt tools
- webi_download # for things that have a releases.js
- webi_extract # for .xz, .tar.*, and .zip files
+pkg_pre_install() { # Required, runs any webi_* commands
+ webi_check # for $HOME/.local/opt tools
+ webi_download # for things that have a releases.js
+ webi_extract # for .xz, .tar.*, and .zip files
}
-pkg_install() {} # Required, usually just needs to rename extracted folder to
- # "$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION"
+pkg_install() {} # Required, usually just needs to rename extracted folder to
+ # "$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION"
-pkg_post_install() { # Required
- pkg_link_new_version # should probably call pkg_link_new_version()
- webi_path_add "$pkg_common_bin" # should probably update PATH
+pkg_post_install() { # Required
+ pkg_link_src_dst # should probably call pkg_link_src_dst()
+ webi_path_add "$pkg_dst_bin" # should probably update PATH
}
-pkg_post_install_message() {} # Optional, pretty print a success message
+pkg_post_install_message() {} # Optional, pretty print a success message
```
## Script API
pkg_cmd_name="xmpl"
## Some of these directories may be the same, in some cases
-#pkg_common_opt="$HOME/.local/opt/xmpl"
-#pkg_common_bin="$HOME/.local/opt/xmpl/bin"
-#pkg_common_cmd="$HOME/.local/opt/xmpl/bin/xmpl"
+#pkg_dst="$HOME/.local/opt/xmpl"
+#pkg_dst_bin="$HOME/.local/opt/xmpl/bin"
+#pkg_dst_cmd="$HOME/.local/opt/xmpl/bin/xmpl"
-#pkg_new_opt="$HOME/.local/opt/xmpl-v$WEBI_VERSION"
-#pkg_new_bin="$HOME/.local/opt/xmpl-v$WEBI_VERSION/bin"
-#pkg_new_cmd="$HOME/.local/opt/xmpl-v$WEBI_VERSION/bin/xmpl"
+#pkg_src="$HOME/.local/opt/xmpl-v$WEBI_VERSION"
+#pkg_src_bin="$HOME/.local/opt/xmpl-v$WEBI_VERSION/bin"
+#pkg_src_cmd="$HOME/.local/opt/xmpl-v$WEBI_VERSION/bin/xmpl"
# Different packages represent the version in different ways
# ex: node v12.8.0 (leading 'v')
# For (re-)linking to the desired installed version
# (for example: 'go' is special and needs both $HOME/go and $HOME/.local/opt/go)
# (others like 'rg', 'hugo', and 'caddy' are single files that just get replaced)
-pkg_link_new_version() {
- rm -rf "$pkg_common_opt"
- ln -s "$pkg_new_opt" "$pkg_common_opt"
+pkg_link_src_dst() {
+ rm -rf "$pkg_dst"
+ ln -s "$pkg_src" "$pkg_dst"
}
pkg_pre_install() {
pushd "$WEBI_TMP" 2>&1 >/dev/null
# remove the versioned folder, just in case it's there with junk
- rm -rf "$pkg_new_opt"
+ rm -rf "$pkg_src"
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/opt/xmpl-v$WEBI_VERSION" by default)
- mv ./"$pkg_cmd_name"* "$pkg_new_opt"
+ mv ./"$pkg_cmd_name"* "$pkg_src"
popd 2>&1 >/dev/null
}
# For updating PATHs and installing companion tools
pkg_post_install() {
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
}
pkg_post_install_message() {
pushd "$WEBI_TMP" 2>&1 >/dev/null
if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
- rsync -Krl ./xmpl*/ "$pkg_new_opt/" 2>/dev/null
+ rsync -Krl ./xmpl*/ "$pkg_src/" 2>/dev/null
else
- cp -Hr ./xmpl*/* "$pkg_new_opt/" 2>/dev/null
- cp -Hr ./xmpl*/.* "$pkg_new_opt/" 2>/dev/null
+ cp -Hr ./xmpl*/* "$pkg_src/" 2>/dev/null
+ cp -Hr ./xmpl*/.* "$pkg_src/" 2>/dev/null
fi
rm -rf ./xmpl*
set -u
pkg_cmd_name="caddy"
-pkg_common_opt="$HOME/.local"
+pkg_dst="$HOME/.local"
-# just a junk file so that the version check always fails for non-current versions
-pkg_new_opt="$HOME/.local/opt/caddy-doesntexist111"
+# the "source" here isn't used, nor very meaningful,
+# but we'll use the download location as a junk value
+pkg_src="$HOME/Downloads/$WEBI_PKG_FILE"
pkg_get_current_version() {
# 'caddy version' has output in this format:
echo "$pkg_cmd_name v$my_version"
}
-pkg_link_new_version() {
+pkg_link_src_dst() {
# caddy is just a single file, no directory linking to do
true
}
pushd "$WEBI_TMP" 2>&1 >/dev/null
# ensure the bin dir exists
- mkdir -p "$pkg_common_bin"
+ mkdir -p "$pkg_dst_bin"
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/bin/caddy", as set above)
# ex (full directory): ./node-v13-linux-amd64/bin/node.exe
- #mv ./"$pkg_cmd_name"* "$pkg_new_opt"
+ #mv ./"$pkg_cmd_name"* "$pkg_src"
# ex (single file): ./caddy-v2.0.0-linux-amd64.exe
- mv ./"$pkg_cmd_name"* "$pkg_common_cmd"
- chmod a+x "$pkg_common_cmd"
+ mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
+ chmod a+x "$pkg_dst_cmd"
# ex (single file, nested in directory): ./rg/rg-v13-linux-amd64
#mv ./"$pkg_cmd_name"*/"$pkg_cmd_name"* "$pkg_commend_cmd"
- #chmod a+x "$pkg_common_cmd"
+ #chmod a+x "$pkg_dst_cmd"
popd 2>&1 >/dev/null
}
pkg_post_install() {
# just in case we add something in the future
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
# Adds "$HOME/.local/bin" to PATH
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
}
pkg_post_install_message() {
- echo "Installed 'caddy' v$WEBI_VERSION as $pkg_common_cmd"
+ echo "Installed 'caddy' v$WEBI_VERSION as $pkg_dst_cmd"
}
# NOTE: pkg_* variables can be defined here
# pkg_cmd_name
-# pkg_new_opt, pkg_new_bin, pkg_new_cmd
-# pkg_common_opt, pkg_common_bin, pkg_common_cmd
+# pkg_src, pkg_src_bin, pkg_src_cmd
+# pkg_dst, pkg_dst_bin, pkg_dst_cmd
#
# Their defaults are defined in webi/template.bash at https://github.com/webinstall/packages
echo "$(flutter --version 2>/dev/null | head -n 1 | cut -d' ' -f2)"
}
-pkg_link_new_version() {
- # 'pkg_common_opt' will default to $HOME/.local/opt/flutter
- # 'pkg_new_opt' will be the installed version, such as to $HOME/.local/opt/flutter-v1.17.3
- rm -rf "$pkg_common_opt"
- ln -s "$pkg_new_opt" "$pkg_common_opt"
+pkg_link_src_dst() {
+ # 'pkg_dst' will default to $HOME/.local/opt/flutter
+ # 'pkg_src' will be the installed version, such as to $HOME/.local/opt/flutter-v1.17.3
+ rm -rf "$pkg_dst"
+ ln -s "$pkg_src" "$pkg_dst"
}
pkg_pre_install() {
pushd "$WEBI_TMP" 2>&1 >/dev/null
# remove the versioned folder, just in case it's there with junk
- rm -rf "$pkg_new_opt"
+ rm -rf "$pkg_src"
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/opt/flutter-v$WEBI_VERSION" by default)
- mv ./flutter* "$pkg_new_opt"
+ mv ./flutter* "$pkg_src"
popd 2>&1 >/dev/null
}
pkg_post_install() {
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
# Adds "$HOME/.local/opt/flutter" to PATH
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
}
set -u
pkg_cmd_name="gitea"
-pkg_common_opt="$HOME/.local"
+pkg_dst="$HOME/.local"
-# just a junk file so that the version check always fails for non-current versions
-pkg_new_opt="$HOME/.local/opt/gitea-doesntexist111"
+# pkg_src isn't used in this script,
+# just setting a junk value for completeness (and possibly debug output)
+pkg_src="$HOME/Downloads/$WEBI_PKG_FILE"
pkg_get_current_version() {
# 'gitea version' has output in this format:
echo "$pkg_cmd_name v$my_version"
}
-pkg_link_new_version() {
+pkg_link_src_dst() {
# gitea is just a single file, no directory linking to do
true
}
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/bin/gitea" by default)
- mkdir -p "$pkg_common_bin"
- mv ./"$pkg_cmd_name"* "$pkg_common_cmd"
- chmod a+x "$pkg_common_cmd"
+ mkdir -p "$pkg_dst_bin"
+ mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
+ chmod a+x "$pkg_dst_cmd"
popd 2>&1 >/dev/null
}
pkg_post_install() {
# just in case we add something in the future
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
# Adds "$HOME/.local/bin" to PATH
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
}
pkg_post_install_message() {
- echo "Installed 'gitea' as $pkg_common_cmd"
+ echo "Installed 'gitea' v$WEBI_VERSION as $pkg_dst_cmd"
}
# NOTE: pkg_* variables can be defined here
# pkg_cmd_name
-# pkg_new_opt, pkg_new_bin, pkg_new_cmd
-# pkg_common_opt, pkg_common_bin, pkg_common_cmd
+# pkg_src, pkg_src_bin, pkg_src_cmd
+# pkg_dst, pkg_dst_bin, pkg_dst_cmd
#
# Their defaults are defined in webi/template.bash at https://github.com/webinstall/packages
echo "${pkg_cmd_name}${my_version}"
}
-pkg_link_new_version() {
- # 'pkg_common_opt' will default to $HOME/.local/opt/go
- # 'pkg_new_opt' will be the installed version, such as to $HOME/.local/opt/go-v1.14.2
- rm -rf "$pkg_common_opt"
- ln -s "$pkg_new_opt" "$pkg_common_opt"
+pkg_link_src_dst() {
+ # 'pkg_dst' will default to $HOME/.local/opt/go
+ # 'pkg_src' will be the installed version, such as to $HOME/.local/opt/go-v1.14.2
+ rm -rf "$pkg_dst"
+ ln -s "$pkg_src" "$pkg_dst"
# Go has a special $GOBIN
pushd "$WEBI_TMP" 2>&1 >/dev/null
# remove the versioned folder, just in case it's there with junk
- rm -rf "$pkg_new_opt"
+ rm -rf "$pkg_src"
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/opt/go-v$WEBI_VERSION" by default)
- mv ./"$pkg_cmd_name"* "$pkg_new_opt"
+ mv ./"$pkg_cmd_name"* "$pkg_src"
popd 2>&1 >/dev/null
}
pkg_post_install() {
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
# Updates PATH with
# "$HOME/.local/opt/go"
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
webi_path_add "$GOBIN/bin"
# Install x go
echo "Installing go extended tools (goimports, gorename, etc)"
- "$pkg_common_cmd" get golang.org/x/tools/cmd/goimports > /dev/null 2>/dev/null
- "$pkg_common_cmd" get golang.org/x/tools/cmd/gorename > /dev/null 2>/dev/null
- "$pkg_common_cmd" get golang.org/x/tools/cmd/gotype > /dev/null 2>/dev/null
- "$pkg_common_cmd" get golang.org/x/tools/cmd/stringer > /dev/null 2>/dev/null
+ "$pkg_dst_cmd" get golang.org/x/tools/cmd/goimports > /dev/null 2>/dev/null
+ "$pkg_dst_cmd" get golang.org/x/tools/cmd/gorename > /dev/null 2>/dev/null
+ "$pkg_dst_cmd" get golang.org/x/tools/cmd/gotype > /dev/null 2>/dev/null
+ "$pkg_dst_cmd" get golang.org/x/tools/cmd/stringer > /dev/null 2>/dev/null
}
pkg_post_install_message() {
set -u
pkg_cmd_name="hugo"
-pkg_common_opt="$HOME/.local"
+pkg_dst="$HOME/.local"
-# just a junk file so that the version check always fails for non-current versions
-pkg_new_opt="$HOME/.local/opt/hugo-doesntexist111"
+# pkg_src isn't used in this script,
+# just setting a junk value for completeness (and possibly debug output)
+pkg_src="$HOME/Downloads/$WEBI_PKG_FILE"
pkg_get_current_version() {
# 'hugo version' has output in this format:
echo "$pkg_cmd_name v$my_version"
}
-pkg_link_new_version() {
+pkg_link_src_dst() {
# hugo is just a single file, no directory linking to do
true
}
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/opt/node-v$WEBI_VERSION" by default)
- mkdir -p "$pkg_common_bin"
- mv ./"$pkg_cmd_name"* "$pkg_common_cmd"
- chmod a+x "$pkg_common_cmd"
+ mkdir -p "$pkg_dst_bin"
+ mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
+ chmod a+x "$pkg_dst_cmd"
popd 2>&1 >/dev/null
}
pkg_post_install() {
# just in case we add something in the future
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
# Adds "$HOME/.local/opt/node" to PATH
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
}
echo "$pkg_cmd_name v$my_version"
}
-pkg_link_new_version() {
- # 'pkg_common_opt' will default to $HOME/.local/opt/node
- # 'pkg_new_opt' will be the installed version, such as to $HOME/.local/opt/node-v12.8.0
- rm -rf "$pkg_common_opt"
- ln -s "$pkg_new_opt" "$pkg_common_opt"
+pkg_link_src_dst() {
+ # '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
+ rm -rf "$pkg_dst"
+ ln -s "$pkg_src" "$pkg_dst"
}
pkg_pre_install() {
pushd "$WEBI_TMP" 2>&1 >/dev/null
# remove the versioned folder, just in case it's there with junk
- rm -rf "$pkg_new_opt"
+ rm -rf "$pkg_src"
# rename the entire extracted folder to the new location
# (this will be "$HOME/.local/opt/node-v$WEBI_VERSION" by default)
# ex (full directory): ./node-v13-linux-amd64/bin/node.exe
- mv ./"$pkg_cmd_name"* "$pkg_new_opt"
+ mv ./"$pkg_cmd_name"* "$pkg_src"
# ex (single file): ./caddy-v13-linux-amd64.exe
- #mv ./"$pkg_cmd_name"* "$pkg_common_cmd"
- #chmod a+x "$pkg_common_cmd"
+ #mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
+ #chmod a+x "$pkg_dst_cmd"
# ex (single file, nested in directory): ./rg/rg-v13-linux-amd64
#mv ./"$pkg_cmd_name"*/"$pkg_cmd_name"* "$pkg_commend_cmd"
- #chmod a+x "$pkg_common_cmd"
+ #chmod a+x "$pkg_dst_cmd"
popd 2>&1 >/dev/null
}
pkg_post_install() {
- pkg_link_new_version
+ pkg_link_src_dst
# web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
# Adds "$HOME/.local/opt/node/bin" to PATH
- webi_path_add "$pkg_common_bin"
+ webi_path_add "$pkg_dst_bin"
}
pkg_post_install_message() {
pkg_current_version="$(pkg_get_current_version)"
# remove trailing '.0's for golang's sake
my_current_version="$(echo $pkg_current_version | sed 's:\.0::g')"
- my_new_version="$(echo $WEBI_VERSION | sed 's:\.0::g')"
+ my_src_version="$(echo $WEBI_VERSION | sed 's:\.0::g')"
if [ -n "$(command -v pkg_format_cmd_version)" ]; then
my_canonical_name="$(pkg_format_cmd_version "$WEBI_VERSION")"
else
#my_canonical_name="$WEBI_NAME $WEBI_VERSION"
my_canonical_name="$pkg_cmd_name v$WEBI_VERSION"
fi
- if [ "$my_new_version" == "$my_current_version" ]; then
+ if [ "$my_src_version" == "$my_current_version" ]; then
echo "$my_canonical_name already installed at $my_current_cmd"
exit 0
else
- if [ "$my_current_cmd" != "$pkg_common_cmd" ]; then
+ if [ "$my_current_cmd" != "$pkg_dst_cmd" ]; then
echo "WARN: possible conflict between $my_canonical_name and $pkg_current_version at $my_current_cmd"
fi
- if [ -x "$pkg_new_cmd" ]; then
- pkg_link_new_version
- echo "switched to $my_canonical_name at $pkg_new_opt"
+ if [ -x "$pkg_src_cmd" ]; then
+ pkg_link_src_dst
+ echo "switched to $my_canonical_name at $pkg_src"
exit 0
fi
fi
if [ -n "$(command -v pkg_install)" ]; then
pkg_cmd_name="${pkg_cmd_name:-$WEBI_NAME}"
- pkg_common_opt="${pkg_common_opt:-$HOME/.local/opt/$pkg_cmd_name}"
- pkg_common_bin="${pkg_common_bin:-$pkg_common_opt/bin}"
- pkg_common_cmd="${pkg_common_cmd:-$pkg_common_bin/$pkg_cmd_name}"
+ pkg_dst="${pkg_dst:-$HOME/.local/opt/$pkg_cmd_name}"
+ pkg_dst_bin="${pkg_dst_bin:-$pkg_common/bin}"
+ pkg_dst_cmd="${pkg_dst_cmd:-$pkg_dst_bin/$pkg_cmd_name}"
- pkg_new_opt="${pkg_new_opt:-$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION}"
- pkg_new_bin="${pkg_new_bin:-$pkg_new_opt/bin}"
- pkg_new_cmd="${pkg_new_cmd:-$pkg_new_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}"
[ -n "$(command -v pkg_pre_install)" ] && pkg_pre_install
- echo "Installing '$pkg_cmd_name' v$WEBI_VERSION as $pkg_new_cmd"
+ echo "Installing '$pkg_cmd_name' v$WEBI_VERSION as $pkg_src_cmd"
pkg_install
[ -n "$(command -v pkg_post_install)" ] && pkg_post_install
if [ -n "$(command -v pkg_post_install_message)" ]; then
pkg_post_install_message
else
- echo "Installed '$pkg_cmd_name' v$WEBI_VERSION as $pkg_new_cmd"
+ echo "Installed '$pkg_cmd_name' v$WEBI_VERSION as $pkg_src_cmd"
fi
echo ""
fi