[641] | 1 | #!/bin/bash |
---|
[127] | 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)." |
---|
[640] | 34 | while printf "Locker name: "; read lname; ! attach "$lname" 2>/dev/null; do |
---|
| 35 | echo "$lname is not a valid locker name." |
---|
| 36 | done |
---|
[127] | 37 | lroot="/mit/$lname" |
---|
| 38 | else |
---|
| 39 | echo |
---|
[458] | 40 | echo "ERROR:" |
---|
| 41 | echo "You must select either '1' or '2'." |
---|
[127] | 42 | exit 1 |
---|
| 43 | fi |
---|
| 44 | else |
---|
| 45 | lname=$1 |
---|
| 46 | fi |
---|
| 47 | fi |
---|
| 48 | |
---|
[629] | 49 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/fsla.php/mit/$lname"` |
---|
| 50 | if [ "$ans" != "0" ]; then |
---|
| 51 | echo |
---|
| 52 | echo "ERROR:" |
---|
| 53 | echo "The scripts servers cannot verify the permissions of the locker <$lname>." |
---|
| 54 | echo "Try running \"fs sa /mit/$lname daemon.scripts l\" (with a lowercase" |
---|
| 55 | echo "L at the end) and then try again. Contact scripts@mit.edu if you are" |
---|
| 56 | echo "unable to solve the problem." |
---|
| 57 | exit 1 |
---|
| 58 | fi |
---|
| 59 | |
---|
[576] | 60 | principal=`klist -5 | sed -n 's/^Default principal: // p'` |
---|
| 61 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/admof.php/$lname/$principal"` |
---|
| 62 | if [ "$ans" != "yes" ]; then |
---|
| 63 | afsuser=`echo "$principal" | sed 's/@ATHENA.MIT.EDU$//'` |
---|
| 64 | echo |
---|
| 65 | echo "ERROR:" |
---|
| 66 | echo "It appears as though you are not an administrator of the locker <$lname>." |
---|
| 67 | echo "Try running \"fs sa /mit/$lname $afsuser all\" and starting over." |
---|
| 68 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
| 69 | exit 1 |
---|
| 70 | fi |
---|
| 71 | |
---|
[458] | 72 | mkdir "/mit/$lname/.scripts-signup" 2>/dev/null |
---|
[127] | 73 | |
---|
| 74 | if [ ! -d "/mit/$lname/.scripts-signup" ]; then |
---|
| 75 | echo |
---|
[458] | 76 | echo "ERROR:" |
---|
| 77 | echo "It appears as though you do not have write access to the locker <$lname>." |
---|
| 78 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
[502] | 79 | exit 1 |
---|
[127] | 80 | fi |
---|
| 81 | |
---|
[502] | 82 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/$lname"` |
---|
[458] | 83 | rmdir "/mit/$lname/.scripts-signup" |
---|
| 84 | |
---|
[502] | 85 | if [ "$ans" != "done" ] && [ "$ans" != "username already taken" ]; then |
---|
| 86 | echo "ERROR:" |
---|
| 87 | echo "Signup reported the following error: \"$ans\"." |
---|
| 88 | echo "Contact scripts@mit.edu for assistance." |
---|
| 89 | exit 1 |
---|
| 90 | fi |
---|
| 91 | |
---|
[127] | 92 | success() { |
---|
| 93 | if [ "$initlname" -eq 0 ]; then |
---|
| 94 | echo |
---|
| 95 | echo "== SUCCESS ==" |
---|
[458] | 96 | echo "$lname is now signed up for $1." |
---|
| 97 | echo "$2" |
---|
[127] | 98 | echo |
---|
| 99 | fi |
---|
| 100 | } |
---|