Subversion Repositories ALCASAR

Rev

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