chore(style): add shebang, set bash strict mode, create function
[webi-installers/.git] / serviceman / install.sh
index 690d44a6d30dbe1218c1e5fe46887af405446190..ae14c59ed0418d5a418149ef6020ddd79b9881a4 100644 (file)
@@ -1,54 +1,42 @@
 #!/bin/bash
 
-# title: Serviceman
-# homepage: https://git.rootprojects.org/root/serviceman
-# tagline: |
-#   Serviceman: cross-platform service management for Linux, Mac, and Windows.
-# description: |
-#   Serviceman is a hassle-free wrapper around your system launcher. It works with `launchctl` (macOS), `systemctl` (Linux), and the Windows Registry to make it easy to start _user_ and _system_ level services, such as webservers, backup scripts, network and system tools, etc.
-# examples: |
-#
-#   Works with anything, including
-#
-#   ### Node.js
-#
-#   ```bash
-#   serviceman add --name my-service node ./serve.js --port 3000
-#   ```
-#
-#   ### Golang
-#
-#   ```bash
-#   go build -mod vendor cmd/my-service
-#   serviceman add ./my-service --port 3000
-#   ```
-#
-#   ### And even bash!
-#
-#   ```bash
-#   serviceman add --name backuper bash ./backup.sh /mnt/data
-#   ```
-
-set -e
-set -u
-
-# Test if in PATH
-set +e
-my_serviceman=$(command -v serviceman)
-set -e
-if [ -n "$my_serviceman" ]; then
-       if [ "$my_serviceman" != "$HOME/.local/bin/serviceman" ]; then
-               echo "a serviceman installation (which make take precedence) exists at:"
-               echo "    $my_serviceman"
-               echo ""
-       fi
-fi
-
-# Get arch envs, etc
-webi_download "https://rootprojects.org/serviceman/dist/$(uname -s)/$(uname -m)/serviceman" "$HOME/Downloads/serviceman"
-chmod +x "$HOME/Downloads/serviceman"
-mv "$HOME/Downloads/serviceman" "$HOME/.local/bin/"
-
-# add to ~/.local/bin to PATH, just in case
-webi_path_add $HOME/.local/bin # > /dev/null 2> /dev/null
-# TODO inform user to add to path, apart from pathman?
+function __init_serviceman() {
+    set -e
+    set -u
+
+    ######################
+    # Install serviceman #
+    ######################
+
+    # Every package should define these 6 variables
+    pkg_cmd_name="serviceman"
+
+    pkg_dst_cmd="$HOME/.local/bin/serviceman"
+    pkg_dst="$pkg_dst_cmd"
+
+    pkg_src_cmd="$HOME/.local/opt/serviceman-v$WEBI_VERSION/bin/serviceman"
+    pkg_src_dir="$HOME/.local/opt/serviceman-v$WEBI_VERSION"
+    pkg_src="$pkg_src_cmd"
+
+    pkg_install() {
+        # $HOME/.local/opt/serviceman-v0.8.0/bin
+        mkdir -p "$pkg_src_bin"
+
+        # mv ./serviceman* "$HOME/.local/opt/serviceman-v0.8.0/bin/serviceman"
+        mv ./"$pkg_cmd_name"* "$pkg_src_cmd"
+
+        # chmod a+x "$HOME/.local/opt/serviceman-v0.8.0/bin/serviceman"
+        chmod a+x "$pkg_src_cmd"
+    }
+
+    pkg_get_current_version() {
+        # 'serviceman version' has output in this format:
+        #       serviceman v0.8.0 (f3ab547) 2020-12-02T16:19:10-07:00
+        # This trims it down to just the version number:
+        #       0.8.0
+        echo "$(serviceman --version 2> /dev/null | head -n 1 | cut -d' ' -f2 | sed 's:^v::')"
+    }
+
+}
+
+__init_serviceman