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