add examples
[webi-installers/.git] / serviceman / serviceman.bash
1 #!/bin/bash
2
3 # title: Serviceman
4 # homepage: https://git.rootprojects.org/root/serviceman
5 # tagline: cross-platform service management for Linux, Mac, and Windows
6 # description: |
7 #   Works with
8 #   - Launchd (macOS)
9 #   - Systemd (Linux)
10 #   - Windows Registry
11 # examples: |
12 #   ```bash
13 #   serviceman add --name my-service ./serve.js --port 3000
14 #   ```
15
16 set -e
17 set -u
18
19 # Get arch envs, etc
20 my_url="https://rootprojects.org/serviceman/dist/$(uname -s)/$(uname -m)/serviceman"
21 curl -fL "$my_url" -o serviceman
22 echo ""
23 # Make executable
24 chmod +x ./serviceman
25 # Move to ~/.local/bin
26 mkdir -p ~/.local/bin
27 mv ./serviceman ~/.local/bin
28
29 # Test if in PATH
30 set +e
31 my_serviceman=$(command -v serviceman)
32 set -e
33 if [ -n "$my_serviceman" ]; then
34         if [ "$my_serviceman" != "$HOME/.local/bin/serviceman" ]; then
35                 echo "a serviceman installation (which make take precedence) exists at:"
36                 echo "    $my_serviceman"
37                 echo ""
38         fi
39 fi
40
41 # add to ~/.local/bin to PATH, just in case
42 pathman add ~/.local/bin # > /dev/null 2> /dev/null
43 # TODO inform user to add to path, apart from pathman?