Skip to content

Commit d36e713

Browse files
committed
Working script.
* Add the AFS-script * Make the script idempotent * Fix a few bugs
1 parent da980ed commit d36e713

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

make-user

+35-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# POC - Make a user, never tested
55

66
abort() {
7-
echo "ABORT: $@"
7+
echo -e "ABORT: $@"
88
exit 1
99
}
1010

@@ -47,22 +47,19 @@ log "Query finger.json for $1"
4747

4848
log "Check for $1 in KDC"
4949
if echo get $1 | kadmin | grep -q "$1@STACKEN.KTH.SE"; then
50-
abort "Principal $1 exists in KDC, abort!"
50+
log "Principal $1 exists in KDC, ignore"
51+
else
52+
log "Add $1 to KDC"
53+
kadmin add \
54+
--max-ticket-life="10 hours" \
55+
--max-renewable-life=unlimited \
56+
--expiration-time="$(date +%Y --date="2 years")-03-15" \
57+
--pw-expiration-time=never \
58+
--attributes="requires-pre-auth, disallow-postdated" \
59+
--policy=default \
60+
$1
5161
fi
5262

53-
log "Add $1 to KDC"
54-
kadmin add \
55-
--max-ticket-life="10 hours" \
56-
--max-renewable-life=unlimited \
57-
--expiration-time="$(date +%Y --date="2 years")-03-15" \
58-
--pw-expiration-time=never \
59-
--attributes="requires-pre-auth, disallow-postdated" \
60-
--policy=default \
61-
$1
62-
63-
cd /afs/stacken.kth.se/admin/passwd/
64-
grep -qE "^$1" master.passwd && abort "User $1 is already part of master.passwd"
65-
6663
next_passwd_uid() {
6764
for n in $(seq 18000 19000); do
6865
if ! grep -q $n master.passwd; then
@@ -72,13 +69,28 @@ next_passwd_uid() {
7269
done
7370
}
7471

75-
PASSWD_UID=$(next_passwd_uid)
76-
log "Add $1 ($2) to master.passwd with UID $PASSWD_UID"
77-
[ -z $PASSWD_UID ] && abort "No free UID found"
78-
co -u master.passwd
79-
echo "$1:*:$PASSWD_UID:30::0:0:$2:/afs/stacken.kth.se/home/$1:/bin/bash" \
80-
>> master.passwd
81-
ci -l -m "Added user $1 ($2) with $0" master.passwd
72+
cd /afs/stacken.kth.se/admin/passwd/
73+
if grep -qE "^$1" master.passwd; then
74+
log "User $1 is already part of master.passwd"
75+
else
76+
PASSWD_UID=$(next_passwd_uid)
77+
log "Add $1 ($2) to master.passwd with UID $PASSWD_UID"
78+
[ -z $PASSWD_UID ] && abort "No free UID found"
79+
co -u master.passwd
80+
echo "$1:*:$PASSWD_UID:30::0:0:$2:/afs/stacken.kth.se/home/$1:/bin/bash" \
81+
>> master.passwd
82+
ci -l -m "Added user $1 ($2) with $0" master.passwd
83+
log "Build database"
84+
make
85+
fi
8286

8387
log "Setup AFS volume"
84-
# TODO
88+
89+
if [ -e "/afs/stacken.kth.se/home/$1" ]; then
90+
log "Home dir for user $1 exists"
91+
else
92+
/afs/stacken.kth.se/src/script/createuser $1 beef.stacken.kth.se vicepa
93+
vos release home
94+
fi
95+
96+
log "Looks good, all done!"

query_finger

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import json
55
import sys
66
from optparse import OptionParser
77

8-
finger = "/afs/stacken.kth.se/home/stacken/Private/finger.json"
8+
finger = "/afs/stacken.kth.se/home/stacken/Private/finger_txt/finger.json"
99

1010
fd = open(finger, 'r')
1111
data = json.load(fd)

0 commit comments

Comments
 (0)