-
Notifications
You must be signed in to change notification settings - Fork 4
/
unifi-latest.sh
210 lines (193 loc) · 11.6 KB
/
unifi-latest.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
202
203
204
205
206
207
208
209
210
#!/bin/bash
# UniFi Network Application Easy Installation Script.
# Version | 1.2.2
# Author | Glenn Rietveld
# Email | glennrietveld8@hotmail.nl
# Website | https://GlennR.nl
###################################################################################################################################################################################################
# #
# Color Codes #
# #
###################################################################################################################################################################################################
RESET='\033[0m'
WHITE_R='\033[39m'
RED='\033[1;31m' # Light Red.
GREEN='\033[1;32m' # Light Green.
###################################################################################################################################################################################################
# #
# Start Checks #
# #
###################################################################################################################################################################################################
header() {
clear
clear
echo -e "${GREEN}#########################################################################${RESET}\\n"
}
header_red() {
clear
clear
echo -e "${RED}#########################################################################${RESET}\\n"
}
# Check for root (SUDO).
if [[ "$EUID" -ne 0 ]]; then
clear && clear
echo -e "${RED}#########################################################################${RESET}\\n"
echo -e "${WHITE_R}#${RESET} The script need to be run as root...\\n\\n"
echo -e "${WHITE_R}#${RESET} For Ubuntu based systems run the command below to login as root"
echo -e "${GREEN}#${RESET} sudo -i\\n"
echo -e "${WHITE_R}#${RESET} For Debian based systems run the command below to login as root"
echo -e "${GREEN}#${RESET} su\\n\\n"
exit 1
fi
# Variables
script_name=$(basename "${BASH_SOURCE[0]}")
script_logo() {
cat << "EOF"
_______________ ___ _________ .___ __ .__ .__
\_ _____/ | \/ _____/ | | ____ _______/ |______ | | | |
| __)_| | /\_____ \ | |/ \ / ___/\ __\__ \ | | | |
| \ | / / \ | | | \\___ \ | | / __ \| |_| |__
/_______ /______/ /_______ / |___|___| /____ > |__| (____ /____/____/
\/ \/ \/ \/ \/
EOF
}
help_script() {
if [[ "${script_option_help}" == 'true' ]]; then header; script_logo; else echo -e "\\n${WHITE_R}----${RESET}\\n"; fi
echo -e " Easy UniFi Network Application Install script assistance\\n"
echo -e "
Script usage:
bash ${script_name} [options]
Script options:
--skip Skip any kind of manual input.
--skip-install-haveged Skip installation of haveged.
--skip-swap Skip swap file check/creation.
--add-repository Add UniFi Repository if --skip is used.
--custom-url [argument] Manually provide a UniFi Network Application download URL.
example:
--custom-url https://dl.ui.com/unifi/5.12.72/unifi_sysvinit_all.deb
--help Shows this information :)\\n\\n
Script options for UniFi Easy Encrypt:
--v6 Run the script in IPv6 mode instead of IPv4.
--email [argument] Specify what email address you want to use
for renewal notifications.
example:
--email glenn@glennr.nl
--fqdn [argument] Specify what domain name ( FQDN ) you want to use, you
can specify multiple domain names with : as seperator, see
the example below:
--fqdn glennr.nl:www.glennr.nl
--server-ip [argument] Specify the server IP address manually.
example:
--server-ip 1.1.1.1
--retry [argument] Retry the unattended script if it aborts for X times.
example:
--retry 5
--external-dns [argument] Use external DNS server to resolve the FQDN.
example:
--external-dns 1.1.1.1
--force-renew Force renew the certificates.
--dns-challenge Run the script in DNS mode instead of HTTP.
example:
--private-key /tmp/PRIVATE.key
--signed-certificate [argument] Specify path to your signed certificate (paid certificate)
example:
--signed-certificate /tmp/SSL_CERTIFICATE.cer
--chain-certificate [argument] Specify path to your chain certificate (paid certificate)
example:
--chain-certificate /tmp/CHAIN.cer
--intermediate-certificate [argument] Specify path to your intermediate certificate (paid certificate)
example:
--intermediate-certificate /tmp/INTERMEDIATE.cer
--own-certificate Requirement if you want to import your own paid certificates
with the use of --skip.\\n\\n"
exit 0
}
mkdir -p /tmp/EUS/ &> /dev/null
rm --force /tmp/EUS/script_options &> /dev/null
script_option_list=(-skip --skip --skip-install-haveged --skip-swap --add-repository --local --local-controller --local-install --custom-url --help --v6 --ipv6 --email --mail --fqdn --domain-name --server-ip --server-address --retry --external-dns --force-renew --renew --dns --dns-challenge)
while [ -n "$1" ]; do
case "$1" in
-skip | --skip)
echo "--skip" &>> /tmp/EUS/script_options;;
--skip-install-haveged)
echo "--skip-install-haveged" &>> /tmp/EUS/script_options;;
--skip-swap)
echo "--skip-swap" &>> /tmp/EUS/script_options;;
--add-repository)
echo "--add-repository" &>> /tmp/EUS/script_options;;
--local | --local-controller | --local-install)
echo "--local-install" &>> /tmp/EUS/script_options;;
--custom-url)
if echo "${2}" | grep -iq ".*\.deb$"; then custom_url_down_provided=true; custom_download_url="${2}"; fi
if [[ "${custom_url_down_provided}" == 'true' ]]; then echo "--custom-url ${2}" &>> /tmp/EUS/script_options; else echo "--custom-url" &>> /tmp/EUS/script_options; fi;;
--help)
script_option_help=true
help_script;;
--v6 | --ipv6)
echo "--v6" &>> /tmp/EUS/script_options;;
--email | --mail)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--email ${2}" &>> /tmp/EUS/script_options
shift;;
--fqdn | --domain-name)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--fqdn ${2}" &>> /tmp/EUS/script_options
fqdn_specified=true
shift;;
--server-ip | --server-address)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--server-ip ${2}" &>> /tmp/EUS/script_options
shift;;
--retry)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo -e "--retry ${2}" &>> /tmp/EUS/script_options
shift;;
--external-dns)
echo -e "--external-dns" &>> /tmp/EUS/script_options;;
--force-renew | --renew)
echo -e "--force-renew" &>> /tmp/EUS/script_options;;
--dns | --dns-challenge)
echo -e "--dns-challenge" &>> /tmp/EUS/script_options;;
--priv-key | --private-key)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--private-key ${2}" &>> /tmp/EUS/script_options
shift;;
--signed-crt | --signed-certificate)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--signed-certificate ${2}" &>> /tmp/EUS/script_options
shift;;
--chain-crt | --chain-certificate)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--chain-certificate ${2}" &>> /tmp/EUS/script_options
shift;;
--intermediate-crt | --intermediate-certificate)
for option in "${script_option_list[@]}"; do
if [[ "${2}" == "${option}" ]]; then header_red; echo -e "${WHITE_R}#${RESET} Option ${1} requires a command argument... \\n\\n"; help_script; fi
done
echo "--intermediate-certificate ${2}" &>> /tmp/EUS/script_options
shift;;
--own-certificate)
echo "--own-certificate" &>> /tmp/EUS/script_options;;
esac
shift
done
if [[ -f /tmp/EUS/script_options && -s /tmp/EUS/script_options ]]; then IFS=" " read -r script_options <<< "$(tr '\r\n' ' ' < /tmp/EUS/script_options)"; fi
rm --force "$0" 2> /dev/null
rm --force unifi-latest.sh* 2> /dev/null
rm --force unifi-7.2.95.sh 2> /dev/null
# shellcheck disable=SC2086
wget -q https://get.glennr.nl/unifi/install/unifi-7.2.95.sh && bash unifi-7.2.95.sh ${script_options[@]}; exit 0