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