Debian Codegraph @

sync-accounts/grab-account

raw
1 #!/bin/sh
2 # This is part of sync-accounts, a tool for synchronising UN*X password data.
3 #
4 # sync-accounts is
5 # Copyright 1999-2000,2002 Ian Jackson <[email protected]>
6 # Copyright 2000-2001 nCipher Corporation Ltd
7 #
8 # sync-accounts is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 3, or (at
11 # your option) any later version.
12 #
13 # sync-accounts is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should already have a copy of the GNU General Public License.
19 # If not, consult the Free Software Foundation's website at
20 # www.fsf.org, or the GNU Project website at www.gnu.org.
21 #
22 # $Id: grab-account,v 1.5 2007-09-21 21:21:15 ianmdlvl Exp $
23
24 set -e
25
26 if [ $# -lt 2 -o $# -gt 3 ]
27 then
28 echo >&2 \
29 'usage: grab-account <localuser> <shorthostname> [<remoteuser>]
30 creates an entry in /etc/sync-accounts, and runs sync-accounts
31 $Id: grab-account,v 1.5 2007-09-21 21:21:15 ianmdlvl Exp $'
32 exit 1
33 fi
34
35 lu="$1"
36 sh="$2"
37
38 if [ $# -gt 2 ]
39 then
40 ru="$3"
41 else
42 ru="$1"
43 fi
44
45 cf=/etc/sync-accounts
46
47 if perl -ne 'exit 1 if m/^\s*user\s+'$lu'\s/;' <$cf
48 then
49 perl -pe '
50 next unless m/^\s*host\s+'$sh'\s*$/...m/^host|^end/;
51 next unless m/^\s*addhere\s*$/;
52 next if $done++;
53 print "user '$lu'".("'$lu'" eq "'$ru'" ? "" : " remote='$ru'")."\n"
54 or die $!;
55 END {
56 print(STDERR "\`addhere'\'' line not found\n"), $?=1 if !$? && !$done;
57 }
58 ' $cf >$cf.new
59 mv -f $cf.new $cf
60 else
61 echo "entry already exists in $cf, leaving alone"
62 fi
63
64 sync-accounts $sh