59112022ed23d81ad31ae51faf182a30f97fa4c9
[webi-installers/.git] / hugo / install.sh
1 set -e
2 set -u
3
4 pkg_cmd_name="hugo"
5 pkg_dst="$HOME/.local"
6
7 # pkg_src isn't used in this script,
8 # just setting a junk value for completeness (and possibly debug output)
9 pkg_src="$HOME/Downloads/$WEBI_PKG_FILE"
10
11 pkg_get_current_version() {
12     # 'hugo version' has output in this format:
13     #       Hugo Static Site Generator v0.72.0-8A7EF3CF darwin/amd64 BuildDate: 2020-05-31T12:07:44Z
14     # This trims it down to just the version number:
15     #       0.72.0
16     echo "$(hugo version 2>/dev/null | head -n 1 | cut -d' ' -f5 | cut -d '-' -f1 | sed 's:^v::')"
17 }
18
19 pkg_format_cmd_version() {
20     # 'node v12.8.0' is the canonical version format for node
21     my_version="$1"
22     echo "$pkg_cmd_name v$my_version"
23 }
24
25 pkg_link() {
26     # hugo is just a single file, no directory linking to do
27     true
28 }
29
30 pkg_pre_install() {
31     # if selected version is installed, quit
32     webi_check
33     # will save to ~/Downloads/$WEBI_PKG_FILE by default
34     webi_download
35     # supported formats (.xz, .tar.*, .zip) will be extracted to $WEBI_TMP
36     webi_extract
37 }
38
39 pkg_install() {
40     pushd "$WEBI_TMP" 2>&1 >/dev/null
41
42         # rename the entire extracted folder to the new location
43         # (this will be "$HOME/.local/opt/node-v$WEBI_VERSION" by default)
44         mkdir -p "$pkg_dst_bin"
45         mv ./"$pkg_cmd_name"* "$pkg_dst_cmd"
46         chmod a+x "$pkg_dst_cmd"
47
48     popd 2>&1 >/dev/null
49 }
50
51 pkg_post_install() {
52     # just in case we add something in the future
53     pkg_link
54
55     # web_path_add is defined in _webi/template.sh at https://github.com/webinstall/packages
56     # Adds "$HOME/.local/opt/node" to PATH
57     webi_path_add "$pkg_dst_bin"
58 }