chiark / gitweb /
tarfile-maker, grab-account, rcsids
[chiark-utils.git] / sync-accounts / grab-account
diff --git a/sync-accounts/grab-account b/sync-accounts/grab-account
new file mode 100755 (executable)
index 0000000..2eef468
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+set -e
+
+if [ $# -lt 2 -o $# -gt 3 ]
+then
+       echo >&2 \
+'usage: grab-account <localuser> <shorthostname> [<remoteuser>]
+creates an entry in /etc/sync-accounts, and runs sync-accounts
+$Id: grab-account,v 1.1 1999-01-03 00:14:07 ian Exp $'
+       exit 1
+fi
+
+lu="$1"
+sh="$2"
+
+if [ $# -gt 2 ]
+then
+       ru="$3"
+else
+       ru="$1"
+fi
+
+cf=/etc/sync-accounts
+
+if perl -ne 'exit 1 if m/^\s*user\s+'$lu'\s/;' <$cf
+then
+       perl -pe '
+               next unless m/^\s*host\s+'$sh'\s*$/...m/^host|^end/;
+               next unless m/^\s*addhere\s*$/;
+               next if $done++;
+               print "user '$lu'".("'$lu'" eq "'$ru'" ? "" : " remote='$ru'")."\n"
+                       or die $!;
+        END {
+               print(STDERR "\`addhere'\'' line not found\n"), $?=1 if !$? && !$done;
+        }
+               ' $cf >$cf.new
+       mv -f $cf.new $cf
+else
+       echo "entry already exists in $cf, leaving alone"
+fi
+
+sync-accounts