forked from OpenMediaVault-Plugin-Developers/installScript
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install
executable file
·548 lines (478 loc) · 17.3 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
#!/bin/bash
#
# shellcheck disable=SC1090,SC1091,SC1117,SC2010,SC2016,SC2046,SC2086,SC2174
#
# Copyright (c) 2015-2021 OpenMediaVault Plugin Developers
# Copyright (c) 2017-2020 Armbian Developers
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# Ideas/code used from:
# https://github.com/armbian/config/blob/master/debian-software
# https://forum.openmediavault.org/index.php/Thread/25062-Install-OMV5-on-Debian-10-Buster/
#
# version: 1.3.1
#
if [[ $(id -u) -ne 0 ]]; then
echo "This script must be executed as root or using sudo."
exit 99
fi
systemd="$(ps --no-headers -o comm 1)"
if [ ! "${systemd}" = "systemd" ]; then
echo "This system is not running systemd. Exiting..."
exit 100
fi
declare -i cfg=0
declare -i ipv6=0
declare -i skipFlash=0
declare -i skipNet=0
declare -i skipReboot=0
declare -i version
declare -l codename
declare -l omvCodename
declare -l omvInstall=""
declare -l omvextrasInstall=""
cpuFreqDef="/etc/default/cpufrequtils"
crda="/etc/default/crda"
defaultGovSearch="^CONFIG_CPU_FREQ_DEFAULT_GOV_"
forceIpv4="/etc/apt/apt.conf.d/99force-ipv4"
ioniceCron="/etc/cron.d/make_nas_processes_faster"
ioniceScript="/usr/sbin/omv-ionice"
keyserver="hkp://keyserver.ubuntu.com:80"
omvKey="/etc/apt/trusted.gpg.d/openmediavault-archive-keyring.asc"
omvRepo="http://packages.openmediavault.org/public"
omvSources="/etc/apt/sources.list.d/openmediavault.list"
rfkill="/usr/sbin/rfkill"
smbOptions="min receivefile size = 16384\nwrite cache size = 524288\ngetwd cache = yes\nsocket options = TCP_NODELAY IPTOS_LOWDELAY"
url="https://github.com/OpenMediaVault-Plugin-Developers/packages/raw/master/"
vsCodeList="/etc/apt/sources.list.d/vscode.list"
wpaConf="/etc/wpa_supplicant/wpa_supplicant.conf"
export DEBIAN_FRONTEND=noninteractive
export APT_LISTCHANGES_FRONTEND=none
export LANG=C.UTF-8
if [ -f /etc/armbian-release ]; then
. /etc/armbian-release
fi
while getopts "fhinr" opt; do
echo "option ${opt}"
case "${opt}" in
f)
skipFlash=1
;;
h)
echo "Use the following flags:"
echo " -f"
echo " to skip the installation of the flashmemory plugin"
echo " -i"
echo " enable using IPv6 for apt"
echo " -n"
echo " to skip the network setup"
echo " -r"
echo " to skip reboot"
echo ""
echo "Examples:"
echo " install"
echo " install -f"
echo " install -n"
exit 100
;;
i)
ipv6=1
;;
n)
skipNet=1
;;
r)
skipReboot=1
;;
\?)
echo "Invalid option: -${OPTARG}"
;;
esac
done
# Fix permissions on / if wrong
echo "Current / permissions = $(stat -c %a /)"
chmod g-w,o-w /
echo "New / permissions = $(stat -c %a /)"
# if ipv6 is not enabled, create apt config file to force ipv4
if [ ${ipv6} -ne 1 ]; then
echo "Forcing IPv4 only for apt..."
echo 'Acquire::ForceIPv4 "true";' > ${forceIpv4}
fi
echo "Updating repos before installing..."
apt-get update
echo "Installing lsb_release..."
apt-get --yes --no-install-recommends --reinstall install lsb-release
arch="$(dpkg --print-architecture)"
# exit if not supported architecture
case ${arch} in
arm64|armhf|amd64|i386)
echo "Supported architecture"
;;
*)
echo "Unsupported architecture :: ${arch}"
exit 5
;;
esac
codename="$(lsb_release --codename --short)"
case ${codename} in
buster)
confCmd="omv-salt deploy run"
network="systemd-networkd"
ntp="chrony"
omvCodename="usul"
phpfpm="phpfpm"
version=5
;;
*)
echo "Unsupported version. Exiting..."
exit 1
;;
esac
echo "${omvCodename} :: ${version}"
hostname=$(</etc/hostname)
tz=$(</etc/timezone)
# Add Debian signing keys to raspbian to prevent apt-get update failures
# when OMV adds security and/or backports repos
if grep -q raspberrypi.org /etc/apt/sources.list.d/*; then
echo "Adding Debian signing keys..."
for key in AA8E81B4331F7F50 112695A0E562B32A 04EE7237B7D453EC 648ACFD622F3D138; do
apt-key adv --no-tty --keyserver ${keyserver} --recv-keys "${key}"
done
echo "Installing monit from raspberrypi repo..."
apt-get --yes --no-install-recommends install -t ${codename} monit
# remove vscode repo if found since there is no desktop environment
# empty file will exist to keep raspberrypi-sys-mods package from adding it back
truncate -s 0 "${vsCodeList}"
fi
echo "Install prerequisites..."
apt-get --yes --no-install-recommends install dirmngr gnupg
# install openmediavault if not installed already
omvInstall=$(dpkg -l | awk '$2 == "openmediavault" { print $1 }')
if [[ ! "${omvInstall}" == "ii" ]]; then
echo "Installing openmediavault required packages..."
if ! apt-get --yes --no-install-recommends install postfix; then
echo "failed installing postfix"
exit 2
fi
echo "Adding openmediavault repo and key..."
echo "deb ${omvRepo} ${omvCodename} main" > ${omvSources}
wget -O "${omvKey}" ${omvRepo}/archive.key
apt-key add "${omvKey}"
echo "Updating repos..."
if ! apt-get update; then
echo "failed to update apt repos."
exit 2
fi
echo "Install openmediavault-keyring..."
if ! apt-get --yes install openmediavault-keyring; then
echo "failed to install openmediavault-keyring package."
exit 2
fi
monitInstall=$(dpkg -l | awk '$2 == "monit" { print $1 }')
if [[ ! "${monitInstall}" == "ii" ]]; then
if ! apt-get --yes --no-install-recommends install monit; then
echo "failed installing monit"
exit 2
fi
fi
echo "Installing openmediavault..."
aptFlags="--yes --auto-remove --show-upgraded --allow-downgrades --allow-change-held-packages --no-install-recommends"
cmd="apt-get ${aptFlags} install openmediavault"
if ! ${cmd}; then
echo "failed to install openmediavault package."
exit 2
fi
if [ ${version} -gt 4 ]; then
omv-confdbadm populate
else
omv-initsystem
omv-mkconf interfaces
omv-mkconf issue
fi
fi
# check if openmediavault is install properly
omvInstall=$(dpkg -l | awk '$2 == "openmediavault" { print $1 }')
if [[ ! "${omvInstall}" == "ii" ]]; then
echo "openmediavault package failed to install or is in a bad state."
exit 3
fi
. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions
# remove backports from sources.list to avoid duplicate sources warning
sed -i "/\(stretch\|buster\)-backports/d" /etc/apt/sources.list
if [ "${codename}" = "eoan" ]; then
omv_set_default "OMV_APT_USE_KERNEL_BACKPORTS" false true
fi
# install omv-extras
echo "Downloading omv-extras.org plugin for openmediavault ${version}.x ..."
file="openmediavault-omvextrasorg_latest_all${version}.deb"
if [ -f "${file}" ]; then
rm ${file}
fi
wget ${url}/${file}
if [ -f "${file}" ]; then
if ! dpkg --install ${file}; then
echo "Installing other dependencies ..."
apt-get --yes --fix-broken install
omvextrasInstall=$(dpkg -l | awk '$2 == "openmediavault-omvextrasorg" { print $1 }')
if [[ ! "${omvextrasInstall}" == "ii" ]]; then
echo "omv-extras failed to install correctly. Trying to fix with ${confCmd} ..."
if ${confCmd} omvextras; then
echo "Trying to fix apt ..."
apt-get --yes --fix-broken install
else
echo "${confCmd} failed and openmediavault-omvextrasorg is in a bad state."
exit 3
fi
fi
omvextrasInstall=$(dpkg -l | awk '$2 == "openmediavault-omvextrasorg" { print $1 }')
if [[ ! "${omvextrasInstall}" == "ii" ]]; then
echo "openmediavault-omvextrasorg package failed to install or is in a bad state."
exit 3
fi
fi
echo "Updating repos ..."
apt-get update
else
echo "There was a problem downloading the package."
fi
# disable armbian log services if found
for service in log2ram armbian-ramlog armbian-zram-config; do
if systemctl list-units --full -all | grep ${service}; then
systemctl stop ${service}
systemctl disable ${service}
fi
done
rm -f /etc/cron.daily/armbian-ram-logging
if [ -f "/etc/default/armbian-ramlog" ]; then
sed -i "s/ENABLED=.*/ENABLED=false/g" /etc/default/armbian-ramlog
fi
if [ -f "/etc/default/armbian-zram-config" ]; then
sed -i "s/ENABLED=.*/ENABLED=false/g" /etc/default/armbian-zram-config
fi
if [ -f "/etc/systemd/system/logrotate.service" ]; then
rm -f /etc/systemd/system/logrotate.service
systemctl daemon-reload
fi
# install flashmemory plugin unless disabled
if [ ${skipFlash} -eq 1 ]; then
echo "Skipping installation of the flashmemory plugin."
else
echo "Install folder2ram..."
if apt-get --yes --fix-missing --no-install-recommends install folder2ram; then
echo "Installed folder2ram."
else
echo "Failed to install folder2ram."
fi
echo "Install flashmemory plugin..."
if apt-get --yes install openmediavault-flashmemory; then
echo "Installed flashmemory plugin."
else
echo "Failed to install flashmemory plugin."
${confCmd} flashmemory
apt-get --yes --fix-broken install
fi
fi
# change default OMV settings
omv_config_update "/config/services/smb/extraoptions" "$(echo -e "${smbOptions}")"
omv_config_update "/config/services/ssh/enable" "1"
omv_config_update "/config/services/ssh/permitrootlogin" "1"
omv_config_update "/config/system/time/ntp/enable" "1"
omv_config_update "/config/system/time/timezone" "${tz}"
omv_config_update "/config/system/network/dns/hostname" "${hostname}"
# disable monitoring and apply changes
echo "Disabling data collection ..."
/usr/sbin/omv-rpc -u admin "perfstats" "set" '{"enable":false}'
/usr/sbin/omv-rpc -u admin "config" "applyChanges" '{ "modules": ["monit","rrdcached","collectd"],"force": true }'
# set min/max frequency and watchdog for RPi boards
rpi_model="/proc/device-tree/model"
if [ -f "${rpi_model}" ] && [[ $(awk '{ print $1 }' ${rpi_model}) = "Raspberry" ]]; then
omv_set_default "OMV_WATCHDOG_DEFAULT_MODULE" "bcm2835_wdt"
omv_set_default "OMV_WATCHDOG_CONF_WATCHDOG_TIMEOUT" "14"
MIN_SPEED="$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq)"
MAX_SPEED="$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq)"
# Determine if RPi4 (for future use)
if [[ $(awk '$1 == "Revision" { print $3 }' /proc/cpuinfo) =~ [a-c]03111 ]]; then
BOARD="rpi4"
fi
cat << EOF > ${cpuFreqDef}
GOVERNOR="ondemand"
MIN_SPEED="${MIN_SPEED}"
MAX_SPEED="${MAX_SPEED}"
EOF
fi
if [ -f "${cpuFreqDef}" ]; then
. ${cpuFreqDef}
else
# set cpufreq settings if no defaults
if [ -f "/proc/config.gz" ]; then
defaultGov="$(zgrep "${defaultGovSearch}" /proc/config.gz | sed -e "s/${defaultGovSearch}\(.*\)=y/\1/")"
elif [ -f "/boot/config-$(uname -r)" ]; then
defaultGov="$(grep "${defaultGovSearch}" /boot/config-$(uname -r) | sed -e "s/${defaultGovSearch}\(.*\)=y/\1/")"
fi
if [ -z "${DEFAULT_GOV}" ]; then
defaultGov="ondemand"
fi
GOVERNOR=${defaultGov,,}
MIN_SPEED="0"
MAX_SPEED="0"
fi
# set defaults in /etc/default/openmediavault
omv_set_default "OMV_CPUFREQUTILS_GOVERNOR" "${GOVERNOR}"
omv_set_default "OMV_CPUFREQUTILS_MINSPEED" "${MIN_SPEED}"
omv_set_default "OMV_CPUFREQUTILS_MAXSPEED" "${MAX_SPEED}"
if [ ${version} -gt 4 ]; then
# update pillar default list - /srv/pillar/omv/default.sls
omv-salt stage run prepare
fi
# update config files
for service in nginx ${phpfpm} samba flashmemory ssh ${ntp} timezone monit rrdcached collectd cpufrequtils apt watchdog; do
${confCmd} ${service}
done
# create php directories if they don't exist
modDir="/var/lib/php/modules"
if [ ! -d "${modDir}" ]; then
mkdir --parents --mode=0755 ${modDir}
fi
sessDir="/var/lib/php/sessions"
if [ ! -d "${sessDir}" ]; then
mkdir --parents --mode=1733 ${sessDir}
fi
if [ -f "${forceIpv4}" ]; then
rm ${forceIpv4}
fi
if [ -f "/etc/init.d/proftpd" ]; then
systemctl disable proftpd.service
systemctl stop proftpd.service
fi
if [[ "${arch}" == "amd64" ]] || [[ "${arch}" == "i386" ]]; then
# skip ionice on x86 boards
echo "Done."
exit 0
fi
# Add a cron job to make NAS processes more snappy and silence rsyslog
cat << EOF > /etc/rsyslog.d/omv-armbian.conf
:msg, contains, "omv-ionice" ~
:msg, contains, "action " ~
:msg, contains, "netsnmp_assert" ~
:msg, contains, "Failed to initiate sched scan" ~
EOF
systemctl restart rsyslog
# add taskset to ionice cronjob for biglittle boards
case ${BOARD} in
odroidxu4|bananapim3|nanopifire3|nanopct3plus|nanopim3)
taskset='; taskset -c -p 4-7 ${srv}'
;;
*rk3399*|*edge*|nanopct4|nanopim4|nanopineo4|renegade-elite|rockpi-4*|rockpro64|helios64)
taskset='; taskset -c -p 4-5 ${srv}'
;;
odroidn2)
taskset='; taskset -c -p 2-5 ${srv}'
;;
esac
# create ionice script
cat << EOF > ${ioniceScript}
#!/bin/sh
for srv in \$(pgrep "ftpd|nfsiod|smbd"); do
ionice -c1 -p \${srv} ${taskset};
done
EOF
chmod 755 ${ioniceScript}
# create ionice cronjob
cat << EOF > ${ioniceCron}
* * * * * root ${ioniceScript} >/dev/null 2>&1
EOF
chmod 600 ${ioniceCron}
# add pi user to ssh group if it exists
if getent passwd pi > /dev/null; then
echo "Adding pi user to ssh group ..."
usermod -a -G ssh pi
fi
# add user running the script to ssh group if not pi or root
if [ -n "${USER}" ] && [ ! "${USER}" = "root" ] && [ ! "${USER}" = "pi" ]; then
if getent passwd ${USER} > /dev/null; then
echo "Adding ${USER} to the ssh group ..."
usermod -a -G ssh ${USER}
fi
fi
# remove networkmanager and dhcpcd5 then configure networkd
if [ ${version} -gt 4 ] && [ ${skipNet} -ne 1 ]; then
if [ "${BOARD}" = "helios64" ]; then
echo -e '#!/bin/sh\n/usr/sbin/ethtool --offload eth1 rx off tx off' > /usr/lib/networkd-dispatcher/routable.d/10-disable-offloading
fi
defLink="/etc/systemd/network/99-default.link"
if [ -e "${defLink}" ]; then
rm -fv "${defLink}"
fi
echo "Removing network-manager and dhcpcd5 ..."
apt-get -y --autoremove purge network-manager dhcpcd5
echo "Enable and start systemd-resolved ..."
systemctl enable systemd-resolved
systemctl start systemd-resolved
rm /etc/resolv.conf
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
if [ -f "${rfkill}" ]; then
echo "Unblocking wifi with rfkill ..."
${rfkill} unblock all
fi
for nic in $(ls /sys/class/net | grep -vE "br-|docker|dummy|lo|tun|virbr|wg"); do
if grep -q "<devicename>${nic}</devicename>" ${OMV_CONFIG_FILE}; then
echo "${nic} already found in database. Skipping..."
continue
fi
if udevadm info /sys/class/net/${nic} | grep -q wlan; then
if [ -f "${wpaConf}" ]; then
country=$(awk -F'=' '/country=/{gsub(/["\r]/,""); print $NF}' ${wpaConf})
wifiName=$(awk -F'=' '/ssid="/{st=index($0,"="); ssid=substr($0,st+1); gsub(/["\r]/,"",ssid); print ssid; exit}' ${wpaConf})
wifiPass=$(awk -F'=' '/psk="/{st=index($0,"="); pass=substr($0,st+1); gsub(/["\r]/,"",pass); print pass; exit}' ${wpaConf})
if [ -n "${country}" ] && [ -n "${wifiName}" ] && [ -n "${wifiPass}" ]; then
if [ -f "${crda}" ]; then
awk -i inplace -F'=' -v country="$country" '/REGDOMAIN=/{$0=$1"="country} {print $0}' ${crda}
fi
echo "Adding ${nic} to openmedivault database ..."
jq --null-input --compact-output \
"{uuid: \"${OMV_CONFIGOBJECT_NEW_UUID}\", devicename: \"${nic}\", type: \"wifi\", method: \"dhcp\", method6: \"dhcp\", wpassid: \"${wifiName}\", wpapsk: \"${wifiPass}\"}" | \
omv-confdbadm update "conf.system.network.interface" -
if grep -q "<devicename>${nic}</devicename>" ${OMV_CONFIG_FILE}; then
cfg=1
fi
fi
fi
else
echo "Adding ${nic} to openmedivault database ..."
if [ -n "$(ip -j -o -4 addr show ${nic} | jq --raw-output '.[] | select(.addr_info[0].dev) | .addr_info[0].local')" ] && \
[ "$(ip -j -o -4 addr show ${nic} | jq --raw-output '.[] | select(.addr_info[0].dev) | .addr_info[0].dynamic')" == "null" ]; then
ipv4Addr=$(ip -j -o -4 addr show ${nic} | jq --raw-output '.[] | select(.addr_info[0].dev) | .addr_info[0].local')
ipv4CIDR=$(ip -j -o -4 addr show ${nic} | jq --raw-output '.[] | select(.addr_info[0].dev) | .addr_info[0].prefixlen')
bitmaskValue=$(( 0xffffffff ^ ((1 << (32 - ipv4CIDR)) - 1) ))
ipv4Netmask=$(( (bitmaskValue >> 24) & 0xff )).$(( (bitmaskValue >> 16) & 0xff )).$(( (bitmaskValue >> 8) & 0xff )).$(( bitmaskValue & 0xff ))
ipv4GW=$(ip -j -o -4 route show | jq --raw-output '.[] | select(.dst=="default") | .gateway')
jq --null-input --compact-output \
"{uuid: \"${OMV_CONFIGOBJECT_NEW_UUID}\", devicename: \"${nic}\", method: \"static\", address: \"${ipv4Addr}\", netmask: \"${ipv4Netmask}\", gateway: \"${ipv4GW}\", dnsnameservers: \"8.8.8.8 ${ipv4GW}\"}" | \
omv-confdbadm update "conf.system.network.interface" -
else
jq --null-input --compact-output \
"{uuid: \"${OMV_CONFIGOBJECT_NEW_UUID}\", devicename: \"${nic}\", method: \"dhcp\", method6: \"dhcp\"}" | \
omv-confdbadm update "conf.system.network.interface" -
fi
if grep -q "<devicename>${nic}</devicename>" ${OMV_CONFIG_FILE}; then
cfg=1
fi
fi
done
if [ ${cfg} -eq 1 ]; then
echo "IP address may change and you could lose connection if running this script via ssh."
# create config files
${confCmd} ${network}
if [ ${skipReboot} -ne 1 ]; then
echo "Network setup. Rebooting..."
reboot
fi
else
echo "It is recommended to reboot and then setup the network adapter in the openmediavault web interface."
fi
fi
exit 0