chore(style): add shebang, set bash strict mode, create function
[webi-installers/.git] / xz / install.sh
1 #!/bin/bash
2 set -e
3 set -u
4
5 function __init_xz() {
6
7     ##############
8     # Install xz #
9     ##############
10
11     # Every package should define these 6 variables
12     pkg_cmd_name="xz"
13
14     pkg_dst_cmd="$HOME/.local/bin/xz"
15     pkg_dst="$pkg_dst_cmd"
16
17     pkg_src_cmd="$HOME/.local/opt/xz-v$WEBI_VERSION/bin/xz"
18     pkg_src_dir="$HOME/.local/opt/xz-v$WEBI_VERSION"
19     pkg_src="$pkg_src_cmd"
20
21     # pkg_install must be defined by every package
22     pkg_install() {
23         # ~/.local/opt/xz-v5.2.5/bin
24         mkdir -p "$(dirname $pkg_src_cmd)"
25
26         # mv ./xz-*/{xz,xzdec} ~/.local/opt/xz-v5.2.5/bin/
27         mv ./xz-*/xz* "$(dirname $pkg_src_cmd)"
28         ln -s xz "$(dirname $pkg_src_cmd)/unxz"
29     }
30
31     pkg_post_install() {
32         # supplements webi_link
33         ln -s xz "$(dirname $pkg_dst_cmd)/unxz"
34
35         webi_post_install
36     }
37
38     # pkg_get_current_version is recommended, but (soon) not required
39     pkg_get_current_version() {
40         # 'xz --version' has output in this format:
41         #       xz (XZ Utils) 5.2.5
42         #       liblzma 5.2.5
43         # This trims it down to just the version number:
44         #       5.2.5
45         echo $(xz --version 2> /dev/null | head -n 1 | cut -d ' ' -f 4)
46     }
47 }
48
49 __init_xz