-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmirror.sh
More file actions
executable file
·57 lines (46 loc) · 2.1 KB
/
Copy pathmirror.sh
File metadata and controls
executable file
·57 lines (46 loc) · 2.1 KB
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
#!/bin/bash
# -------------------------------------------------------------------------------------------------------------------- #
# UNIVERSAL MIRRORING REPOSITORY TOOL
# -------------------------------------------------------------------------------------------------------------------- #
# @package Bash
# @author Kai Kimera
# @license MIT
# @version 0.1.0
# @link https://github.com/ghastore
# -------------------------------------------------------------------------------------------------------------------- #
set -euo pipefail; (( EUID != 0 )) && { echo >&2 'This script should be run as root!'; exit 1; }
# -------------------------------------------------------------------------------------------------------------------- #
# CONFIGURATION
# -------------------------------------------------------------------------------------------------------------------- #
# Parameters.
SRC_REPO="${1:?}"; readonly SRC_REPO
SRC_USER="${2:?}"; readonly SRC_USER
SRC_TOKEN="${3:?}"; readonly SRC_TOKEN
DST_REPO="${4:?}"; readonly DST_REPO
DST_USER="${5:?}"; readonly DST_USER
DST_TOKEN="${6:?}"; readonly DST_TOKEN
# Variables.
d_src='/root/git/src'
# -------------------------------------------------------------------------------------------------------------------- #
# -----------------------------------------------------< SCRIPT >----------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
function _pushd() {
command pushd "$@" > '/dev/null' || exit 1
}
function _popd() {
command popd > '/dev/null' || exit 1
}
function _title() {
local title; title="${1}"
echo '' && echo "${title}" && echo ''
}
function mirror() {
_title "--- [GIT] CLONE: ${SRC_REPO#https://}"
local src; src="https://${SRC_USER}:${SRC_TOKEN}@${SRC_REPO#https://}"
local dst; dst="https://${DST_USER}:${DST_TOKEN}@${DST_REPO#https://}"
git clone --mirror "${src}" "${d_src}" && _pushd "${d_src}" \
&& git remote add 'dst' "${dst}" && git push -f --mirror 'dst' && _popd
}
function main() {
mirror
}; main "$@"