generalize, a lot
[webi-installers/.git] / pathman / install.sh
1 #!/bin/bash
2
3 # title: Pathman
4 # homepage: https://git.rootprojects.org/root/pathman
5 # tagline: cross-platform PATH management for bash, zsh, fish, cmd.exe, and PowerShell
6 # description: |
7 #   Manages PATH on various OSes and shells
8 #     - Mac, Windows, Linux
9 #     - Bash, Zsh, Fish
10 #     - Command, Powershell
11 # examples: |
12 #   ```bash
13 #   pathman add ~/.local/bin
14 #   ```
15 #   <br/>
16 #
17 #   ```bash
18 #   pathman remove ~/.local/bin
19 #   ```
20 #   <br/>
21 #
22 #   ```bash
23 #   pathman list
24 #   ```
25
26
27 set -e
28 set -u
29
30 pkg_cmd_name="pathman"
31 WEBI_SINGLE=true
32
33 pkg_get_current_version() {
34     echo $(pathman version 2>/dev/null | head -n 1 | cut -d ' ' -f2 | sed 's:^v::')
35 }
36
37 x_pkg_pre_install() {
38     # Test if in PATH
39     set +e
40     my_pathman=$(command -v pathman)
41     set -e
42     if [ -n "$my_pathman" ]; then
43         # TODO test pathman version
44         # if [ "$WEBI_VERSION" == "$(pathman version | cut -d ' ' -f2)" ]; then
45         if [ "$my_pathman" != "$HOME/.local/bin/pathman" ]; then
46             echo "a pathman installation (which make take precedence) exists at:"
47             echo "    $my_pathman"
48             echo ""
49         fi
50         echo "pathman already installed"
51         exit 0
52     fi
53 }
54
55 x_pkg_install() {
56     # TODO use webi_download via releases.js
57     mkdir -p "$HOME/.local/bin/"
58     webi_check
59     webi_download
60     webi_download
61     # webi_download "https://rootprojects.org/pathman/dist/$(uname -s)/$(uname -m)/pathman"
62     mv "$HOME/Downloads/pathman-v0.5.2" "$HOME/.local/bin/pathman"
63     chmod +x "$HOME/.local/bin/pathman"
64 }
65
66 x_pkg_link() {
67     true
68 }
69
70 pkg_post_install() {
71     # add to ~/.local/bin to PATH even if pathman is elsewhere
72     # TODO pathman needs silent option and debug output (quiet "already exists" output)
73     # TODO inform user to add to path, apart from pathman?
74     "$HOME/.local/bin/pathman" add "$HOME/.local/bin"
75 }
76
77 pkg_done_message() {
78     true
79 }