1 | #!/bin/bash |
---|
2 | |
---|
3 | if [ "$initlname" = "" ]; then |
---|
4 | if [ "$lname" = "" ]; then |
---|
5 | initlname=0 |
---|
6 | else |
---|
7 | initlname=1 |
---|
8 | fi |
---|
9 | fi |
---|
10 | |
---|
11 | if type wget >/dev/null 2>/dev/null; then |
---|
12 | WGET=wget |
---|
13 | else |
---|
14 | WGET="athrun gnu wget" |
---|
15 | fi |
---|
16 | |
---|
17 | if [ "$lname" = "" ]; then |
---|
18 | if [ "$1" = "" ]; then |
---|
19 | echo |
---|
20 | echo "Would you like to sign up:" |
---|
21 | echo "1. Your personal Athena account" |
---|
22 | echo "2. A locker that you control (a club, a course, etc)" |
---|
23 | echo "If you do not understand this question, you should answer '1'." |
---|
24 | printf "Please enter either '1' or '2' (without quotes): " |
---|
25 | read whofor |
---|
26 | if [ "$whofor" = 1 ]; then |
---|
27 | lname="${ATHENA_USER:-$USER}" |
---|
28 | elif [ "$whofor" = 2 ]; then |
---|
29 | echo |
---|
30 | echo "OK. A locker of your choice that you control will be signed up." |
---|
31 | echo "Please enter the name of the selected locker below." |
---|
32 | echo "(For the locker /mit/sipb, you would enter sipb)." |
---|
33 | printf "Locker name: " |
---|
34 | read lname |
---|
35 | else |
---|
36 | echo |
---|
37 | echo "ERROR:" |
---|
38 | echo "You must select either '1' or '2'." |
---|
39 | exit 1 |
---|
40 | fi |
---|
41 | while true; do |
---|
42 | if attach "$lname"; then |
---|
43 | break |
---|
44 | fi |
---|
45 | echo "$lname is not a valid locker name." |
---|
46 | printf "Locker name: " |
---|
47 | read lname |
---|
48 | done |
---|
49 | else |
---|
50 | lname="$1" |
---|
51 | fi |
---|
52 | fi |
---|
53 | lroot="/mit/$lname" |
---|
54 | |
---|
55 | attach "$lname" 2>/dev/null |
---|
56 | |
---|
57 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/fsla.php/mit/$lname"` |
---|
58 | if [ "$ans" != "0" ]; then |
---|
59 | echo |
---|
60 | echo "ERROR:" |
---|
61 | echo "The scripts servers cannot verify the permissions of the locker <$lname>." |
---|
62 | echo "Try running \"fs sa /mit/$lname daemon.scripts l\" (with a lowercase" |
---|
63 | echo "L at the end) and then try again. Contact scripts@mit.edu if you are" |
---|
64 | echo "unable to solve the problem." |
---|
65 | exit 1 |
---|
66 | fi |
---|
67 | |
---|
68 | principal=`klist -5 | sed -n 's/^Default principal: // p'` |
---|
69 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/admof.php/$lname/$principal"` |
---|
70 | if [ "$ans" != "yes" ]; then |
---|
71 | afsuser=`echo "$principal" | sed 's/@ATHENA.MIT.EDU$//'` |
---|
72 | echo |
---|
73 | echo "ERROR:" |
---|
74 | echo "It appears as though you are not an administrator of the locker <$lname>." |
---|
75 | echo "Try running \"fs sa /mit/$lname $afsuser all\" and starting over." |
---|
76 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
77 | exit 1 |
---|
78 | fi |
---|
79 | |
---|
80 | mkdir -p "/mit/$lname/.scripts-signup" |
---|
81 | |
---|
82 | if [ ! -d "/mit/$lname/.scripts-signup" ]; then |
---|
83 | echo |
---|
84 | echo "ERROR:" |
---|
85 | echo "It appears as though you do not have write access to the locker <$lname>." |
---|
86 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
87 | exit 1 |
---|
88 | fi |
---|
89 | |
---|
90 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/$lname"` |
---|
91 | rmdir "/mit/$lname/.scripts-signup" |
---|
92 | |
---|
93 | if [ "$ans" != "done" ] && [ "$ans" != "username already taken" ]; then |
---|
94 | echo "ERROR:" |
---|
95 | echo "Signup reported the following error: \"$ans\"." |
---|
96 | echo "Contact scripts@mit.edu for assistance." |
---|
97 | exit 1 |
---|
98 | fi |
---|
99 | |
---|
100 | success() { |
---|
101 | if [ "$initlname" -eq 0 ]; then |
---|
102 | echo |
---|
103 | echo "== SUCCESS ==" |
---|
104 | echo "$lname is now signed up for $1." |
---|
105 | echo "$2" |
---|
106 | echo |
---|
107 | fi |
---|
108 | } |
---|