begin support for batch templating
[webi-installers/.git] / _webi / template.sh
index 191cf1081944fcf86170b0491836fcec72633dd4..7a16ae275819eaf3c3f0e75c8ec377489fffeecc 100644 (file)
@@ -22,6 +22,7 @@ set -u
 #WEBI_LTS=
 #WEBI_CHANNEL=
 #WEBI_EXT=
+#WEBI_FORMATS=
 #WEBI_PKG_URL=
 #WEBI_PKG_FILE=
 WEBI_UA="$(uname -a)"
@@ -45,6 +46,8 @@ export WEBI_CURL="$(command -v curl)"
 export WEBI_WGET="$(command -v wget)"
 set -e
 
+
+# get the special formatted version (i.e. "go is go1.14" while node is "node v12.10.8")
 my_versioned_name=""
 _webi_canonical_name() {
     if [ -n "$my_versioned_name" ]; then
@@ -61,6 +64,7 @@ _webi_canonical_name() {
     echo "$my_versioned_name"
 }
 
+# update symlinks according to $HOME/.local/opt and $HOME/.local/bin install paths.
 webi_link() {
     if [ -n "$(command -v pkg_link)" ]; then
         pkg_link
@@ -68,24 +72,27 @@ webi_link() {
     fi
 
     if [ -n "$WEBI_SINGLE" ] || [ "single" == "${1:-}" ]; then
-        if [ -d "$pkg_dst_cmd" ]; then
-            rm -rf -i "$pkg_dst_cmd"
-        else
+        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
         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 [ -d "$pkg_dst" ]; then
-            rm -rf -i "$pkg_dst"
-        else
+        if [ -L "$pkg_dst" ]; then
             rm -f "$pkg_dst"
+        elif [ -e "$pkg_dst" ]; then
+            echo "remove $pkg_dst?"
+            rm -rf -i "$pkg_dst"
         fi
         ln -s "$pkg_src" "$pkg_dst"
     fi
 }
 
+# detect if this program is already installed or if an installed version may cause conflict
 webi_check() {
     # Test for existing version
     set +e
@@ -113,6 +120,7 @@ webi_check() {
     fi
 }
 
+# detect if file is downloaded, and how to download it
 webi_download() {
     if [ -n "${1:-}" ]; then
         my_url="$1"
@@ -121,6 +129,12 @@ webi_download() {
             # TODO pass back requested OS / Arch / Version
             echo "Error: no '$WEBI_NAME' release found for the given OS and architecture by that tag or version"
             echo "       (check that the package name and version are correct)"
+            echo "See $WEBI_RELEASES"
+            echo "        WEBI_PKG=$WEBI_PKG"
+            echo "        WEBI_NAME=$WEBI_NAME"
+            echo "        WEBI_VERSION=$WEBI_VERSION"
+            echo "        WEBI_EXT=$WEBI_EXT"
+            echo "        WEBI_FORMATS=$WEBI_FORMATS"
             exit 1
         fi
         my_url="$WEBI_PKG_URL"
@@ -159,6 +173,7 @@ webi_download() {
     mv "$my_dl.part" "$my_dl"
 }
 
+# detect which archives can be used
 webi_extract() {
     pushd "$WEBI_TMP" 2>&1 >/dev/null
         if [ "tar" == "$WEBI_EXT" ]; then
@@ -181,6 +196,7 @@ webi_extract() {
     popd 2>&1 >/dev/null
 }
 
+# use 'pathman' to update $HOME/.config/envman/PATH.env
 webi_path_add() {
     # make sure that we don't recursively install pathman with webi
     my_path="$PATH"
@@ -200,12 +216,14 @@ webi_path_add() {
     "$HOME/.local/bin/pathman" add "$1"
 }
 
+# group common pre-install tasks as default
 webi_pre_install() {
     webi_check
     webi_download
     webi_extract
 }
 
+# move commands from the extracted archive directory to $HOME/.local/opt or $HOME/.local/bin
 webi_install() {
     if [ -n "$WEBI_SINGLE" ] || [ "single" == "${1:-}" ]; then
         mkdir -p "$(dirname $pkg_src_cmd)"
@@ -213,26 +231,29 @@ webi_install() {
         chmod a+x "$pkg_src_cmd"
     else
         mkdir -p "$(dirname $pkg_src)"
-        if [ -d "$pkg_src" ]; then
-            rm -rf -i "$pkg_src"
-        else
+        if [ -L "$pkg_src" ]; then
             rm -f "$pkg_src"
+        elif [ -e "$pkg_src" ]; then
+            echo "remove $pkg_src?"
+            rm -rf -i "$pkg_src"
         fi
         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"
 }
 
+# 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"
 }
 
 ##
 ##
-## BEGIN user-submited script
+## BEGIN custom override functions from <package>/install.sh
 ##
 ##
 
@@ -246,10 +267,11 @@ WEBI_SINGLE=
 
 ##
 ##
-## END user-submitted script
+## END custom override functions
 ##
 ##
 
+# run everything with defaults or overrides as needed
 if [ -n "$(command -v pkg_get_current_version)" ]; then
     pkg_cmd_name="${pkg_cmd_name:-$WEBI_NAME}"
 
@@ -291,6 +313,9 @@ if [ -n "$(command -v pkg_get_current_version)" ]; then
     echo ""
 fi
 
+# cleanup the temp directory
 rm -rf "$WEBI_TMP"
 
+# See? No magic. Just downloading and moving files.
+
 }