-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·121 lines (112 loc) · 3.46 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
# vi:et lbr noet sw=2 ts=2 tw=79 wrap
# Copyright 2023-2025 David Rabkin
# Uses Unix shell framework shellbase:
# https://github.com/rdavid/shellbase/
# shellcheck disable=SC2034,SC3043 # Uses local variables, appears unused.
readonly \
BASE_APP_VERSION=0.9.20250122 \
BASE_MIN_VERSION=0.9.20230606 \
DST=/usr/local/bin \
GOR=0.9.20240303 \
PKG="\
curl \
dci-ansible \
dci-openshift-agent \
dci-openshift-app-agent \
jq \
python3-dciclient \
tar \
which" \
SHR=0.9.20241111 \
USR=dci-openshift-app-agent \
YQR=4.45.1
readonly \
GO=https://github.com/rdavid/gento/archive/refs/tags/v$GOR.tar.gz \
OC=https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable-4.14/openshift-client-linux.tar.gz \
SH=https://github.com/rdavid/shellbase/archive/refs/tags/v$SHR.tar.gz \
YQ=https://github.com/mikefarah/yq/releases/download/v$YQR/yq_linux_amd64
# Downloads an archive, extracts, and puts a single file to the destination.
# The first parameter is an package name, the second is an URL of an archive,
# the lasted arguments are a position of a file inside the archive to extract
# and install.
install_arc() {
local pkg="$1" url="$2"
shift 2
curl --location --silent "$url" |
tar --directory $DST --extract --gzip "$@" ||
die Failed to download and extract "$pkg".
log "$pkg" is installed or upgraded.
}
# Installs or updates needful RHEL packages. dnf upgrade does not fail if
# multiple packages are listed, and a single package succeeds, hence upgrade
# packages one by one.
install_dnf() {
local out pkg
for pkg in $PKG; do
out="$(dnf install --assumeyes --best --quiet "$pkg" 2>&1)" ||
die "Failed to install or upgrade $pkg. $out"
log "$pkg" is installed or upgraded.
done
}
# Downloads the executable to the destination.
install_yq() {
curl --location --output $DST/yq --silent $YQ ||
die Unable to install $YQ.
chmod +x $DST/yq || die Unable to add execute permission to $DST/yq.
log yq is installed or upgraded.
}
# Validates the environment and installs the software.
main() {
validate
install_arc gento $GO --strip-components=2 gento-$GOR/app/gento
install_arc oc $OC oc
install_arc shellbase $SH --strip-components=2 shellbase-$SHR/lib/base.sh
install_dnf
install_yq
}
# Installs shellbase to the current shell session. Packages curl and tar are
# required.
shellbase() {
local err pkg
for pkg in curl tar; do
command -v $pkg >/dev/null 2>&1 || {
err=$?
printf >&2 Install\ %s.\\n $pkg
exit $err
}
done
curl --fail --head --output /dev/null --silent $SH || {
err=$?
printf >&2 '%s is unavailable.\n' $SH
exit $err
}
eval "$(
curl --location --silent $SH |
tar --extract --gzip --to-stdout shellbase-$SHR/lib/base.sh
)"
[ -n "${BASE_VERSION+x}" ] || {
printf >&2 No\ shellbase.\\n
exit 1
}
log shellbase "$BASE_VERSION" is installed to the current shell session.
}
# Uses functions of shellbase to validate the environment.
validate() {
local dir uid
# shellcheck disable=SC1091,SC2015 # File not following, A && B || C.
[ -r $DST/base.sh ] && . $DST/base.sh || shellbase
beroot
validate_cmd curl dnf install tar
iswritable $DST || die $DST is not writable.
url_exists $GO $OC $SH $YQ || die
user_exists $USR || die $USR: Not such user.
# Verifies that XDG_RUNTIME_DIR exists and accessible by
# dci-openshift-app-agent.
uid="$(id -u $USR 2>&1)" || die "$uid"
dir=/run/user/"$uid"
install --directory --group $USR --mode 0700 --owner $USR "$dir" ||
die Unable to create "$dir".
}
# Starting point.
main "$@"