mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-03-03 01:40:17 +00:00
update caddy installer with latest functions
This commit is contained in:
@@ -11,47 +11,55 @@
|
||||
set -e
|
||||
set -u
|
||||
|
||||
#################
|
||||
# Install caddy #
|
||||
#################
|
||||
pkg_cmd_name="caddy"
|
||||
pkg_common_opt="$HOME/.local"
|
||||
|
||||
new_caddy="${HOME}/.local/bin/caddy"
|
||||
# just a junk file so that the version check always fails for non-current versions
|
||||
pkg_new_opt="$HOME/.local/opt/caddy-doesntexist111"
|
||||
|
||||
# Test for existing version
|
||||
set +e
|
||||
cur_caddy="$(command -v caddy)"
|
||||
set -e
|
||||
if [ -n "$cur_caddy" ]; then
|
||||
cur_ver=$(caddy version | head -n 1 | cut -d ' ' -f 2)
|
||||
if [ "$cur_ver" == "$WEBI_VERSION" ]; then
|
||||
echo "caddy v$WEBI_VERSION already installed at $cur_caddy"
|
||||
exit 0
|
||||
elif [ "$cur_caddy" != "$new_caddy" ]; then
|
||||
echo "WARN: possible conflict with caddy v$WEBI_VERSION at $cur_caddy"
|
||||
fi
|
||||
fi
|
||||
pkg_get_current_version() {
|
||||
# 'caddy version' has output in this format:
|
||||
# v2.1.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=
|
||||
# This trims it down to just the version number:
|
||||
# 2.0.0
|
||||
echo "$(caddy version 2>/dev/null | head -n 1 | cut -d ' ' -f1 | sed 's:^v::')"
|
||||
}
|
||||
|
||||
# Note: this file is `source`d by the true installer and hence will have the webi functions
|
||||
pkg_format_cmd_version() {
|
||||
# 'node v12.8.0' is the canonical version format for node
|
||||
my_version="$1"
|
||||
echo "$pkg_cmd_name v$my_version"
|
||||
}
|
||||
|
||||
# because we created releases.js we can use webi_download()
|
||||
# downloads caddy to ~/Downloads
|
||||
webi_download
|
||||
pkg_link_new_version() {
|
||||
# caddy is just a single file, no directory linking to do
|
||||
}
|
||||
|
||||
# because this is tar or zip, we can webi_extract()
|
||||
# extracts to the WEBI_TMP directory, raw (no --strip-prefix)
|
||||
webi_extract
|
||||
pkg_pre_install() {
|
||||
# if selected version is installed, quit
|
||||
webi_check
|
||||
# will save to ~/Downloads/$WEBI_PKG_FILE by default
|
||||
webi_download
|
||||
# supported formats (.xz, .tar.*, .zip) will be extracted to $WEBI_TMP
|
||||
webi_extract
|
||||
}
|
||||
|
||||
pushd "$WEBI_TMP" 2>&1 >/dev/null
|
||||
echo Installing caddy v${WEBI_VERSION} as "$new_caddy"
|
||||
mv ./caddy "$HOME/.local/bin/"
|
||||
popd 2>&1 >/dev/null
|
||||
pkg_install() {
|
||||
pushd "$WEBI_TMP" 2>&1 >/dev/null
|
||||
|
||||
###################
|
||||
# Update PATH #
|
||||
###################
|
||||
# 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"
|
||||
|
||||
# TODO get better output from pathman / output the path to add as return to webi bootstrap
|
||||
webi_path_add "$HOME/.local/bin"
|
||||
popd 2>&1 >/dev/null
|
||||
}
|
||||
|
||||
echo "Installed 'caddy'"
|
||||
echo ""
|
||||
pkg_post_install() {
|
||||
# just in case we add something in the future
|
||||
pkg_link_new_version
|
||||
|
||||
# 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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user