Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

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