update variables _new_ => _src_, _common_ => _dst_,
[webi-installers/.git] / hugo / install.bash
1 # title: Hugo
2 # homepage: https://github.com/gohugoio/hugo
3 # tagline: The world’s fastest framework for building websites
4 # description: |
5 #   Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.
6 # examples: |
7 #   ```bash
8 #   hugo
9 #   ```
10 #
11 #   ```bash
12 #   hugo server -D
13 #   ```
14
15 set -e
16 set -u
17
18 pkg_cmd_name="hugo"
19 pkg_dst="$HOME/.local"
20
21 # pkg_src isn't used in this script,
22 # just setting a junk value for completeness (and possibly debug output)
23 pkg_src="$HOME/Downloads/$WEBI_PKG_FILE"
24
25 pkg_get_current_version() {
26     # 'hugo version' has output in this format:
27     #       Hugo Static Site Generator v0.72.0-8A7EF3CF darwin/amd64 BuildDate: 2020-05-31T12:07:44Z
28     # This trims it down to just the version number:
29     #       0.72.0
30     echo "$(hugo version 2>/dev/null | head -n 1 | cut -d' ' -f5 | cut -d '-' -f1 | sed 's:^v::')"
31 }
32
33 pkg_format_cmd_version() {
34     # 'node v12.8.0' is the canonical version format for node
35     my_version="$1"
36     echo "$pkg_cmd_name v$my_version"
37 }
38
39 pkg_link_src_dst() {
40     # hugo is just a single file, no directory linking to do
41     true
42 }
43
44 pkg_pre_install() {
45     # if selected version is installed, quit
46     webi_check
47     # will save to ~/Downloads/$WEBI_PKG_FILE by default
48     webi_download
49     # supported formats (.xz, .tar.*, .zip) will be extracted to $WEBI_TMP
50     webi_extract
51 }
52
53 pkg_install() {
54     pushd "$WEBI_TMP" 2>&1 >/dev/null
55
56         # rename the entire extracted folder to the new location
57         # (this will be "$HOME/.local/opt/node-v$WEBI_VERSION" by default)
58         mkdir -p "$pkg_dst_bin"
59         mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
60         chmod a+x "$pkg_dst_cmd"
61
62     popd 2>&1 >/dev/null
63 }
64
65 pkg_post_install() {
66     # just in case we add something in the future
67     pkg_link_src_dst
68
69     # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
70     # Adds "$HOME/.local/opt/node" to PATH
71     webi_path_add "$pkg_dst_bin"
72 }