-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror.sh
executable file
·75 lines (59 loc) · 2.5 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash -e
#
# Universal mirroring repository tool.
#
# @package Bash
# @author Kai Kimera <[email protected]>
# @copyright 2023 Kai Kimera
# @license MIT
# @version 0.0.1
# @link https://github.com/ghastore
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
# CONFIGURATION.
# -------------------------------------------------------------------------------------------------------------------- #
# Vars.
SRC_REPO="${1}"
SRC_USER="${2}"
SRC_TOKEN="${3}"
DST_REPO="${4}"
DST_USER="${5}"
DST_TOKEN="${6}"
# Apps.
git="$( command -v git )"
# Dirs.
d_src="/root/git/src"
# -------------------------------------------------------------------------------------------------------------------- #
# INITIALIZATION.
# -------------------------------------------------------------------------------------------------------------------- #
init() {
mirror
}
# -------------------------------------------------------------------------------------------------------------------- #
# GIT: MIRROR.
# -------------------------------------------------------------------------------------------------------------------- #
mirror() {
echo "--- [GIT] CLONE: ${SRC_REPO#https://}"
local src="https://${SRC_USER}:${SRC_TOKEN}@${SRC_REPO#https://}"
local dst="https://${DST_USER}:${DST_TOKEN}@${DST_REPO#https://}"
${git} clone --mirror "${src}" "${d_src}" \
&& _pushd "${d_src}" || exit 1
${git} remote add 'dst' "${dst}"
${git} push -f --mirror 'dst'
_popd || exit 1
}
# -------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------< COMMON FUNCTIONS >------------------------------------------------ #
# -------------------------------------------------------------------------------------------------------------------- #
# Pushd.
_pushd() {
command pushd "$@" > /dev/null || exit 1
}
# Popd.
_popd() {
command popd > /dev/null || exit 1
}
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------< RUNNING SCRIPT >------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
init "$@"; exit 0