make TCP_UDP_SERVICE not be stateful
[mirror/dsa-puppet.git] / modules / roles / files / static-mirroring / static-master-update-component
index a79f342..f2ea116 100755 (executable)
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-componentlist=/home/staticsync/etc/static-components
+componentlist=/etc/static-components.conf
 base=/home/staticsync/static-master/master
 
 set -e
 set -u
 
+if [ "`id -u`" != "`stat -c %u "$base"`" ]; then
+  echo >&2 "You are probably running this as the wrong user."
+  exit 1
+fi
 
 lock() {
   local fd="$1"; shift
@@ -77,15 +81,22 @@ if [ "${component%/*}" != "$component" ] ; then
   exit 1
 fi
 
-src="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")"
-if [ -z "$src" ]; then
+srchost="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")"
+srcdir="$(awk -v component="$component" '$1 == component {print $3; exit}' "$componentlist")"
+if [ -z "$srchost" ] || [ -z "$srcdir" ]; then
   echo >&2 "$0: Invalid component: $component (not found in $componentlist)";
   exit 1
 fi
 tgt="$base/$component"
 if ! [ -d "$tgt" ]; then
-  echo >&2 "$0: Invalid component: $component ($tgt does not exist)";
-  exit 1
+  echo "$0: Creating $tgt for $component";
+  mkdir "$tgt"
+fi
+
+if [ "$srchost" = "`hostname -f`" ]; then
+  src="$srcdir"
+else
+  src="$srchost:$srcdir"
 fi
 
 echo "$0: Acquiring locks..."
@@ -102,7 +113,8 @@ echo "$0: Got them."
 
 echo "$0: Updating master copy of $component..."
 rsync --delete \
-  -tr \
+  -trz \
+  --links --hard-links --safe-links \
   --link-dest="$tgt" \
   "$src/." "$tmpdir_new/."
 echo "$0: Done.  Committing."