From 6775d7e93737bba2bde02b19491125442d021c05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Wed, 26 Oct 2016 12:19:53 +0200
Subject: [PATCH] Fixed iptables setup for apt cacher (refs #19053).

---
 51.Install_CM/0_setup.sh | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/51.Install_CM/0_setup.sh b/51.Install_CM/0_setup.sh
index 73ffc259..62e9c54c 100755
--- a/51.Install_CM/0_setup.sh
+++ b/51.Install_CM/0_setup.sh
@@ -5,24 +5,22 @@ source /root/envsetup/conf.sh
 APT_CACHER_PWD=$(pwgen 12)
 
 # installation cm
-aptitude install -y campus-manager
+apt-get install -y campus-manager
 
 # installation cache local
-aptitude install -y apt-cacher-ng
+apt-get install -y apt-cacher-ng
 # secure it
 echo "AdminAuth: ${APT_CACHER_USER}:${APT_CACHER_PWD}" >> /etc/apt-cacher-ng/security.conf
 service apt-cacher-ng restart
 
 # proxy
-if [ ${PROXY} = "1" ]
-then
-	if [ ${PROXY_AUTHENTICATION} = "1" ]
-	then
-# general settings
-	echo "Proxy: http://${PROXY_USER}:${PROXY_PASSWD}@${PROXY_HTTP}:${PROXY_PORT}" >> /etc/apt-cacher-ng/acng.conf
+if [ ${PROXY} = "1" ]; then
+	if [ ${PROXY_AUTHENTICATION} = "1" ]; then
+		# general settings
+		echo "Proxy: http://${PROXY_USER}:${PROXY_PASSWD}@${PROXY_HTTP}:${PROXY_PORT}" >> /etc/apt-cacher-ng/acng.conf
 	else
-# general settings
-	echo "Proxy: http://${PROXY_HTTP}:${PROXY_PORT}" >> /etc/apt-cacher-ng/acng.conf
+		# general settings
+		echo "Proxy: http://${PROXY_HTTP}:${PROXY_PORT}" >> /etc/apt-cacher-ng/acng.conf
 	fi
 fi
 
@@ -35,11 +33,18 @@ sed -i "s@server_name skyreach;@server_name ${CM_SERVER_NAME};@" /etc/nginx/site
 service nginx restart
 
 # iptables rules for port 3142
-DEBIAN_FRONTEND=noninteractive aptitude install -y iptables-persistent
-update-rc.d iptables-persistent enable
+DEBIAN_FRONTEND=noninteractive apt-get install -y iptables-persistent
 iptables -A INPUT -p tcp -s localhost --destination-port 3142 -j ACCEPT
 iptables -A INPUT -p tcp --destination-port 3142 -j DROP
-service iptables-persistent save
+iptables-save
+# the save using "service" command fails on VM
+if ( cat /etc/lsb-release | grep '14.04' ); then
+	update-rc.d iptables-persistent enable
+	service iptables-persistent save || true
+else
+	update-rc.d netfilter-persistent enable
+	service netfilter-persistent save || true
+fi
 
 LIG=$(grep -n "^iface lo inet loopback" /etc/network/interfaces | awk -F ":" '{print$1}')
 LIG=$(( ${LIG} + 1 ))
-- 
GitLab