[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 |
---|
[733] | 27 | lname="${ATHENA_USER:-$USER}" |
---|
[458] | 28 | elif [ "$whofor" = 2 ]; then |
---|
[127] | 29 | echo |
---|
[458] | 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." |
---|
[127] | 32 | echo "(For the locker /mit/sipb, you would enter sipb)." |
---|
[733] | 33 | printf "Locker name: " |
---|
| 34 | read lname |
---|
[127] | 35 | else |
---|
| 36 | echo |
---|
[458] | 37 | echo "ERROR:" |
---|
| 38 | echo "You must select either '1' or '2'." |
---|
[127] | 39 | exit 1 |
---|
| 40 | fi |
---|
[733] | 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 |
---|
[127] | 49 | else |
---|
[733] | 50 | lname="$1" |
---|
[127] | 51 | fi |
---|
| 52 | fi |
---|
[733] | 53 | lroot="/mit/$lname" |
---|
[127] | 54 | |
---|
[726] | 55 | attach "$lname" 2>/dev/null |
---|
| 56 | |
---|
[629] | 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>." |
---|
[1429] | 62 | echo "This is probably because your locker is not publicly listable." |
---|
| 63 | echo "You can remedy this signup problem and make your locker publicly" |
---|
| 64 | echo "listable by running \"fs sa /mit/$lname system:anyuser l\" (with a" |
---|
[1430] | 65 | echo "lowercase L at the end)." |
---|
| 66 | echo "" |
---|
| 67 | echo "NOTE: This will make it possible for the public (including anyone" |
---|
| 68 | echo "viewing http://web.mit.edu/$lname) to see the names of your files" |
---|
| 69 | echo "and the list of people who have access to them, though it will not" |
---|
| 70 | echo "cause the contents of your files to be publicly readable. If you" |
---|
| 71 | echo "are unwilling to have your locker listable by the public, please" |
---|
| 72 | echo "contact scripts@mit.edu for information about other ways to work" |
---|
| 73 | echo "around the problem." |
---|
[629] | 74 | exit 1 |
---|
| 75 | fi |
---|
| 76 | |
---|
[576] | 77 | principal=`klist -5 | sed -n 's/^Default principal: // p'` |
---|
| 78 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/admof.php/$lname/$principal"` |
---|
| 79 | if [ "$ans" != "yes" ]; then |
---|
| 80 | afsuser=`echo "$principal" | sed 's/@ATHENA.MIT.EDU$//'` |
---|
| 81 | echo |
---|
| 82 | echo "ERROR:" |
---|
| 83 | echo "It appears as though you are not an administrator of the locker <$lname>." |
---|
| 84 | echo "Try running \"fs sa /mit/$lname $afsuser all\" and starting over." |
---|
| 85 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
| 86 | exit 1 |
---|
| 87 | fi |
---|
| 88 | |
---|
[660] | 89 | mkdir -p "/mit/$lname/.scripts-signup" |
---|
[127] | 90 | |
---|
| 91 | if [ ! -d "/mit/$lname/.scripts-signup" ]; then |
---|
| 92 | echo |
---|
[458] | 93 | echo "ERROR:" |
---|
| 94 | echo "It appears as though you do not have write access to the locker <$lname>." |
---|
| 95 | echo "Contact scripts@mit.edu if you are unable to solve the problem." |
---|
[502] | 96 | exit 1 |
---|
[127] | 97 | fi |
---|
| 98 | |
---|
[502] | 99 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/$lname"` |
---|
[458] | 100 | rmdir "/mit/$lname/.scripts-signup" |
---|
| 101 | |
---|
[776] | 102 | if [ "$ans" = "done" ]; then |
---|
| 103 | # nscd caches account nonexistence with a 5-second TTL. |
---|
| 104 | # (LDAP updates are more or less instant.) |
---|
| 105 | # Somehow, the server can wait up to 10 seconds... |
---|
| 106 | echo "Creating scripts.mit.edu account for $lname..." |
---|
| 107 | sleep 10 |
---|
| 108 | fi |
---|
| 109 | |
---|
[502] | 110 | if [ "$ans" != "done" ] && [ "$ans" != "username already taken" ]; then |
---|
| 111 | echo "ERROR:" |
---|
| 112 | echo "Signup reported the following error: \"$ans\"." |
---|
| 113 | echo "Contact scripts@mit.edu for assistance." |
---|
| 114 | exit 1 |
---|
| 115 | fi |
---|
| 116 | |
---|
[127] | 117 | success() { |
---|
| 118 | if [ "$initlname" -eq 0 ]; then |
---|
| 119 | echo |
---|
| 120 | echo "== SUCCESS ==" |
---|
[458] | 121 | echo "$lname is now signed up for $1." |
---|
| 122 | echo "$2" |
---|
[127] | 123 | echo |
---|
| 124 | fi |
---|
| 125 | } |
---|