Subversion Repositories ALCASAR

Rev

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

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