3 # Copyright (c) 2012 Peter Palfrader
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:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
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.
25 echo >&2 "Usage: $0 <component>"
29 componentlist=/etc/static-components.conf
38 if [ "${component%/*}" != "$component" ] ; then
39 echo >&2 "$0: Invalid component: $component";
43 thishost=$(hostname -f)
44 masterhost="$(awk -v component="$component" '!/^ *(#|$)/ && $2 == component {print $1; exit}' "$componentlist")"
45 srchost="$(awk -v component="$component" '!/^ *(#|$)/ && $2 == component {print $3; exit}' "$componentlist")"
46 srcdir="$(awk -v component="$component" '!/^ *(#|$)/ && $2 == component {print $4; exit}' "$componentlist")"
48 awk -v component="$component" -v host="$thishost" '
49 !/^ *(#|$)/ && $2 == component {
52 if (host == extra[i]) {
53 printf "%s:%s\n", $3, $4
60 if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
61 echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
65 if ! [ "$srchost" = "$thishost" ] && [ -z "$inextralist" ]; then
66 echo >&2 "Component $component is sourced from $srchost, and this host is neither that nor in the extra allowed list."
70 if [ "$srchost" = "$thishost" ] && ! [ -d "$srcdir" ]; then
71 echo >&2 "Component source directory $srcdir does not exist or is not a directory, or is not accessible."
75 if [ "`id -nu`" != "staticsync" ]; then
76 sudo -u staticsync static-update-component "$@"
78 ssh -o AddressFamily=inet -t -o ServerAliveInterval=300 -o PreferredAuthentications=publickey "$masterhost" static-master-update-component "$component"
83 # vim:set shiftwidth=2: