]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/roles/templates/static-mirroring/static-update-component.erb
fix script
[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 componentlist=/etc/static-components.conf
25
26 if [ "$#" != 1 ]; then
27   echo >&2 "Usage: $0 <component>"
28   exit 1
29 fi
30
31 component="$1"
32
33 if [ "${component%/*}" != "$component" ] ; then
34   echo >&2 "$0: Invalid component: $component";
35   exit 1
36 fi
37
38 srchost="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")"
39 srcdir="$(awk -v component="$component" '$1 == component {print $3; exit}' "$componentlist")"
40 if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
41   echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
42   exit 1
43 fi
44
45 if [ "$srchost" = "`hostname -f`" ]; then
46   src="$srcdir"
47 else
48   echo >&2 "Component $component is sourced from $srchost, not this host."
49   exit 1
50 fi
51
52 if ! [ -d "$srcdir" ]; then
53   echo >&2 "Component source directory $srcdir does not exist or is not a directory, or is not accessible."
54   exit 1
55 fi
56
57 if [ "`id -nu`" != "staticsync" ]; then
58   sudo -u staticsync static-update-component "$component"
59 else
60   masters=()
61 <%=
62 lines = []
63 masters = []
64 scope.lookupvar('site::localinfo').keys.sort.each do |node|
65     if scope.lookupvar('site::localinfo')[node]['static_master']
66         lines << "masters+=(\"#{node}\"}"
67     end
68 end
69 lines.join("\n")
70 %>
71
72   for master_idx in ${!masters[*]}; do
73     ssh "${masters[$master_idx]}" static-master-update-component "$component"
74   done
75 fi
76
77 # vim:set et:
78 # vim:set ts=2:
79 # vim:set shiftwidth=2:
80 # vim:set syn=sh: