-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-ci-cd-repo.sh
executable file
·167 lines (144 loc) · 3.74 KB
/
install-ci-cd-repo.sh
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/sh
# shellcheck disable=SC2317
# install-ci-cd-repo.sh (https://github.com/webmin/webmin-ci-cd)
# Copyright Ilia Ross <[email protected]>
# Licensed under the MIT License
#
# Installs package repository configuration for CI/CD builds
url="https://raw.githubusercontent.com/webmin/webmin/master/webmin-setup-repo.sh"
virtualmin_license_file="/etc/virtualmin-license"
virtualmin_unstable_host="software.virtualmin.dev"
virtualmin_prerelease_host="rc.software.virtualmin.dev"
download_script() {
tmp_file=$(mktemp)
for downloader in "curl -fsSL" "wget -qO-"; do
if command -v "${downloader%% *}" >/dev/null 2>&1; then
case $downloader in
curl*) curl -fsSL "$1" > "$tmp_file" ;;
wget*) wget -qO- "$1" > "$tmp_file" ;;
esac
echo "$tmp_file"
return 0
fi
done
echo "Error: Neither curl nor wget is installed." >&2
return 1
}
check_virtualmin_license() {
if [ -f "$virtualmin_license_file" ]; then
serial=$(grep "SerialNumber" "$virtualmin_license_file" | cut -d= -f2)
license=$(grep "LicenseKey" "$virtualmin_license_file" | cut -d= -f2)
if [ "$serial" != "GPL" ] && [ "$license" != "GPL" ]; then
echo "--auth-user=$serial --auth-pass=$license"
fi
fi
return 0
}
set_virtualmin_package_preferences() {
fn_auth_user="$1"
fn_auth_pass="$2"
if [ -z "$fn_auth_user" ] || [ -z "$fn_auth_pass" ]; then
echo "deb:webmin-virtual-server=1001=gpl rpm:wbm-virtual-server*pro*"
fi
return 0
}
setup_repo() {
product="$1"
type="$2"
if ! script=$(download_script "$url"); then
return 1
fi
auth_user=""
auth_pass=""
[ "$product" = "virtualmin" ] && {
license_data=$(check_virtualmin_license)
auth_user=$(echo "$license_data" | awk '{print $1}')
auth_pass=$(echo "$license_data" | awk '{print $2}')
}
# Call package preference function if it exists
pkg_prefs=""
func="set_${product}_package_preferences"
if command -v "$func" >/dev/null 2>&1; then
pkg_prefs=$(eval "$func" "$auth_user" "$auth_pass")
fi
case "$product" in
webmin)
case "$type" in
prerelease) sh "$script" "--prerelease" "--force" ;;
unstable) sh "$script" "--unstable" "--force" ;;
esac
;;
virtualmin)
case "$type" in
prerelease)
set -- \
--force \
--prerelease-host="$virtualmin_prerelease_host" \
--name=virtualmin \
--dist=virtualmin \
--description=Virtualmin \
--component=main \
--check-binary=0 \
--prerelease
[ -n "$auth_user" ] && set -- "$@" "$auth_user"
[ -n "$auth_pass" ] && set -- "$@" "$auth_pass"
[ -n "$pkg_prefs" ] && set -- "$@" "--pkg-prefs=$pkg_prefs"
sh "$script" "$@"
;;
unstable)
set -- \
--force \
--unstable-host="$virtualmin_unstable_host" \
--name=virtualmin \
--dist=virtualmin \
--description=Virtualmin \
--component=main \
--check-binary=0 \
--unstable
[ -n "$auth_user" ] && set -- "$@" "$auth_user"
[ -n "$auth_pass" ] && set -- "$@" "$auth_pass"
[ -n "$pkg_prefs" ] && set -- "$@" "--pkg-prefs=$pkg_prefs"
sh "$script" "$@"
;;
esac
;;
esac
ret=$?
rm -f "$script"
return $ret
}
usage() {
if [ -n "${1-}" ]; then
echo "Error: $1"
echo
fi
echo "Usage: ${0##*/} <webmin|virtualmin> <prerelease|unstable>"
exit "${2:-1}"
}
main() {
# Check for help flags
case "${1-}" in
-h|--help)
usage "" 0
;;
esac
# Validate number of arguments
if [ $# -ne 2 ]; then
usage "Wrong number of arguments"
fi
product="$1"
repo_type="$2"
# Validate arguments
case "$product" in
webmin|virtualmin) ;;
*) usage "Invalid product name" ;;
esac
case "$repo_type" in
prerelease|unstable) ;;
*) usage "Invalid repository type" ;;
esac
# Setup repository
setup_repo "$product" "$repo_type"
exit $?
}
main "$@"