-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgitlab-remote-mirror.sh
More file actions
executable file
·110 lines (83 loc) · 2.4 KB
/
Copy pathgitlab-remote-mirror.sh
File metadata and controls
executable file
·110 lines (83 loc) · 2.4 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
BASEDIR=$(pwd)
CONFIG_DIR="${BASEDIR}/repositories.d"
for filename in $CONFIG_DIR/*.cnf; do
if [ -f $filename ]; then
echo "Loading ${filename}..."
# Reset config
TARGET_URL=""
SOURCE_PATH=""
LFS=0
GITLAB_LFS_OBJECTS_PATH=""
cd "${BASEDIR}"
# Load config file
source $filename
if [ -z "${TARGET_URL}" ]; then
echo "Error! TARGET_URL is not set in the configuration file." 1>&2
exit 1
fi
if [ -z "${SOURCE_PATH}" ]; then
echo "Error! SOURCE_PATH is not set in the configuration file." 1>&2
exit 1
fi
if [ ! -d "${SOURCE_PATH}" ]; then
echo "Error! '${SOURCE_PATH}' directory does not exists." 1>&2
exit 1
fi
if [ ! -f "${SOURCE_PATH}/HEAD" ]; then
echo "Error! '${SOURCE_PATH}' is not a bare git repository." 1>&2
exit 1
fi
echo "Pushing changes to the remote repository..."
cd "${SOURCE_PATH}"
git push --all "${TARGET_URL}"
if [ $? -ne 0 ] ; then
echo "Error! Command failed." 1>&2
exit 1
fi
echo "Done pushing changes to the remote repository."
if [ $LFS -eq 1 ] ; then
if [ ! -z "${GITLAB_LFS_OBJECTS_PATH}" ]; then
echo "Creating Git LFS compatible links to the GitLab LFS storage..."
for IOD1 in $GITLAB_LFS_OBJECTS_PATH/*; do
if [ -d "${IOD1}" ]; then
for IOD2 in $IOD1/*; do
if [ -d "${IOD2}" ]; then
for IOD3 in $IOD2/*; do
if [ -f "${IOD3}" ]; then
GITLAB_OID_PATH="$GITLAB_LFS_OBJECTS_PATH/${IOD1##*/}/${IOD2##*/}/${IOD3##*/}"
if [ ! -f "${GITLAB_OID_PATH}" ]; then
echo "Error! Can not find LFS object file at '${GITLAB_OID_PATH}'." 1>&2
exit 1
fi
LOCAL_OID_DIR="${SOURCE_PATH}/lfs/objects/${IOD1##*/}/${IOD2##*/}"
mkdir -p "${LOCAL_OID_DIR}"
if [ $? -ne 0 ] ; then
echo "Error! Command failed." 1>&2
exit 1
fi
LOCAL_OID_PATH="${LOCAL_OID_DIR}/${IOD1##*/}${IOD2##*/}${IOD3##*/}"
ln -s -f "${GITLAB_OID_PATH}" "${LOCAL_OID_PATH}"
if [ $? -ne 0 ] ; then
echo "Error! Command failed." 1>&2
exit 1
fi
fi
done
fi
done
fi
done
fi
echo "Pushing Git LFS changes..."
git lfs push --all "${TARGET_URL}"
if [ $? -ne 0 ] ; then
echo "Error! Command failed." 1>&2
exit 1
fi
echo "Done pushing Git LFS changes."
fi
fi
done
echo "All done."
exit 0