Working script.

* Add the AFS-script
* Make the script idempotent
* Fix a few bugs
This commit is contained in:
Stefan Berggren 2016-09-01 22:00:00 +02:00
parent da980ed894
commit d36e713a62
2 changed files with 36 additions and 24 deletions

View file

@ -4,7 +4,7 @@
# POC - Make a user, never tested
abort() {
echo "ABORT: $@"
echo -e "ABORT: $@"
exit 1
}
@ -47,11 +47,10 @@ log "Query finger.json for $1"
log "Check for $1 in KDC"
if echo get $1 | kadmin | grep -q "$1@STACKEN.KTH.SE"; then
abort "Principal $1 exists in KDC, abort!"
fi
log "Add $1 to KDC"
kadmin add \
log "Principal $1 exists in KDC, ignore"
else
log "Add $1 to KDC"
kadmin add \
--max-ticket-life="10 hours" \
--max-renewable-life=unlimited \
--expiration-time="$(date +%Y --date="2 years")-03-15" \
@ -59,9 +58,7 @@ kadmin add \
--attributes="requires-pre-auth, disallow-postdated" \
--policy=default \
$1
cd /afs/stacken.kth.se/admin/passwd/
grep -qE "^$1" master.passwd && abort "User $1 is already part of master.passwd"
fi
next_passwd_uid() {
for n in $(seq 18000 19000); do
@ -72,13 +69,28 @@ next_passwd_uid() {
done
}
PASSWD_UID=$(next_passwd_uid)
log "Add $1 ($2) to master.passwd with UID $PASSWD_UID"
[ -z $PASSWD_UID ] && abort "No free UID found"
co -u master.passwd
echo "$1:*:$PASSWD_UID:30::0:0:$2:/afs/stacken.kth.se/home/$1:/bin/bash" \
cd /afs/stacken.kth.se/admin/passwd/
if grep -qE "^$1" master.passwd; then
log "User $1 is already part of master.passwd"
else
PASSWD_UID=$(next_passwd_uid)
log "Add $1 ($2) to master.passwd with UID $PASSWD_UID"
[ -z $PASSWD_UID ] && abort "No free UID found"
co -u master.passwd
echo "$1:*:$PASSWD_UID:30::0:0:$2:/afs/stacken.kth.se/home/$1:/bin/bash" \
>> master.passwd
ci -l -m "Added user $1 ($2) with $0" master.passwd
ci -l -m "Added user $1 ($2) with $0" master.passwd
log "Build database"
make
fi
log "Setup AFS volume"
# TODO
if [ -e "/afs/stacken.kth.se/home/$1" ]; then
log "Home dir for user $1 exists"
else
/afs/stacken.kth.se/src/script/createuser $1 beef.stacken.kth.se vicepa
vos release home
fi
log "Looks good, all done!"

View file

@ -5,7 +5,7 @@ import json
import sys
from optparse import OptionParser
finger = "/afs/stacken.kth.se/home/stacken/Private/finger.json"
finger = "/afs/stacken.kth.se/home/stacken/Private/finger_txt/finger.json"
fd = open(finger, 'r')
data = json.load(fd)