[127] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | if [ "$initlname" = "" ]; then |
---|
| 4 | if [ "$lname" = "" ]; then |
---|
| 5 | initlname=0 |
---|
| 6 | else |
---|
| 7 | initlname=1 |
---|
| 8 | fi |
---|
| 9 | fi |
---|
| 10 | |
---|
[575] | 11 | if type wget >/dev/null 2>/dev/null; then |
---|
| 12 | WGET=wget |
---|
| 13 | else |
---|
| 14 | WGET="athrun gnu wget" |
---|
| 15 | fi |
---|
| 16 | |
---|
[127] | 17 | if [ "$lname" = "" ]; then |
---|
| 18 | if [ "$1" = "" ]; then |
---|
| 19 | echo |
---|
[458] | 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'." |
---|
[127] | 24 | printf "Please enter either '1' or '2' (without quotes): " |
---|
| 25 | read whofor |
---|
[458] | 26 | if [ "$whofor" = 1 ]; then |
---|
[127] | 27 | lname=$USER |
---|
| 28 | lroot=$HOME |
---|
[458] | 29 | elif [ "$whofor" = 2 ]; then |
---|
[127] | 30 | echo |
---|
[458] | 31 | echo "OK. A locker of your choice that you control will be signed up." |
---|
| 32 | echo "Please enter the name of the selected locker below." |
---|
[127] | 33 | echo "(For the locker /mit/sipb, you would enter sipb)." |
---|
| 34 | printf "Locker name: " |
---|
| 35 | read lname |
---|
| 36 | lroot="/mit/$lname" |
---|
| 37 | else |
---|
| 38 | echo |
---|
[458] | 39 | echo "ERROR:" |
---|
| 40 | echo "You must select either '1' or '2'." |
---|
[127] | 41 | exit 1 |
---|
| 42 | fi |
---|
| 43 | else |
---|
| 44 | lname=$1 |
---|
| 45 | fi |
---|
| 46 | fi |
---|
| 47 | |
---|
[458] | 48 | attach "$lname" 2>/dev/null |
---|
[127] | 49 | |
---|
| 50 | if [ "$lname" != "$USER" ]; then |
---|
[575] | 51 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/admof.php/$lname/$USER@ATHENA.MIT.EDU"` |
---|
[127] | 52 | if [ "$ans" != "yes" ]; then |
---|
| 53 | echo |
---|
[458] | 54 | echo "ERROR:" |
---|
| 55 | echo "It appears as though you are not an administrator of the locker <$lname>." |
---|
| 56 | echo "Try running \"fs sa /mit/$lname $USER all\" and starting over." |
---|
| 57 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
[502] | 58 | exit 1 |
---|
[127] | 59 | fi |
---|
| 60 | fi |
---|
| 61 | |
---|
[458] | 62 | attach "$lname" 2>/dev/null |
---|
[127] | 63 | |
---|
| 64 | if [ ! -d "/mit/$lname" ]; then |
---|
| 65 | echo |
---|
[458] | 66 | echo "ERROR:" |
---|
| 67 | echo "Cannot find locker <$lname>." |
---|
[502] | 68 | exit 1 |
---|
[127] | 69 | fi |
---|
| 70 | |
---|
[458] | 71 | ans=`fs la "/mit/$lname" | grep '^ system:a[nyuth]*user .*l'` |
---|
| 72 | if [ -z "$ans" ]; then |
---|
[184] | 73 | echo |
---|
[458] | 74 | echo "ERROR:" |
---|
| 75 | echo "It appears as though the locker <$lname> is not listable by system:anyuser." |
---|
| 76 | echo "You might want to run \"fs sa /mit/$lname system:anyuser l\"" |
---|
| 77 | echo "(that's a lowercase L rather than a one) and then try again." |
---|
| 78 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
[502] | 79 | exit 1 |
---|
[184] | 80 | fi |
---|
| 81 | |
---|
[458] | 82 | mkdir "/mit/$lname/.scripts-signup" 2>/dev/null |
---|
[127] | 83 | |
---|
| 84 | if [ ! -d "/mit/$lname/.scripts-signup" ]; then |
---|
| 85 | echo |
---|
[458] | 86 | echo "ERROR:" |
---|
| 87 | echo "It appears as though you do not have write access to the locker <$lname>." |
---|
| 88 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
[502] | 89 | exit 1 |
---|
[127] | 90 | fi |
---|
| 91 | |
---|
[502] | 92 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/$lname"` |
---|
[458] | 93 | rmdir "/mit/$lname/.scripts-signup" |
---|
| 94 | |
---|
[502] | 95 | if [ "$ans" != "done" ] && [ "$ans" != "username already taken" ]; then |
---|
| 96 | echo "ERROR:" |
---|
| 97 | echo "Signup reported the following error: \"$ans\"." |
---|
| 98 | echo "Contact scripts@mit.edu for assistance." |
---|
| 99 | exit 1 |
---|
| 100 | fi |
---|
| 101 | |
---|
[127] | 102 | success() { |
---|
| 103 | if [ "$initlname" -eq 0 ]; then |
---|
| 104 | echo |
---|
| 105 | echo "== SUCCESS ==" |
---|
[458] | 106 | echo "$lname is now signed up for $1." |
---|
| 107 | echo "$2" |
---|
[127] | 108 | echo |
---|
| 109 | fi |
---|
| 110 | } |
---|