]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/roles/templates/static-mirroring/static-update-component.erb
typo fix
[dsa-puppet.git] / modules / roles / templates / static-mirroring / static-update-component.erb
1 #!/bin/bash
2
3 # Copyright (c) 2012 Peter Palfrader
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 usage() {
25   echo >&2 "Usage: $0 <component>"
26   exit 1
27 }
28
29 componentlist=/etc/static-components.conf
30
31 if [ "$#" = 1 ]; then
32   component="$1"
33 else
34   usage
35 fi
36
37
38 if [ "${component%/*}" != "$component" ] ; then
39   echo >&2 "$0: Invalid component: $component";
40   exit 1
41 fi
42
43 thishost=$(hostname -f)
44 srchost="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")"
45 srcdir="$(awk -v component="$component" '$1 == component {print $3; exit}' "$componentlist")"
46 inextralist="$(
47                awk -v component="$component" -v host="$thishost" '
48                  $1 == component {
49                    split($4,extra,",")
50                    for (i in extra) {
51                      if (host == extra[i]) {
52                        printf "%s:%s\n", $2, $3
53                        exit
54                      }
55                    }
56                    exit
57                  }' "$componentlist"
58               )"
59 if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
60   echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
61   exit 1
62 fi
63
64 if ! [ "$srchost" = "$thishost" ] && [ -z "$inextralist" ]; then
65   echo >&2 "Component $component is sourced from $srchost, and this host is neither that nor in the extra allowed list."
66   exit 1
67 fi
68
69 if [ "$srchost" = "$thishost" ] && ! [ -d "$srcdir" ]; then
70   echo >&2 "Component source directory $srcdir does not exist or is not a directory, or is not accessible."
71   exit 1
72 fi
73
74 if [ "`id -nu`" != "staticsync" ]; then
75   sudo -u staticsync static-update-component "$@"
76 else
77   masters=()
78 <%=
79 lines = []
80 masters = []
81 scope.lookupvar('site::localinfo').keys.sort.each do |node|
82     if scope.lookupvar('site::localinfo')[node]['static_master']
83         lines << "  masters+=(\"#{node}\")"
84     end
85 end
86 lines.join("\n")
87 %>
88
89   for master_idx in ${!masters[*]}; do
90     ssh -o AddressFamily=inet -t -o ServerAliveInterval=300 -o PreferredAuthentications=publickey "${masters[$master_idx]}" static-master-update-component "$component"
91   done
92 fi
93
94 # vim:set et:
95 # vim:set ts=2:
96 # vim:set shiftwidth=2:
97 # vim:set syn=sh: