-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebmin-install.sh
202 lines (181 loc) · 5.2 KB
/
webmin-install.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#!/bin/sh
# shellcheck disable=SC1090 disable=SC2059 disable=SC2164 disable=SC2181
# setup-repos.sh
# Configures Webmin repository for RHEL and Debian systems (derivatives)
webmin_download="https://download.webmin.com"
webmin_key="jcameron-key.asc"
webmin_key_download="$webmin_download/$webmin_key"
developers_key="developers-key.asc"
developers_key_download="$webmin_download/$developers_key"
debian_repo_file="/etc/apt/sources.list.d/webmin.list"
rhel_repo_file="/etc/yum.repos.d/webmin.repo"
download_wget="/usr/bin/wget"
download="$download_wget -nv"
# Temporary colors
NORMAL=''
GREEN=''
RED=''
ITALIC=''
BOLD=''
if tty -s; then
NORMAL="$(tput sgr0)"
GREEN=$(tput setaf 2)
RED="$(tput setaf 1)"
BOLD=$(tput bold)
ITALIC=$(tput sitm)
fi
# Check user permission
if [ "$(id -u)" -ne 0 ]; then
echo "${RED}Error:${NORMAL} \`setup-repos.sh\` script must be run as root!" >&2
exit 1
fi
# Go to temp
cd "/tmp" 1>/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "${RED}Error:${NORMAL} Failed to switch to \`/tmp\` directory!"
exit 1
fi
# Check for OS release file
osrelease="/etc/os-release"
if [ ! -f "$osrelease" ]; then
echo "${RED}Error:${NORMAL} Cannot detect OS!"
exit 1
fi
# Detect OS and package manager and install command
. "$osrelease"
if [ -n "${ID_LIKE}" ]; then
osid="$ID_LIKE"
else
osid="$ID"
fi
if [ -z "$osid" ]; then
echo "${RED}Error:${NORMAL} Failed to detect OS!"
exit 1
fi
# Derivatives precise test
osid_debian_like=$(echo "$osid" | grep "debian\|ubuntu")
osid_rhel_like=$(echo "$osid" | grep "rhel\|fedora\|centos")
# Setup OS dependent
if [ -n "$osid_debian_like" ]; then
package_type=deb
install_cmd="apt-get install"
install="$install_cmd --quiet --assume-yes"
clean="apt-get clean"
update="apt-get update"
elif [ -n "$osid_rhel_like" ]; then
package_type=rpm
if command -pv dnf 1>/dev/null 2>&1; then
install_cmd="dnf install"
install="$install_cmd -y"
clean="dnf clean all"
else
install_cmd="yum install"
install="$install_cmd -y"
clean="yum clean all"
fi
else
echo "${RED}Error:${NORMAL} Unknown OS : $osid"
exit
fi
# Ask first
# printf "Setup Webmin official repository? (y/N) "
# read -r sslyn
# if [ "$sslyn" != "y" ] && [ "$sslyn" != "Y" ]; then
# exit
# fi
# Check for wget or curl or fetch
if [ ! -x "$download_wget" ]; then
if [ -x "/usr/bin/curl" ]; then
download="/usr/bin/curl -f -s -L -O"
elif [ -x "/usr/bin/fetch" ]; then
download="/usr/bin/fetch"
else
# Try installing wget
echo " Installing required ${ITALIC}wget${NORMAL} package from OS repository .."
$install wget 1>/dev/null 2>&1
if [ "$?" != "0" ]; then
echo " .. failed to install 'wget' package!"
exit 1
else
echo " .. done"
fi
fi
fi
# Check if GPG command is installed
if [ -n "$osid_debian_like" ]; then
if [ ! -x /usr/bin/gpg ]; then
$update 1>/dev/null 2>&1
$install gnupg 1>/dev/null 2>&1
fi
fi
# Clean files
rm -f "/tmp/$webmin_key"
rm -f "/tmp/$developers_key"
# Download key
echo " Downloading Webmin key .."
download_out=$($download $webmin_key_download 2>/dev/null 2>&1)
if [ "$?" != "0" ]; then
download_out=$(echo "$download_out" | tr '\n' ' ')
echo " ..failed : $download_out"
exit
fi
download_out=$($download $developers_key_download 2>/dev/null 2>&1)
if [ "$?" != "0" ]; then
download_out=$(echo "$download_out" | tr '\n' ' ')
echo " ..failed : $download_out"
exit
fi
echo " .. done"
# Setup repos
case "$package_type" in
rpm)
# Install our keys
echo " Installing Webmin key .."
rpm --import $webmin_key
cp -f $webmin_key /etc/pki/rpm-gpg/RPM-GPG-KEY-webmin
rpm --import $developers_key
cp -f $developers_key /etc/pki/rpm-gpg/RPM-GPG-KEY-developers
echo " .. done"
# Create repo file
echo " Setting up Webmin repository .."
echo "[webmin-noarch]" >$rhel_repo_file
echo "name=Webmin - noarch" >>$rhel_repo_file
echo "baseurl=$webmin_download/download/yum" >>$rhel_repo_file
echo "enabled=1" >>$rhel_repo_file
echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webmin" >>$rhel_repo_file
echo "gpgcheck=1" >>$rhel_repo_file
echo " .. done"
;;
deb)
# Install our keys
echo " Installing Webmin key .."
gpg --import $webmin_key 1>/dev/null 2>&1
cat $webmin_key | gpg --dearmor > /usr/share/keyrings/debian-webmin.gpg
gpg --import $developers_key 1>/dev/null 2>&1
cat $developers_key | gpg --dearmor > /usr/share/keyrings/debian-webmin-developers.gpg
echo " .. done"
# Create repo file
echo " Setting up Webmin repository .."
echo "deb [signed-by=/usr/share/keyrings/debian-webmin.gpg] $webmin_download/download/repository sarge contrib" >$debian_repo_file
echo " .. done"
# Clean meta
echo " Cleaning repository metadata .."
$clean 1>/dev/null 2>&1
echo " .. done"
# Update meta
echo " Downloading repository metadata .."
$update 1>/dev/null 2>&1
echo " .. done"
;;
*)
echo "${RED}Error:${NORMAL} Cannot setup repositories on this system."
exit 1
;;
esac
# Could not setup
if [ ! -x "/usr/bin/webmin" ]; then
echo "Webmin package can now be installed using ${GREEN}${BOLD}${ITALIC}$install_cmd webmin${NORMAL} command."
fi
sudo apt-get update
sudo apt-get install webmin -y