]> mj.ucw.cz Git - moe.git/blob - mop/admin/mo-create-logins.sh
Merge branch 'layout'
[moe.git] / mop / admin / mo-create-logins.sh
1 #!/bin/bash
2 # Create /etc/shadow, /etc/passwd and /etc/group records for accounts
3 # used by the evaluator and the contestants.
4
5 [ -f cf/mop ] || { echo "Missing config file, check cwd." ; exit 1 ; }
6 set -e
7 . cf/mop
8
9 mode=$1
10
11 case "$mode" in
12   eval) uid=$EVAL_UID_MIN;;
13   users) uid=$CT_UID_MIN;;
14   *) echo "Usage: $0 [eval|users]!"; exit 1;;
15 esac
16
17 >>etcshadow >>etcpasswd >>etcgroup
18 expire=$((`date +%s` / 86400 - 1))
19
20 case $mode in
21   eval)
22     echo -n Enter password for evaluation users:
23     read passwd
24     passwd=`echo $passwd | bin/md5crypt`
25     gid=$uid
26     tgid=$(($gid+1))
27     rgid=$(($gid+2))
28     echo $EVAL_USER:x:$uid:$gid:MO Evaluator:$MO_ROOT/eval/eval:/bin/bash >> etcpasswd
29     echo $EVAL_USER:$passwd:$expire:0:99999:7:::                >> etcshadow
30     echo $EVAL_GROUP:x:$gid:                                    >> etcgroup
31     echo $TEST_GROUP:x:$tgid:$EVAL_USER                         >> etcgroup
32
33     if [ -n "$REMOTE_SUBMIT" ] ; then
34       uid=$(($uid + 1))
35       echo $REMOTE_SUBMIT_USER:x:$uid:$rgid:MO Submitter:$MO_ROOT/eval/submit:/bin/bash >> etcpasswd
36       echo $REMOTE_SUBMIT_USER:$passwd:$expire:0:99999:7:::                             >> etcshadow
37       echo $REMOTE_SUBMIT_GROUP:x:$rgid:                                                >> etcgroup
38     fi
39
40     tuid=$(($uid + 1))
41     for tester in $TEST_USERS; do
42       echo $tester:x:$tuid:$tgid:MO Tester `expr $tuid - $uid`:$MO_ROOT/eval/$tester:/bin/bash  >> etcpasswd
43       echo $tester:$passwd:$expire:0:99999:7:::                         >> etcshadow
44       tuid=$(($tuid + 1))
45     done
46   ;;
47
48   users)
49 #   if [ -f logins.tex ]; then echo "File logins.tex exists! Bailing out!"; exit 1; fi
50     cat > logins.tex <<- EOF
51         \\nopagenumbers
52         \\voffset=-1.5cm\\vsize=280mm\\hoffset=-0.75cm\\advance\\hsize by 3cm
53         \\rightskip=0pt plus 3in\\parindent=0pt
54         \\font\\ftt=cstt17
55         \\font\\frm=csr17
56         \\font\\fit=csti17
57         \\ftt
58         \\def\\user#1#2#3{\\vbox to 4.5cm{\\hsize=6cm\\vss\\vss{\\fit Practice Session}\\vss\\vss{\\frm #3}\\vss\\vss#1\\vss#2\\vss\\vss}}
59         \\leavevmode
60         EOF
61
62     bin/mo-get-users --full | while read user name; do
63       passwd=`apg -n1 -m6 -Mncl | cut -d" " -f1 | tr l1O0 '@*?-' `
64       passwd_md5=`echo $passwd | bin/md5crypt`
65       echo $user:x:$uid:$uid:$name:$MO_ROOT/users/$user/$user:/bin/bash                 >> etcpasswd
66       echo $user:x:$uid:                                                                >> etcgroup
67       echo $user:$passwd_md5:`expr \`date +%s\` / 86400 - 1`:0:99999:7:::               >> etcshadow
68       echo "\\user{$user}{$passwd}{$name}"                                              >> logins.tex
69       uid=$(($uid + 1))
70     done
71
72     cat >> logins.tex <<- EOF
73         \\vfil
74         \\bye
75         EOF
76   ;;
77 esac