-
Notifications
You must be signed in to change notification settings - Fork 0
/
handin-prep
executable file
·60 lines (53 loc) · 1.63 KB
/
handin-prep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
KEYFILE="$HOME/.ssh/id_rsa"
BASE_URL="https://pdos.csail.mit.edu/6.828/submit/"
PK_URL="$BASE_URL""setpubkey"
SSH_HOST="[email protected]"
GIT_URL="ssh://$SSH_HOST/joslab.git"
REPO="handin"
# generate key pairs if not exist
if ! test -r "$KEYFILE"; then
read -p "SSH key file $KEYFILE does not exist, generate one? [Y/n]" r
test "$r" = y -o "$r" = Y -o -z "$r" || exit 0
mkdir -p "`dirname $KEYFILE`"
if ! ssh-keygen -t rsa -N '' -C '' -f "$KEYFILE"; then
echo "$0: cannot generate key pairs"
exit 1
fi
fi
# retrieve and display public key
pubkey=$(ssh-keygen -y -f "$KEYFILE")
if test -z "$pubkey"; then
echo "$0: cannot retrieve public key from $KEYFILE"
exit 1
fi
echo "Using public key from $KEYFILE:"
echo "$pubkey"
read -p "Continue? [Y/n]" r
test "$r" = y -o "$r" = Y -o -z "$r" || exit 0
# login to server
echo
echo "Login to 6.828 submission website."
echo "If you do not have an account yet, sign up at $BASE_URL"
echo "before continuing."
read -p "Username ($USER): " username
test -n "$username" || username="$USER"
test -n "$username" || exit 0
stty -echo
read -p "Password: " password
stty echo
test -n "$password" || exit 0
echo
resp=$(curl -sSk -F "u=$username" -F "p=$password" -F "k=$pubkey" "$PK_URL")
if test "$resp" != "OK"; then
test -z "$resp" || echo "$resp"
exit 1
fi
echo "Your public key has been successfully updated."
# config git
echo "Setting up hand-in Git repository..."
echo "Adding remote repository $GIT_URL as '$REPO'."
git remote rm "$REPO" 2> /dev/null
git remote add "$REPO" "$GIT_URL" || exit 1
echo "Done! Use 'make handin' to submit your lab code."
echo