blob: 2a488d3677e1cc6cd21b6ea657cf2591f74d9433 (
plain)
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
|
#!/bin/sh
set -e
# mirror [REPO] to [URL] - set up hourly push mirror
# mirror [REPO] from [URL] - set up hourly fetch mirror
# mirror [REPO] delete - remove any mirror
_usage() {
echo "Usage:"
echo " mirror [REPO] to [URL] set up hourly push mirror"
echo " mirror [REPO] from [URL] set up hourly fetch mirror"
echo " mirror [REPO] delete remove any mirror"
exit "${1:-0}"
}
[ -z "$1" ] && _usage
[ -z "$2" ] && _usage
REPO="$1"
CMD="$2"
ARG="$3"
REPO_PATH="$HOME/$REPO.git"
if [ ! -d "$REPO_PATH" ]; then
echo "Repository $REPO does not exist"
exit 1
fi
cd "$REPO_PATH" || exit 1
case "$CMD" in
to)
[ -z "$ARG" ] && _usage 1
if git remote get-url mirror-from >/dev/null 2>&1; then
echo "Error: $REPO already has a mirror-from. Remove it first with: mirror $REPO delete"
exit 1
fi
if git remote get-url mirror-to >/dev/null 2>&1; then
git remote set-url mirror-to "$ARG"
else
git remote add mirror-to "$ARG"
fi
echo "Configured $REPO to mirror to $ARG"
echo "Runs hourly. Logs: /var/log/git-mirrors.log"
;;
from)
[ -z "$ARG" ] && _usage 1
if git remote get-url mirror-to >/dev/null 2>&1; then
echo "Error: $REPO already has a mirror-to. Remove it first with: mirror $REPO delete"
exit 1
fi
if git remote get-url mirror-from >/dev/null 2>&1; then
git remote set-url mirror-from "$ARG"
else
git remote add mirror-from "$ARG"
fi
echo "Configured $REPO to mirror from $ARG"
echo "Runs hourly. Logs: /var/log/git-mirrors.log"
;;
delete)
removed=0
if git remote get-url mirror-to >/dev/null 2>&1; then
git remote remove mirror-to
echo "Removed mirror-to for $REPO"
removed=1
fi
if git remote get-url mirror-from >/dev/null 2>&1; then
git remote remove mirror-from
echo "Removed mirror-from for $REPO"
removed=1
fi
[ "$removed" -eq 0 ] && echo "No mirror configured for $REPO"
;;
*)
_usage 1
;;
esac
|