/
nems-build.sh
executable file
·174 lines (125 loc) · 3.41 KB
/
nems-build.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
#!/bin/bash
# TO DO
# Add removal of swap
####
# This script is *DESTRUCTIVE*
# This is how I build NEMS distros from scratch
# This is *NOT* meant to be run by users - please do not run it unless you understand clearly what you're doing.
#
# Some of the ideas in this process come from DietPi - https://github.com/Fourdee/DietPi/blob/master/PREP_SYSTEM_FOR_DIETPI.sh
####
if [[ $EUID -ne 0 ]]; then
echo "ERROR: This script must be run as root" 2>&1
exit 1
else
ver=$1
if [ -z $ver ]; then
echo "Usage: $0 [version]"
exit
fi
echo Building NEMS $ver
cd /usr/local/share/
mkdir nems
cd nems
echo "version=$ver" > nems.conf
chown www-data:www-data nems.conf
cd /root/nems/nems-admin
echo "" > /tmp/errors.log
echo "Usage before build:"
df -hT /etc
sleep 5
# Add repositories needed for deployment of apps
# Webmin
echo "deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list
wget -qO - http://www.webmin.com/jcameron-key.asc | apt-key add -
# Monitorix
echo "deb [arch=all] https://apt.izzysoft.de/ubuntu generic universe" > /etc/apt/sources.list.d/monitorix.list
wget -qO - https://apt.izzysoft.de/izzysoft.asc | apt-key add -
# Remove cruft
apt update
apt --yes --allow-remove-essential clean
apt --yes --allow-remove-essential --purge remove $(grep -vE "^\s*#" build/packages.remove | tr "\n" " ")
apt autoremove --purge -y
rm -R /usr/share/fonts/*
rm -R /usr/share/icons/*
echo "Usage after cruft removal:"
df -hT /etc
sleep 5
for pkg in $(grep -vE "^\s*#" build/packages.base | tr "\n" " ")
do
apt --yes --no-install-recommends install $pkg
done
# Add packages from repositories
for pkg in $(grep -vE "^\s*#" build/packages.add | tr "\n" " ")
do
apt --yes --no-install-recommends install $pkg
done
# Install dependencies, if any
apt --yes install -f
# Be up to date
apt --yes upgrade && apt --yes dist-upgrade
# Upgrade firmware
rpi-update
# Upgrade again in case anything changed on the new kernel
apt update
apt --yes upgrade && apt --yes dist-upgrade
# Disable firstrun
systemctl disable firstrun
rm /etc/init.d/firstrun # ARMbian
# Install NEMS Migrator first and foremost
./build/0-migrator
# Replace TTY screen
./build/10-tty
# Configure grub
./build/20-grub
# Setup Linux user
./build/30-user
# Install Apache2
./build/35-apache2
# Install Nagios Core
./build/50-nagios
# Install Check_MK livestatus
./build/55-check_mk
# Install NagVis
./build/60-nagvis
# Setup NEMS software
./build/150-nems
# Activate Samba Config from Migrator
./build/155-samba
# Install rpimonitor
./build/160-rpimonitor
# Install and activate Monitorix
./build/165-monitorix
# Install cockpit
./build/170-cockpit
# Configure monit
./build/175-monit
# Install Adagios
./build/180-adagios
# Change hostname to nems
./build/200-hostname
# Configure webmin
./build/220-webmin
# Disable swap
sed -i '/ swap / s/^/#/' /etc/fstab
swapoff -a
# Install apps from tar like Check-MK, NConf
cd /tmp
# pnp4nagios
git clone https://github.com/lingej/pnp4nagios
cd pnp4nagios
./configure
make
make all
make install
# Enable systemd items
systemctl enable webmin
# clean it up!
apt --yes autoremove
echo "Usage after build:"
df -hT /etc
# Output any errors encountered along the way.
cat /tmp/errors.log
echo "Don't forget to run: echo DEVID > /etc/.nems_hw_model_identifier"
fi