5f6a98f6b50a9a26c4d37da7110ae4e639e465d6
[webi-installers/.git] / caddy / install.bash
1 # title: Caddy
2 # homepage: https://github.com/caddyserver/caddy
3 # tagline: Fast, multi-platform web server with automatic HTTPS
4 # description: |
5 #   Caddy is an extensible server platform that uses TLS by default.
6 # examples: |
7 #   ```bash
8 #   caddy start
9 #   ```
10
11 set -e
12 set -u
13
14 pkg_cmd_name="caddy"
15 pkg_dst="$HOME/.local"
16
17 # the "source" here isn't used, nor very meaningful,
18 # but we'll use the download location as a junk value
19 pkg_src="$HOME/Downloads/$WEBI_PKG_FILE"
20
21 pkg_get_current_version() {
22     # 'caddy version' has output in this format:
23     #       v2.1.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=
24     # This trims it down to just the version number:
25     #       2.0.0
26     echo "$(caddy version 2>/dev/null | head -n 1 | cut -d' ' -f1 | sed 's:^v::')"
27 }
28
29 pkg_format_cmd_version() {
30     # 'caddy v2.1.0' is the canonical version format for caddy
31     my_version="$1"
32     echo "$pkg_cmd_name v$my_version"
33 }
34
35 pkg_link_src_dst() {
36     # caddy is just a single file, no directory linking to do
37     true
38 }
39
40 pkg_pre_install() {
41     # if selected version is installed, quit
42     webi_check
43     # will save to ~/Downloads/$WEBI_PKG_FILE by default
44     webi_download
45     # supported formats (.xz, .tar.*, .zip) will be extracted to $WEBI_TMP
46     webi_extract
47 }
48
49 pkg_install() {
50     pushd "$WEBI_TMP" 2>&1 >/dev/null
51
52         # ensure the bin dir exists
53         mkdir -p "$pkg_dst_bin"
54
55         # rename the entire extracted folder to the new location
56         # (this will be "$HOME/.local/bin/caddy", as set above)
57
58         # ex (full directory): ./node-v13-linux-amd64/bin/node.exe
59         #mv ./"$pkg_cmd_name"* "$pkg_src"
60
61         # ex (single file): ./caddy-v2.0.0-linux-amd64.exe
62         mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
63         chmod a+x "$pkg_dst_cmd"
64
65         # ex (single file, nested in directory): ./rg/rg-v13-linux-amd64
66         #mv ./"$pkg_cmd_name"*/"$pkg_cmd_name"* "$pkg_commend_cmd"
67         #chmod a+x "$pkg_dst_cmd"
68
69     popd 2>&1 >/dev/null
70 }
71
72 pkg_post_install() {
73     # just in case we add something in the future
74     pkg_link_src_dst
75
76     # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
77     # Adds "$HOME/.local/bin" to PATH
78     webi_path_add "$pkg_dst_bin"
79 }
80
81 pkg_post_install_message() {
82     echo "Installed 'caddy' v$WEBI_VERSION as $pkg_dst_cmd"
83 }