Subversion Repositories ALCASAR

Rev

Rev 2944 | Go to most recent revision | Details | 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
 
7
# script de mise en place des dépots RPM
8
# configure the RPM repository
9
 
10
Lang=`echo $LANG|cut -c 1-2`
11
VERSION="7"
12
ARCH="x86_64"
13
# The kernel version we compile netflow for
14
KERNEL="kernel-server-5.10.27-1.mga7-1-1.mga7"
15
# ****** Alcasar needed RPMS - paquetages nécessaires au fonctionnement d'Alcasar ******
16
# (old) perl-Socket6 : needed by nfsen
17
# "fonts-dejavu-common" & "fonts-ttf-dejavu" : fonts needed by wkhtmltopdf
18
# "lsscsi" & nvme-cli" : needed by phpsysinfo
19
# "socat" : avoid a warning when run the install script of letsencrypt ("acme.sh")
20
# "sudo" : needed after a reinstallation (to be investigated)
21
PACKAGES="vim-enhanced freeradius freeradius-mysql freeradius-ldap lighttpd lighttpd-mod_auth php-fpm php-gd php-ldap php-mysqli php-mbstring php-sockets php-curl php-pdo_sqlite php-cli unbound e2guardian postfix mariadb ntp bind-utils openssh-server rng-utils rsync clamd fail2ban gnupg2 ulogd pm-fallback-policy ipset usb_modeswitch vnstat dos2unix p7zip msec kernel-userspace-headers kernel-firmware-nonfree dnsmasq dhcp-server tcpdump fonts-dejavu-common fonts-ttf-dejavu lsscsi nvme-cli sudo socat"
22
 
23
rpm_repository_sync ()
24
{
25
cat <<EOF > /etc/urpmi/urpmi.cfg
26
{
27
downloader: wget
28
}
29
EOF
30
echo ${!MIRRORLIST}
31
urpmi.addmedia core --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/core/release
32
urpmi.addmedia core-updates --update --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/core/updates
33
urpmi.addmedia nonfree --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/nonfree/release
34
urpmi.addmedia nonfree-updates --update --probe-synthesis --mirrorlist ${!MIRRORLIST} /media/nonfree/updates
35
}
36
 
37
rpm_error ()
38
{
39
echo
40
if [ $Lang == "fr" ]
41
then
42
	echo "Relancez l'installation ultérieurement."
43
	echo "Si vous rencontrez à nouveau ce problème, modifier les variables MIRRORLIST[1&2] du fichier 'scripts/alcasar-rpm.sh'"
44
else
45
	echo "Try an other install later."
46
	echo "If this problem occurs again, change the MIRRORLIST[1&2] variables in the file 'scripts/alcasar-rpm.sh'"
47
fi
48
}
49
 
50
# extract the current Mageia version and hardware architecture (i586 ou X64)
51
fic=`cat /etc/product.id`
52
old="$IFS"
53
IFS=","
54
set $fic
55
for i in $*
56
do
57
	if [ "`echo $i|grep distribution|cut -d'=' -f1`" == "distribution" ]
58
	then
59
		DISTRIBUTION=`echo $i|cut -d"=" -f2`
60
	fi
61
	if [ "`echo $i|grep version|cut -d'=' -f1`" == "version" ]
62
	then
63
		CURRENT_VERSION=`echo $i|cut -d"=" -f2`
64
	fi
65
	if [ "`echo $i|grep arch|cut -d'=' -f1`" == "arch" ]
66
	then
67
		ARCH=`echo $i|cut -d"=" -f2`
68
	fi
69
done
70
IFS="$old"
71
 
72
# We prefer wget than curl
73
urpmi --no-verify-rpm --auto rpms/$ARCH/wget*.rpm
74
 
75
# Set the RPM repository (if not already set)
76
ACTIVE_REPO=`cat /etc/urpmi/urpmi.cfg|grep "mageia.org"|wc -l`
77
MIRROR_NBR=2
78
#                       For Europeans
79
MIRRORLIST1="https://www.mirrorservice.org/pub/mageia/distrib/$VERSION/$ARCH"
80
#                       For International install
81
MIRRORLIST2="https://mirrors.mageia.org/api/mageia.$VERSION.$ARCH.list"
82
try_nb="0"; nb_repository="0"
83
while [ "$nb_repository" != "4" ]
84
do
85
	try_nb=`expr $try_nb + 1`
86
	MIRRORLIST="MIRRORLIST$try_nb"
87
	rpm_repository_sync
88
	nb_repository=`cat /etc/urpmi/urpmi.cfg|grep mirrorlist|wc -l`
89
	if [ "$nb_repository" != "4" ]
90
	then
91
		if [ $Lang == "fr" ]
92
		then
93
			echo "Une erreur a été détectée lors de la synchronisation avec le dépot N°$try_nb."
94
		else
95
			echo "An error occurs when synchronising the repositories N°$try_nb"
96
		fi
97
		if [ $(expr $try_nb) -eq $MIRROR_NBR ]
98
		then
99
			rpm_error
100
			exit 1
101
		fi
102
		if [ $Lang == "fr" ]
103
		then
104
			echo "Voulez-vous tenter une synchronisation avec un autre dépôt ? (O/n)"
105
		else
106
			echo "Do you want to try a synchronisation with an other repository? (Y/n)"
107
		fi
108
		response=0
109
		PTN='^[oOnNyY]?$'
110
		until [[ "$response" =~ $PTN ]]
111
		do
112
			read response
113
		done
114
		if [ "$response" = "n" ] || [ "$response" = "N" ]
115
		then
116
			exit 1
117
		fi
118
	fi
119
done
120
# download the kernel used by ALCASAR
121
if [ $Lang == "fr" ]
122
then
123
	echo "Récupération du noyau Linux exploité par ALCASAR. Veuillez patienter ..."
124
else
125
	echo "Download the Linux kernel used by ALCASAR. Please wait ..."
126
fi
127
urpmi --auto --quiet $KERNEL
128
# Remove some of our RPMs in order to avoid their update
129
urpme wkhtmltopdf
130
# download updated RPM in cache
131
if [ $Lang == "fr" ]
132
then
133
	echo "Récupération des paquetages de mise à jour. Veuillez patienter ..."
134
	echo "Il est temps d'aller prendre un café (ou une bonne bière) ;-)"
135
else
136
	echo "Updated RPM download. Please wait ..."
137
	echo "You should now take a coffe (or a good beer) ;-)"
138
fi
139
urpmi --auto --auto-update --quiet --test --retry 2
140
if [ "$?" != "0" ]
141
then
142
	echo
143
	if [ $Lang == "fr" ]
144
	then
145
		echo "Une erreur a été détectée lors de la récupération des paquetages."
146
	else
147
		echo "An error occurs when downloading RPMS"
148
	fi
149
	rpm_error
150
	exit 1
151
fi
152
 
153
# update with cached RPM
154
urpmi --auto --auto-update
155
if [ "$?" != "0" ]
156
then
157
	echo
158
	if [ $Lang == "fr" ]
159
	then
160
		echo "Une erreur a été détectée lors de la mise à jour des paquetages."
161
	else
162
		echo "An error occurs when updating packages"
163
	fi
164
	rpm_error
165
	exit 1
166
fi
167
# Clean the RPM cache
168
urpmi --clean
169
 
170
# Download of ALCASAR specifics RPM in cache (and test)
171
if [ $Lang == "fr" ]
172
then
173
	echo "Récupération des paquetages complémentaires. Veuillez patienter ..."
174
else
175
	echo "Download of complementary packages. Please wait ..."
176
fi
177
urpmi --auto --no-recommends $PACKAGES --quiet --test --retry 2
178
if [ "$?" != "0" ]
179
then
180
	echo
181
	if [ $Lang == "fr" ]
182
	then
183
		echo "Une erreur a été détectée lors de la récupération des paquetages complémentaires."
184
	else
185
		echo "An error occurs when downloading complementary packages"
186
	fi
187
	rpm_error
188
	exit 1
189
fi
190
 
191
# update with cached RPM
192
urpmi --auto --no-recommends $PACKAGES
193
if [ "$?" != "0" ]
194
then
195
	echo
196
	if [ $Lang == "fr" ]
197
	then
198
		echo "Une erreur a été détectée lors de l'installation des paquetages complémentaires."
199
	else
200
		echo "An error occurs when installing complementary packages"
201
	fi
202
	rpm_error
203
	exit 1
204
fi
205
 
206
# Keep only the kernel version we compil netflow with, and remove all others
207
kernelVersion=$(rpm -qa | grep -e ^kernel-server -e ^kernel-desktop)
208
for i in $kernelVersion
209
do
210
	if [ $i != $KERNEL ];then
211
		urpme --auto $i
212
	fi
213
done
214
# delete unused RPMs
215
if [ $Lang == "fr" ]
216
then
217
	echo "Cleaning the system : "
218
else
219
	echo "Nettoyage du système : "
220
fi
221
rm_rpm="shorewall mandi plymouth cpupower squid"
222
/usr/sbin/urpme --auto -a $rm_rpm
223
/usr/sbin/urpme --auto --auto-orphans
224
 
225
# Save chilli launch script (erase with new rpm one)
226
[ -e /etc/chilli.conf ] && cp /etc/chilli.conf /tmp/
227
# Install home made RPMs
228
for pkg in `ls rpms/$ARCH/*.rpm`
229
do
230
    urpmi --no-verify --auto $pkg
231
done
232
# restore chilli launch script
233
[ -e /tmp/chilli.conf ] && mv /tmp/chilli.conf /etc/
234
# Clean the RPM cache
235
urpmi --clean
236
# 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)
237
/sbin/depmod -a 2>/dev/null
238
# test if all needed rpms are correctly installed
239
count_pkg=0; nb_pkg=0;
240
for pkg in $PACKAGES
241
do
242
	nb_pkg=`expr $nb_pkg + 1`
243
	if rpm -q --quiet $pkg ; then
244
		count_pkg=`expr $count_pkg + 1`
245
	else
246
		echo "error installing $pkg"
247
	fi
248
done
249
if [ $count_pkg -ne $nb_pkg ]
250
then
251
	exit 1
252
fi
253
# test if all custom rpms are correctly installed
254
count_pkg=0; nb_pkg=0;
255
for pkg in `ls rpms/$ARCH/|sed 's/.x86_64.rpm//'`
256
do
257
	nb_pkg=`expr $nb_pkg + 1`
258
	if rpm -q --quiet $pkg ; then
259
		count_pkg=`expr $count_pkg + 1`
260
	else
261
		echo "error installing $pkg"
262
	fi
263
done
264
if [ $count_pkg -ne $nb_pkg ]
265
then
266
	exit 1
267
fi
268
# fix some RPM versions
269
echo "/^kernel/" > /etc/urpmi/skip.list
270
echo "/^wkhtmltopdf/" >> /etc/urpmi/skip.list
271
echo "/^clamd/" >> /etc/urpmi/skip.list
272
echo "/^clamav/" >> /etc/urpmi/skip.list
273
echo "exclude=kernel* wkhtmltopdf clamd clamav" >> /etc/dnf/dnf.conf
274
exit 0