-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd-repository
executable file
·81 lines (71 loc) · 2.06 KB
/
add-repository
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
#!/bin/bash
# Add a repository using standard cvmfs_server commands
ME="`basename $0`"
usage()
{
echo "Usage: $ME [-p] reponame {http_url_of_repo_server|continue}" >&2
echo ' If the last parameter is "continue", only run snapshot on repo' >&2
echo ' If [-p] is given, pass it to cvmfs_server add-replica' >&2
exit 1
}
ADDREPARGS=""
case "$1" in
-p) ADDREPARGS="$1"; shift;;
-*) echo "Unrecognized option $1" >&2; usage;;
esac
if [ $# != 2 ]; then
usage
fi
CREATEREPO=true
REPONAME="$1"
REPOURL=""
case "$2" in
http*://*) REPOURL="$2/cvmfs/$REPONAME";;
continue) CREATEREPO=false;;
*) usage ;;
esac
set -e
if $CREATEREPO; then
# create the replica
if [ -f /etc/cvmfs/repositories.d/$REPONAME/replica.conf ]; then
echo "Repository already exists, aborting" >&2
exit 1
fi
DOMAIN=${REPONAME#*.}
PUBKEY="/etc/cvmfs/keys/$DOMAIN.pub"
if [ ! -f "$PUBKEY" ]; then
PUBDIR="/etc/cvmfs/keys/$DOMAIN"
if [ -d "$PUBDIR" ]; then
PUBKEY="`echo $PUBDIR/*.pub|tr ' ' ':'`"
else
echo "$ME: $PUBKEY and $PUBDIR not found" >&2
exit 1
fi
fi
if [ -d /srv/cvmfs/$REPONAME ]; then
echo "Saving old /srv/cvmfs/$REPONAME data" >&2
if [ -d /srv/cvmfs/.$REPONAME.save ]; then
echo " ... but saved data already existed, aborting" >&2
exit 1
fi
mv /srv/cvmfs/$REPONAME /srv/cvmfs/.$REPONAME.save
fi
RET=0
if ! cvmfs_server add-replica $ADDREPARGS -o root $REPOURL $PUBKEY$EXTRAPUBKEY; then
RET=1
fi
if [ -d /srv/cvmfs/.$REPONAME.save ]; then
echo "Restoring old /srv/cvmfs/$REPONAME data" >&2
rm -rf /srv/cvmfs/$REPONAME
mv /srv/cvmfs/.$REPONAME.save /srv/cvmfs/$REPONAME
if [ -f /srv/cvmfs/$REPONAME/.cvmfsreflog ]; then
echo "Removing ${REPONAME}'s .cvmfsreflog" >&2
rm /srv/cvmfs/$REPONAME/.cvmfsreflog
fi
fi
if [ $RET != 0 ]; then
exit $RET
fi
fi
# pull initial snapshot
cvmfs_server snapshot $REPONAME