Subversion Repositories ALCASAR

Rev

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