Browse Source

implement functions allowing to easily mirror repository; actually only git supported

belliash 7 years ago
parent
commit
9c4cce0f4e
1 changed files with 34 additions and 0 deletions
  1. 34
    0
      libraries/repositories

+ 34
- 0
libraries/repositories View File

@@ -3,6 +3,40 @@
3 3
 # Distributed under the terms of the GNU General Public License v3
4 4
 
5 5
 
6
+#-------------------------------------------------------------------------------
7
+# Creates a local mirror of specified GIT repository
8
+# Parameters: %dest_directory% %address% [%username%]
9
+#-------------------------------------------------------------------------------
10
+function mirrorGit() {
11
+	local DIRECTORY="${1}"
12
+	local ADDRESS="${2}"
13
+	local USER="${3:-root}"
14
+	if [ -d ${DIRECTORY} ]; then
15
+		cd ${DIRECTORY}
16
+		run "su ${USER} -s \"/bin/sh\" -c \"git fetch -all\"" || return 1
17
+	else
18
+		run "su ${USER} -s \"/bin/sh\" -c \"git clone --mirror --bare \
19
+			${ADDRESS} ${DIRECTORY}\"" || return 1
20
+	fi
21
+	return 0
22
+}
23
+
24
+#-------------------------------------------------------------------------------
25
+# Creates a local mirror of specified repository regardless its protocol
26
+# Parameters: %dest_directory% %protocol% %address% [%username%]
27
+#-------------------------------------------------------------------------------
28
+function mirrorRepository() {
29
+	case "${2}" in
30
+		[Gg][Ii][Tt])
31
+			mirrorGit "${1}" "${3}" "${4}" && return 0
32
+			;;
33
+		*)
34
+			printWarn "Tried to mirror data using unsupported protocol (${2})!"
35
+			;;
36
+	esac
37
+	return 1
38
+}
39
+
6 40
 #-------------------------------------------------------------------------------
7 41
 # Prepares SSH Wrappers for use with unknown hosts (requires key authentication)
8 42
 #-------------------------------------------------------------------------------

Loading…
Cancel
Save