#!/bin/sh set -e if [ $# -lt 2 -o $# -gt 3 ] then echo >&2 \ 'usage: grab-account [] creates an entry in /etc/sync-accounts, and runs sync-accounts $Id: grab-account,v 1.2 1999-01-03 02:56: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 $sh