| 1 | #!/bin/bash | 
|---|
| 2 |  | 
|---|
| 3 | if false; then | 
|---|
| 4 | echo "Scripts signups are temporarily unavailable.  Please" | 
|---|
| 5 | echo "check back later." | 
|---|
| 6 | exit 1 | 
|---|
| 7 | fi | 
|---|
| 8 |  | 
|---|
| 9 | if [ "$initlname" = "" ]; then | 
|---|
| 10 | if [ "$lname" = "" ]; then | 
|---|
| 11 | initlname=0 | 
|---|
| 12 | else | 
|---|
| 13 | initlname=1 | 
|---|
| 14 | fi | 
|---|
| 15 | fi | 
|---|
| 16 |  | 
|---|
| 17 | if type wget >/dev/null 2>/dev/null; then | 
|---|
| 18 | WGET=wget | 
|---|
| 19 | else | 
|---|
| 20 | WGET="athrun gnu wget" | 
|---|
| 21 | fi | 
|---|
| 22 |  | 
|---|
| 23 | if [ "$lname" = "" ]; then | 
|---|
| 24 | if [ "$1" = "" ]; then | 
|---|
| 25 | echo | 
|---|
| 26 | echo "Would you like to sign up:" | 
|---|
| 27 | echo "1. Your personal Athena account" | 
|---|
| 28 | echo "2. A locker that you control (a club, a course, etc)" | 
|---|
| 29 | echo "If you do not understand this question, you should answer '1'." | 
|---|
| 30 | printf "Please enter either '1' or '2' (without quotes): " | 
|---|
| 31 | read whofor | 
|---|
| 32 | if [ "$whofor" = 1 ]; then | 
|---|
| 33 | lname="${ATHENA_USER:-$USER}" | 
|---|
| 34 | elif [ "$whofor" = 2 ]; then | 
|---|
| 35 | echo | 
|---|
| 36 | echo "OK.  A locker of your choice that you control will be signed up." | 
|---|
| 37 | echo "Please enter the name of the selected locker below." | 
|---|
| 38 | echo "(For the locker /mit/sipb, you would enter sipb)." | 
|---|
| 39 | printf "Locker name: " | 
|---|
| 40 | read lname | 
|---|
| 41 | else | 
|---|
| 42 | echo | 
|---|
| 43 | echo "ERROR:" | 
|---|
| 44 | echo "You must select either '1' or '2'." | 
|---|
| 45 | exit 1 | 
|---|
| 46 | fi | 
|---|
| 47 | while true; do | 
|---|
| 48 | if attach "$lname"; then | 
|---|
| 49 | break | 
|---|
| 50 | fi | 
|---|
| 51 | echo "$lname is not a valid locker name." | 
|---|
| 52 | printf "Locker name: " | 
|---|
| 53 | read lname | 
|---|
| 54 | done | 
|---|
| 55 | else | 
|---|
| 56 | lname="$1" | 
|---|
| 57 | fi | 
|---|
| 58 | fi | 
|---|
| 59 | lroot="/mit/$lname" | 
|---|
| 60 |  | 
|---|
| 61 | attach "$lname" 2>/dev/null | 
|---|
| 62 |  | 
|---|
| 63 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/fsla.php/mit/$lname"` | 
|---|
| 64 | if [ "$ans" != "0" ]; then | 
|---|
| 65 | echo | 
|---|
| 66 | echo "ERROR:" | 
|---|
| 67 | echo "The scripts servers cannot verify the permissions of the locker <$lname>." | 
|---|
| 68 | echo "This is probably because your locker is not publicly listable." | 
|---|
| 69 | echo "You can remedy this signup problem and make your locker publicly" | 
|---|
| 70 | echo "listable by running \"fs setacl /mit/$lname system:anyuser l\"" | 
|---|
| 71 | echo "(that's a lowercase L at the end)." | 
|---|
| 72 | echo "" | 
|---|
| 73 | echo "NOTE: This will make it possible for the public (including anyone" | 
|---|
| 74 | echo "viewing http://web.mit.edu/$lname) to see the names of your files" | 
|---|
| 75 | echo "and the list of people who have access to them, though it will not" | 
|---|
| 76 | echo "cause the contents of your files to be publicly readable.  If you" | 
|---|
| 77 | echo "are unwilling to have your locker listable by the public, please" | 
|---|
| 78 | echo "contact scripts@mit.edu for information about other ways to work" | 
|---|
| 79 | echo "around the problem, or see http://scripts.mit.edu/faq/122 for more" | 
|---|
| 80 | echo "detailed information." | 
|---|
| 81 | exit 1 | 
|---|
| 82 | fi | 
|---|
| 83 |  | 
|---|
| 84 | principal=`klist -5 | sed -n 's/^Default principal: // p'` | 
|---|
| 85 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/admof.php/$lname/$principal"` | 
|---|
| 86 | if [ "$ans" != "yes" ]; then | 
|---|
| 87 | afsuser=`echo "$principal" | sed 's/@ATHENA.MIT.EDU$//'` | 
|---|
| 88 | echo | 
|---|
| 89 | echo "ERROR:" | 
|---|
| 90 | echo "It appears as though you are not an administrator of the locker <$lname>." | 
|---|
| 91 | echo "Try running \"fs setacl /mit/$lname $afsuser all\" and starting over." | 
|---|
| 92 | echo "Contact scripts@mit.edu if you are unable to solve the problem." | 
|---|
| 93 | exit 1 | 
|---|
| 94 | fi | 
|---|
| 95 |  | 
|---|
| 96 | mkdir -p "/mit/$lname/.scripts-signup" | 
|---|
| 97 |  | 
|---|
| 98 | if [ ! -d "/mit/$lname/.scripts-signup" ]; then | 
|---|
| 99 | echo | 
|---|
| 100 | echo "ERROR:" | 
|---|
| 101 | echo "It appears as though you do not have write access to the locker <$lname>." | 
|---|
| 102 | echo "Contact scripts@mit.edu if you are unable to solve the problem." | 
|---|
| 103 | exit 1 | 
|---|
| 104 | fi | 
|---|
| 105 |  | 
|---|
| 106 | ans=`$WGET -q -O- "http://scripts.mit.edu/~signup/$lname"` | 
|---|
| 107 | rmdir "/mit/$lname/.scripts-signup" | 
|---|
| 108 |  | 
|---|
| 109 | if [ "$ans" = "done" ]; then | 
|---|
| 110 | # nscd caches account nonexistence with a 5-second TTL. | 
|---|
| 111 | # (LDAP updates are more or less instant.) | 
|---|
| 112 | # Somehow, the server can wait up to 10 seconds... | 
|---|
| 113 | echo "Creating scripts.mit.edu account for $lname..." | 
|---|
| 114 | sleep 10 | 
|---|
| 115 | fi | 
|---|
| 116 |  | 
|---|
| 117 | if [ "$ans" != "done" ] && [ "$ans" != "username already taken" ]; then | 
|---|
| 118 | echo "ERROR:" | 
|---|
| 119 | echo "Signup reported the following error: \"$ans\"." | 
|---|
| 120 | echo "Contact scripts@mit.edu for assistance." | 
|---|
| 121 | exit 1 | 
|---|
| 122 | fi | 
|---|
| 123 |  | 
|---|
| 124 | success() { | 
|---|
| 125 | if [ "$initlname" -eq 0 ]; then | 
|---|
| 126 | echo | 
|---|
| 127 | echo "== SUCCESS ==" | 
|---|
| 128 | echo "$lname is now signed up for $1." | 
|---|
| 129 | echo "$2" | 
|---|
| 130 | echo | 
|---|
| 131 | fi | 
|---|
| 132 | } | 
|---|