-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcheckoutshard
executable file
·102 lines (87 loc) · 2.49 KB
/
checkoutshard
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
set -e
shard="$1"
if [ -z "$shard" ]; then
echo "Usage: checkoutshard shardN" >&2
exit 1
fi
SHARD="$(echo "$shard" | tr a-z A-Z)"
if [ -d "$shard" ]; then
echo "$shard already checked out"
exit 0
fi
case "$(uname)" in
Darwin)
PATH=$(pwd)/git-annex.osx:$PATH
;;
*)
PATH=$(pwd)/git-annex.linux:$PATH
;;
esac
export PATH
. ./locks.sh
top="$(pwd)"
prevshard="$(echo shard* 2>/dev/null | cut -d ' ' -f 1)"
if [ ! -e .registrationemail ]; then
#./prompt-email
# we have some older shards w/o emails, collect those
./change-email
fi
registrationemail="$(cat .registrationemail)"
checkssh () {
repourl="$1"
uuid="$2"
delay="$3"
if [ ! -e id_rsa ]; then
ssh-keygen -q -P "" -t rsa -f ./id_rsa
# we expect ssh-keygen to do this for us, but not every version does, it seems.
chmod go-rwx id_rsa
chmod go-wx id_rsa.pub
fi
user="$(echo "$repourl" | cut -d : -f 1)"
dir="$(echo "$repourl" | cut -d : -f 2)"
echo "Checking ssh to server at $repourl..."
if ! ssh -i id_rsa -o BatchMode=yes -o StrictHostKeyChecking=no "$user" git-annex-shell -c configlist "$dir"; then
echo "Seem you're not set up yet for access to $repourl yet. Let's fix that.."
wget -O- "$(./register-helper.pl "$SHARD" "$uuid" "$registrationemail" "$(cat id_rsa.pub)")"
sleep 1
wget -q -O- http://iabak.archiveteam.org/cgi-bin/pushme.cgi >/dev/null 2>&1 || true
sleep "$delay"
checkssh "$repourl" "$uuid" "$(($delay * 2))"
fi
}
l=$(grep -i "^$shard " repolist)
if [ -z "$l" ]; then
echo "Shard not found in repolist" >&2
exit 1
fi
set -- $l
localdir="$1"
repourl="$2"
status="$3"
# This is slightly weird way to clone, but it allows using our
# dedicated ssh key without installing it in ~/.ssh/
${GIT} init "$localdir"
cd "$localdir"
${GIT} config user.name "$(whoami)"
${GIT} config user.email "$(whoami)@iabak"
${GIT} config gc.auto 0
${GITANNEX} init
uuid="$(git config annex.uuid)"
(cd .. && checkssh "$repourl" "$uuid" 2)
cp -a ../id_rsa .git/annex/id_rsa
cp -a ../id_rsa.pub .git/annex/id_rsa.pub
${GIT} remote add origin "$repourl"
${GIT} config remote.origin.annex-ssh-options "-i .git/annex/id_rsa"
${GIT} annex sync
# Copy over any user configuration from a previous shard.
cd "$top"
if [ -n "$prevshard" ] && [ -d "$prevshard" ]; then
for c in annex.diskreserve annex.web-options; do
val="$(cd "$prevshard" && git config "$c" || true)"
if [ -n "$val" ]; then
(cd "$localdir" && ${GIT} config "$c" "$val")
fi
done
fi
echo "Checked out $localdir for $shard (from $repourl). Current status: $status"