install.sh: expand @cfg_name@ in processed scripts
[girocco.git] / bin / update-pwd-db
blob05a0d6c47fd13be52dde2ec05e8986e04324ee54
1 #!/bin/sh
3 set -e
5 . @basedir@/shlib.sh
7 # If Config.pm $update_pwd_db is set then this script
8 # will be run whenever the passwd database in the jail
9 # has been changed and needs to be updated.
11 # This script will always be passed one or two arguments:
13 # update-pwd-db file [user]
15 # file - always passed. This is the full path to the
16 # file that is about to become the new etc/passwd
17 # file. It will be renamed into place after this
18 # script returns successfully.
20 # user - optionally passed. If passed then the only
21 # change to file involves the username 'user'.
23 [ -n "$1" ] && [ -r "$1" ] || { echo "update-pwd-db: error: no such passwd file: $1" >&2; exit 2; }
24 cd "$cfg_chroot"
25 user_only=
26 [ -z "$2" ] || user_only="-u $2"
27 cleanup() {
28 chmod 0664 etc/master.passwd etc/pwd.db etc/spwd.db || :
29 return 0
30 } >/dev/null 2>&1
31 trap cleanup EXIT
32 rm -f etc/master.passwd
33 LC_ALL=C awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' <"$1" >etc/master.passwd
34 PW_SCAN_BIG_IDS=1 pwd_mkdb -d etc $user_only etc/master.passwd 2>/dev/null
35 exit 0