From 8063d110a07d937d3a31a9809b3cf38affc4d5e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Wed, 12 Apr 2017 09:22:09 +0200
Subject: [PATCH] Added a step for apt cacher ng configuration (refs #21177).

---
 .../3.Proxy_settings/0_setup.py               |  7 ------
 .../2.Configure_apt_cacher_ng/0_setup.py      | 24 +++++++++++++++++++
 launcher.sh                                   |  1 +
 3 files changed, 25 insertions(+), 7 deletions(-)
 create mode 100755 6.CampusManager/2.Configure_apt_cacher_ng/0_setup.py

diff --git a/3.New_server_deployment/3.Proxy_settings/0_setup.py b/3.New_server_deployment/3.Proxy_settings/0_setup.py
index 8490fc3a..38449921 100644
--- a/3.New_server_deployment/3.Proxy_settings/0_setup.py
+++ b/3.New_server_deployment/3.Proxy_settings/0_setup.py
@@ -27,17 +27,10 @@ def setup(interactive=True):
     if https_proxy:
         apt_proxy += 'Acquire::https::Proxy "%s";\n' % https_proxy
 
-    # apt-cacher-ng
-    apt_cacher_ng_conf_path = '/etc/apt-cacher-ng/acng.conf'
-    apt_cacher_ng_proxy = ''
-    if http_proxy:
-        apt_cacher_ng_proxy += 'Proxy: %s' % http_proxy
-
     # write changes
     files = (
         (environment_path, environment),
         (apt_proxy_path, apt_proxy),
-        (apt_cacher_ng_conf_path, apt_cacher_ng_proxy),
     )
     for path, content in files:
         if os.path.exists(path):
diff --git a/6.CampusManager/2.Configure_apt_cacher_ng/0_setup.py b/6.CampusManager/2.Configure_apt_cacher_ng/0_setup.py
new file mode 100755
index 00000000..8f1983b5
--- /dev/null
+++ b/6.CampusManager/2.Configure_apt_cacher_ng/0_setup.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import os
+import re
+
+import utils
+
+
+def setup(interactive=True):
+    http_proxy = utils.get_conf('PROXY_HTTP')
+    # apt-cacher-ng
+    path = '/etc/apt-cacher-ng/acng.conf'
+    if os.path.exists(path):
+        with open(path, 'r') as fo:
+            current_conf = fo.read()
+        new_conf = re.sub(r'\nProxy:.*', '', current_conf).strip() + '\n'
+        if http_proxy:
+            new_conf += '\nProxy: %s\n' % http_proxy
+        if current_conf != new_conf:
+            with open(path, 'w') as fo:
+                fo.write(new_conf)
+            utils.log('File "%s" updated.' % path)
+        else:
+            utils.log('File "%s" already up to date.' % path)
diff --git a/launcher.sh b/launcher.sh
index 6a3e0ef5..f3581981 100755
--- a/launcher.sh
+++ b/launcher.sh
@@ -56,6 +56,7 @@ campusmanager() {
     python3 /root/envsetup/envsetup.py 23
     python3 /root/envsetup/envsetup.py 25
     python3 /root/envsetup/envsetup.py 61
+    python3 /root/envsetup/envsetup.py 62
     python3 /root/envsetup/envsetup.py 25
 }
 
-- 
GitLab