-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mirror.sh
executable file
·56 lines (44 loc) · 1.92 KB
/
mirror.sh
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
#!/bin/bash -e
# -------------------------------------------------------------------------------------------------------------------- #
# INITIALIZATION.
# -------------------------------------------------------------------------------------------------------------------- #
init() {
# Vars.
SOURCE_REPO="${1}"
SOURCE_USER="${2}"
SOURCE_TOKEN="${3}"
TARGET_REPO="${4}"
TARGET_USER="${5}"
TARGET_TOKEN="${6}"
# Apps.
git="$( command -v git )"
# Run.
mirror
}
# -------------------------------------------------------------------------------------------------------------------- #
# GIT: MIRROR.
# -------------------------------------------------------------------------------------------------------------------- #
mirror() {
SOURCE="https://${SOURCE_USER}:${SOURCE_TOKEN}@${SOURCE_REPO#https://}"
TARGET="https://${TARGET_USER}:${TARGET_TOKEN}@${TARGET_REPO#https://}"
${git} clone --mirror "${SOURCE}" '/root/git/source' \
&& _pushd '/root/git/source' || exit 1
${git} remote add 'target' "${TARGET}"
${git} push -f --mirror 'target'
_popd || exit 1
}
# -------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------< COMMON FUNCTIONS >------------------------------------------------ #
# -------------------------------------------------------------------------------------------------------------------- #
# Pushd.
_pushd() {
command pushd "$@" > /dev/null || exit 1
}
# Popd.
_popd() {
command popd > /dev/null || exit 1
}
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------< INIT FUNCTIONS >------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
init "$@"; exit 0