bugfix(_example): vars should be quoted (and disable unexported vars warning)
[webi-installers/.git] / _example / install.sh
1 #!/bin/bash
2
3 # shellcheck disable=SC2034
4 # "'pkg_cmd_name' appears unused. Verify it or export it."
5
6 function __init_foobar() {
7     set -e
8     set -u
9
10     ##################
11     # Install foobar #
12     ##################
13
14     # Every package should define these 6 variables
15     pkg_cmd_name="foo"
16
17     pkg_dst_cmd="$HOME/.local/bin/foo"
18     pkg_dst="$pkg_dst_cmd"
19
20     pkg_src_cmd="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin/foo"
21     pkg_src_dir="$HOME/.local/opt/foobar-v$WEBI_VERSION"
22     pkg_src="$pkg_src_cmd"
23
24     # pkg_install must be defined by every package
25     pkg_install() {
26         # ~/.local/opt/foobar-v0.99.9/bin
27         mkdir -p "$(dirname "${pkg_src_cmd}")"
28
29         # mv ./foobar-*/foo ~/.local/opt/foobar-v0.99.9/bin/foo
30         mv ./foobar-*/foo "${pkg_src_cmd}"
31     }
32
33     # pkg_get_current_version is recommended, but not required
34     pkg_get_current_version() {
35         # 'foo --version' has output in this format:
36         #       foobar 0.99.9 (rev abcdef0123)
37         # This trims it down to just the version number:
38         #       0.99.9
39         foo --version 2> /dev/null |
40             head -n 1 |
41             cut -d ' ' -f 2
42     }
43
44 }
45
46 __init_foobar