Do not hardcode debian specifics in staticsync scripts, make them use a conffile
authorPeter Palfrader <peter@palfrader.org>
Fri, 29 Sep 2017 08:43:29 +0000 (10:43 +0200)
committerPeter Palfrader <peter@palfrader.org>
Fri, 29 Sep 2017 08:43:35 +0000 (10:43 +0200)
modules/roles/files/static-mirroring/static-master-run
modules/roles/files/static-mirroring/static-master-update-component
modules/roles/files/static-mirroring/static-mirror-run-all
modules/roles/files/static-mirroring/static-update-component
modules/roles/files/static-mirroring/staticsync-ssh-wrap
modules/roles/manifests/static_base.pp

index e2a583e..e7e8b2d 100755 (executable)
@@ -9,10 +9,23 @@ import sys
 import tempfile
 import time
 
-base="/srv/static.debian.org"
 serialname = '.serial'
 had_warnings = False
 
+conffile = '/etc/staticsync.conf'
+config={}
+
+with open(conffile) as f:
+  for line in f:
+    line = line.rstrip()
+    if not line or line.startswith("#"): continue
+    (name, value) = line.split("=")
+    config[name] = value
+
+for key in ('base'):
+  if not key in config:
+    raise Exception("Configuration element '%s' not found in config file %s", key, conffile)
+
 allclients = set()
 with open('/etc/static-clients.conf') as f:
   for line in f:
@@ -106,7 +119,7 @@ def callout(component, serial, clients):
     stage2(pipes, status, 'abort', clients)
     return False
 
-  failedmirrorsfile = os.path.join(base, 'master', component + "-failedmirrors")
+  failedmirrorsfile = os.path.join(config['base'], 'master', component + "-failedmirrors")
   if 'failed' in cnt:
     log("WARNING: %d clients failed!  Continuing anyway!"%(cnt['failed'],))
     global had_warnings
@@ -152,7 +165,7 @@ def run_mirror(component):
   clients = allclients - meta['extraignoreclients']
 
   # setup
-  basemaster = os.path.join(base, 'master')
+  basemaster = os.path.join(config['base'], 'master')
   componentdir = os.path.join(basemaster, component)
   cur = componentdir + '-current-push'
   live = componentdir + '-current-live'
index 64836ba..2d397df 100755 (executable)
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 componentlist=/etc/static-components.conf
-base=/home/staticsync/static-master/master
+. /etc/staticsync.conf
+if ! [ -n "$masterbase" ]; then
+  echo >&2 "masterbase not configured!"
+  exit 1
+fi
 
 set -e
 set -u
 
-if [ "`id -u`" != "`stat -c %u "$base"`" ]; then
+if [ "`id -u`" != "`stat -c %u "$masterbase"`" ]; then
   echo >&2 "You are probably running this as the wrong user."
   exit 1
 fi
@@ -87,7 +91,7 @@ if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
   echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
   exit 1
 fi
-tgt="$base/$component"
+tgt="$masterbase/$component"
 if ! [ -d "$tgt" ]; then
   echo "$0: Creating $tgt for $component";
   mkdir "$tgt"
@@ -102,8 +106,8 @@ fi
 echo "$0: Acquiring locks..."
 lock 201 "$tgt" 1
 
-tmpdir_new="$(mktemp -d --tmpdir="$base" "${component}-updating.incoming-XXXXXX")"
-tmpdir_old="$(mktemp -d --tmpdir="$base" "${component}-updating.removing-XXXXXX")"
+tmpdir_new="$(mktemp -d --tmpdir="$masterbase" "${component}-updating.incoming-XXXXXX")"
+tmpdir_old="$(mktemp -d --tmpdir="$masterbase" "${component}-updating.removing-XXXXXX")"
 trap "rm -rf '$tmpdir_new' '$tmpdir_old'" EXIT
 chmod 0755 "$tmpdir_new"
 
index b85948f..c6aea0c 100755 (executable)
 
 set -u
 
+. /etc/staticsync.conf
+if ! [ -n "$base" ]; then
+  echo >&2 "base not configured!"
+  exit 1
+fi
+
 awk -v host="$(hostname -f)" '
   !/^ *(#|$)/ {
     split($6,ignorehosts,",")
@@ -36,5 +42,5 @@ awk -v host="$(hostname -f)" '
     print $1, $2
   }' /etc/static-components.conf |
   while read master component ; do
-    static-mirror-run --one-stage "/srv/static.debian.org/mirrors/$component" "$master:$component/-live-"
+    static-mirror-run --one-stage "$base/mirrors/$component" "$master:$component/-live-"
   done
index f8ca81e..455d17d 100755 (executable)
@@ -27,6 +27,11 @@ usage() {
 }
 
 componentlist=/etc/static-components.conf
+. /etc/staticsync.conf
+if ! [ -n "$staticuser" ]; then
+  echo >&2 "staticuser not configured!"
+  exit 1
+fi
 
 if [ "$#" = 1 ]; then
   component="$1"
@@ -72,8 +77,8 @@ if [ "$srchost" = "$thishost" ] && ! [ -d "$srcdir" ]; then
   exit 1
 fi
 
-if [ "`id -nu`" != "staticsync" ]; then
-  sudo -u staticsync static-update-component "$@"
+if [ "`id -nu`" != "$staticuser" ]; then
+  sudo -u "$staticuser" static-update-component "$@"
 else
   ssh -o AddressFamily=inet -t -t -o ServerAliveInterval=300 -o PreferredAuthentications=publickey "$masterhost" static-master-update-component "$component"
 fi
index dfd98c8..a407547 100755 (executable)
 set -e
 set -u
 
+. /etc/staticsync.conf
+if ! [ -n "$base" ]; then
+  echo >&2 "base not configured!"
+  exit 1
+fi
+BASEDIR="$base"
+
 MYLOGNAME="`basename "$0"`[$$]"
-BASEDIR="/srv/static.debian.org"
 COMPONENTLIST=/etc/static-components.conf
 
 usage() {
index 95ad7d9..fa756d6 100644 (file)
@@ -38,4 +38,16 @@ class roles::static_base {
                rule        => 'proto tcp mod state state (NEW) mod multiport destination-ports (6881:6999) @subchain \'static-bt\' { saddr ($HOST_STATIC_V6) ACCEPT; }',
                notarule    => true,
        }
+
+       file { "/etc/staticsync.conf":
+               content  => @("EOF"),
+                               # This file is sourced by bash
+                               # and parsed by python
+                               #  - empty lines and lines starting with a # are ignored.
+                               #  - other lines are key=value.  No extra spaces anywhere.  No quoting.
+                               base=/srv/static.debian.org
+                               masterbase=/home/staticsync/static-master/master
+                               staticuser=staticsync
+                               | EOF
+       }
 }