Subversion Repositories ALCASAR

Rev

Rev 3230 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2941 rexy 1
#!/bin/bash
2
 
3
# alcasar-rpm.sh
4
# by 3abtux and Rexy
5
# This script is distributed under the Gnu General Public License (GPL)
6
 
2990 rexy 7
# script de mise en place des dépots RPM + installation des RPM complémentaires
8
# configure the RPM repository + complementary RPM installation
2941 rexy 9
 
10
Lang=`echo $LANG|cut -c 1-2`
2971 rexy 11
SED="/bin/sed -i"
3190 rexy 12
VERSION="9"
2941 rexy 13
ARCH="x86_64"
14
# The kernel version we compile netflow for
3221 rexy 15
KERNEL="kernel-server-6.6.37-1.mga9"
2941 rexy 16
# ****** Alcasar needed RPMS - paquetages nécessaires au fonctionnement d'Alcasar ******
17
# (old) perl-Socket6 : needed by nfsen
18
# "fonts-dejavu-common" & "fonts-ttf-dejavu" : fonts needed by wkhtmltopdf
3077 rexy 19
# "lsscsi" & nvme-cli" & "php-dom" : needed by phpsysinfo
2941 rexy 20
# "socat" : avoid a warning when run the install script of letsencrypt ("acme.sh")
21
# "sudo" : needed after a reinstallation (to be investigated)
3053 rexy 22
# "postfix" + "cyrus-sasl" + "lib64sasl2-plug-plain" : email registration method
3193 rexy 23
# "nmap" : "/usr/share/nmap/nmap-mac-prefixes" is used to display MAC manufacturers in ACC
24
 
3230 rexy 25
PACKAGES="vim-enhanced freeradius freeradius-mysql freeradius-ldap apache apache-mod_ssl apache-mod_php php-gd php-ldap php-mysqli php-mbstring php-sockets php-curl php-pdo_sqlite php-cli php-dom php-filter unbound e2guardian postfix mariadb ntpsec bind-utils openssh-server rng-utils rsync fail2ban gnupg2 ulogd ipset usb_modeswitch vnstat dos2unix p7zip msec kernel-userspace-headers kernel-firmware kernel-firmware-nonfree dhcp-server tcpdump fonts-dejavu-common fonts-ttf-dejavu lsscsi nvme-cli sudo socat postfix cyrus-sasl lib64sasl2-plug-plain iftop"
2941 rexy 26
 
27
rpm_repository_sync ()
28
{
3111 rexy 29
	cat <<EOF > /etc/urpmi/urpmi.cfg
2941 rexy 30
{
31
downloader: wget
32
}
33
EOF
3111 rexy 34
	echo ${!MIRRORLIST}
35
	urpmi.addmedia core --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/core/release
36
	urpmi.addmedia core-updates --update --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/core/updates
37
	urpmi.addmedia nonfree --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/nonfree/release
38
	urpmi.addmedia nonfree-updates --update --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/nonfree/updates
2941 rexy 39
}
40
 
41
rpm_error ()
42
{
3111 rexy 43
	# restore previous rpm conf file & removed RPMs
44
	[ -e /etc/urpmi/urpmi.cfg.old ] && mv /etc/urpmi/urpmi.cfg.old /etc/urpmi/urpmi.cfg
45
	urpmi --no-verify-rpm --auto rpms/$ARCH/wkhtmltopdf*.rpm
46
	echo
47
	if [ $Lang == "fr" ]
48
	then
49
		echo "Relancez l'installation ultérieurement."
50
		echo "Si vous rencontrez à nouveau ce problème, modifier les variables MIRRORLIST[1&2] du fichier 'scripts/alcasar-rpm.sh'"
51
	else
52
		echo "Try an other install later."
53
		echo "If this problem occurs again, change the MIRRORLIST[1&2] variables in the file 'scripts/alcasar-rpm.sh'"
54
	fi
2941 rexy 55
}
56
 
57
# We prefer wget than curl
3216 rexy 58
wget_exist=`rpm -qa|grep wget|wc -l`
59
if [ "$wget_exist" -eq "0" ]
60
then
3238 rexy 61
	urpmi --no-verify-rpm --auto rpms/$ARCH/wget*.rpm && rm -f rpms/$ARCH/wget*.rpm
62
else
63
	rm -f rpms/$ARCH/wget*.rpm
3216 rexy 64
fi
2941 rexy 65
# Set the RPM repository (if not already set)
3111 rexy 66
cp /etc/urpmi/urpmi.cfg /etc/urpmi/urpmi.cfg.old
2941 rexy 67
ACTIVE_REPO=`cat /etc/urpmi/urpmi.cfg|grep "mageia.org"|wc -l`
2990 rexy 68
MIRROR_NBR=3
69
#                       For French
70
MIRRORLIST1="http://ftp.free.fr/mirrors/mageia.org/distrib/$VERSION/$ARCH"
2941 rexy 71
#                       For Europeans
2990 rexy 72
MIRRORLIST2="https://www.mirrorservice.org/pub/mageia/distrib/$VERSION/$ARCH"
73
#                       For everybody
74
MIRRORLIST3="https://mirrors.mageia.org/api/mageia.$VERSION.$ARCH.list"
2941 rexy 75
try_nb="0"; nb_repository="0"
76
while [ "$nb_repository" != "4" ]
77
do
78
	try_nb=`expr $try_nb + 1`
79
	MIRRORLIST="MIRRORLIST$try_nb"
80
	rpm_repository_sync
81
	nb_repository=`cat /etc/urpmi/urpmi.cfg|grep mirrorlist|wc -l`
82
	if [ "$nb_repository" != "4" ]
83
	then
84
		if [ $Lang == "fr" ]
85
		then
86
			echo "Une erreur a été détectée lors de la synchronisation avec le dépot N°$try_nb."
87
		else
88
			echo "An error occurs when synchronising the repositories N°$try_nb"
89
		fi
90
		if [ $(expr $try_nb) -eq $MIRROR_NBR ]
91
		then
92
			rpm_error
93
			exit 1
94
		fi
95
		if [ $Lang == "fr" ]
96
		then
97
			echo "Voulez-vous tenter une synchronisation avec un autre dépôt ? (O/n)"
98
		else
99
			echo "Do you want to try a synchronisation with an other repository? (Y/n)"
100
		fi
101
		response=0
102
		PTN='^[oOnNyY]?$'
103
		until [[ "$response" =~ $PTN ]]
104
		do
105
			read response
106
		done
107
		if [ "$response" = "n" ] || [ "$response" = "N" ]
108
		then
3111 rexy 109
			[ -e /etc/urpmi/urpmi.cfg.old ] && mv /etc/urpmi/urpmi.cfg.old /etc/urpmi/urpmi.cfg # restore previous rpm conf file
2941 rexy 110
			exit 1
111
		fi
112
	fi
113
done
3093 rexy 114
 
3200 rexy 115
# Clean the RPM cache
116
urpmi --clean
117
 
3093 rexy 118
# At this time, we only skip Kernel update
119
echo "/^kernel/" > /etc/urpmi/skip.list
3190 rexy 120
if [ `grep -E '^exclude=' /etc/dnf/dnf.conf |wc -l` -eq "1" ]; then
3093 rexy 121
	$SED "s?^exclude=.*?exclude=kernel\*?g" /etc/dnf/dnf.conf
122
else
123
	echo "exclude=kernel*" >> /etc/dnf/dnf.conf
124
fi
125
 
2941 rexy 126
# download the kernel used by ALCASAR
127
if [ $Lang == "fr" ]
128
then
129
	echo "Récupération du noyau Linux exploité par ALCASAR. Veuillez patienter ..."
130
else
131
	echo "Download the Linux kernel used by ALCASAR. Please wait ..."
132
fi
133
urpmi --auto --quiet $KERNEL
3093 rexy 134
 
2941 rexy 135
# download updated RPM in cache
136
if [ $Lang == "fr" ]
137
then
138
	echo "Récupération des paquetages de mise à jour. Veuillez patienter ..."
139
	echo "Il est temps d'aller prendre un café (ou une bonne bière) ;-)"
140
else
141
	echo "Updated RPM download. Please wait ..."
142
	echo "You should now take a coffe (or a good beer) ;-)"
143
fi
144
urpmi --auto --auto-update --quiet --test --retry 2
145
if [ "$?" != "0" ]
146
then
147
	echo
148
	if [ $Lang == "fr" ]
149
	then
150
		echo "Une erreur a été détectée lors de la récupération des paquetages."
151
	else
152
		echo "An error occurs when downloading RPMS"
153
	fi
154
	rpm_error
155
	exit 1
156
fi
157
 
158
# update with cached RPM
159
urpmi --auto --auto-update
160
if [ "$?" != "0" ]
161
then
162
	echo
163
	if [ $Lang == "fr" ]
164
	then
165
		echo "Une erreur a été détectée lors de la mise à jour des paquetages."
166
	else
167
		echo "An error occurs when updating packages"
168
	fi
169
	rpm_error
170
	exit 1
171
fi
172
 
173
# Download of ALCASAR specifics RPM in cache (and test)
174
if [ $Lang == "fr" ]
175
then
176
	echo "Récupération des paquetages complémentaires. Veuillez patienter ..."
177
else
178
	echo "Download of complementary packages. Please wait ..."
179
fi
180
urpmi --auto --no-recommends $PACKAGES --quiet --test --retry 2
181
if [ "$?" != "0" ]
182
then
183
	echo
184
	if [ $Lang == "fr" ]
185
	then
186
		echo "Une erreur a été détectée lors de la récupération des paquetages complémentaires."
187
	else
188
		echo "An error occurs when downloading complementary packages"
189
	fi
190
	rpm_error
191
	exit 1
192
fi
193
 
194
# update with cached RPM
195
urpmi --auto --no-recommends $PACKAGES
196
if [ "$?" != "0" ]
197
then
198
	echo
199
	if [ $Lang == "fr" ]
200
	then
201
		echo "Une erreur a été détectée lors de l'installation des paquetages complémentaires."
202
	else
203
		echo "An error occurs when installing complementary packages"
204
	fi
205
	rpm_error
206
	exit 1
207
fi
208
 
209
# Keep only the kernel version we compil netflow with, and remove all others
210
kernelVersion=$(rpm -qa | grep -e ^kernel-server -e ^kernel-desktop)
211
for i in $kernelVersion
212
do
213
	if [ $i != $KERNEL ];then
214
		urpme --auto $i
215
	fi
216
done
3093 rexy 217
 
3219 rexy 218
# delete unused or not usefull RPMs
2941 rexy 219
if [ $Lang == "fr" ]
220
then
221
	echo "Cleaning the system : "
222
else
223
	echo "Nettoyage du système : "
224
fi
3230 rexy 225
unused_rpm="shorewall mandi plymouth squid polkit pm-utils dnsmasq clamav clamd clamav-db tracker lighttpd php-fpm"
2988 rexy 226
/usr/sbin/urpme --auto -a $unused_rpm
3207 rexy 227
for distrib in mga7 mga8
228
do
229
	for rpm in `rpm -qa|grep $distrib`; do urpme --auto $rpm; done
230
done
2941 rexy 231
/usr/sbin/urpme --auto --auto-orphans
232
 
233
# Save chilli launch script (erase with new rpm one)
234
[ -e /etc/chilli.conf ] && cp /etc/chilli.conf /tmp/
235
# Install home made RPMs
3216 rexy 236
for pkg in `ls rpms/$ARCH/*.rpm|grep -v wget`
2941 rexy 237
do
238
    urpmi --no-verify --auto $pkg
239
done
240
# restore chilli launch script
241
[ -e /tmp/chilli.conf ] && mv /tmp/chilli.conf /etc/
3093 rexy 242
 
2941 rexy 243
# Clean the RPM cache
244
urpmi --clean
245
# the ipt-netflow RPM add the kernel module ipt_NETFLOW (the modules dependance tree need to be updated). "2>/dev/null" in order not to display a error (the running kernel is not the ALCASAR one during the installation process)
246
/sbin/depmod -a 2>/dev/null
247
# test if all needed rpms are correctly installed
248
count_pkg=0; nb_pkg=0;
249
for pkg in $PACKAGES
250
do
251
	nb_pkg=`expr $nb_pkg + 1`
252
	if rpm -q --quiet $pkg ; then
253
		count_pkg=`expr $count_pkg + 1`
254
	else
255
		echo "error installing $pkg"
256
	fi
257
done
258
if [ $count_pkg -ne $nb_pkg ]
259
then
260
	exit 1
261
fi
3093 rexy 262
 
2941 rexy 263
# test if all custom rpms are correctly installed
264
count_pkg=0; nb_pkg=0;
265
for pkg in `ls rpms/$ARCH/|sed 's/.x86_64.rpm//'`
266
do
267
	nb_pkg=`expr $nb_pkg + 1`
268
	if rpm -q --quiet $pkg ; then
269
		count_pkg=`expr $count_pkg + 1`
270
	else
271
		echo "error installing $pkg"
272
	fi
273
done
274
if [ $count_pkg -ne $nb_pkg ]
275
then
276
	exit 1
277
fi
3104 rexy 278
 
279
# .rpmnew handling (unused with ALCASAR)
280
[ -e /etc/shadow.rpmnew ] && rm -f /etc/shadow.rpmnew
281
[ -e /etc/sysconfig/system.rpmnew ] && rm -f /etc/sysconfig/system.rpmnew
282
[ -e /etc/rpm/macros.rpmnew ] && rm -f /etc/rpm/macros.rpmnew
283
[ -e /etc/fstab.rpmnew ] && rm -f /etc/fstab.rpmnew
284
[ -e /etc/shells.rpmnew ] && rm -f /etc/shells.rpmnew
285
[ -e /etc/hosts.rpmnew ] && rm -f /etc/hosts.rpmnew
286
[ -e /etc/systemd/journald.conf.rpmnew ] && rm -f /etc/systemd/journald.conf.rpmnew
287
[ -e /etc/raddb/certs/dh.rpmnew ] && rm -f /etc/raddb/certs/dh.rpmnew
288
 
289
# .rpmnew handling (used with ALCASAR)
290
[ -e /etc/php.ini.rpmnew ] && mv -f /etc/php.ini.rpmnew /etc/php.ini.default
291
[ -e /etc/lighttpd/lighttpd.conf.rpmnew ] && mv -f /etc/lighttpd/lighttpd.conf.rpmnew /etc/lighttpd/lighttpd.conf.default
292
[ -e /etc/lighttpd/modules.conf.rpmnew ] && mv -f /etc/lighttpd/modules.conf.rpmnew /etc/lighttpd/modules.conf.default
293
[ -e /etc/e2guardian/e2guardian.conf.rpmnew ] && mv -f /etc/e2guardian/e2guardian.conf.rpmnew /etc/e2guardian/e2guardian.conf.default
294
[ -e /etc/e2guardian/e2guardianf1.conf.rpmnew ] && mv -f /etc/e2guardian/e2guardianf1.conf.rpmnew /etc/e2guardian/e2guardianf1.conf.default
295
[ -e /etc/e2guardian/lists/urlregexplist.rpmnew ] && mv -f /etc/e2guardian/lists/urlregexplist.rpmnew /etc/e2guardian/lists/urlregexplist.default
296
[ -e /etc/e2guardian/lists/bannedregexpurllist.rpmnew ] && mv -f /etc/e2guardian/lists/bannedregexpurllist.rpmnew /etc/e2guardian/lists/bannedregexpurllist.default
297
[ -e /etc/vnstat.conf.rpmnew ] && mv -f /etc/vnstat.conf.rpmnew /etc/vnstat.conf.default
298
[ -e /etc/fail2ban/jail.conf.rpmnew ] && mv -f /etc/fail2ban/jail.conf.rpmnew /etc/fail2ban/jail.conf.default
299
[ -e /etc/ssh/sshd_config.rpmnew ] && mv -f /etc/ssh/sshd_config.rpmnew /etc/ssh/sshd_config.default
300
 
2941 rexy 301
exit 0