Browse Source

implement snapshotPortage()

master
belliash 7 years ago
parent
commit
25c2c398bb
1 changed files with 53 additions and 0 deletions
  1. 53
    0
      libraries/repositories

+ 53
- 0
libraries/repositories View File

@@ -314,3 +314,56 @@ function pushRepository() {
314 314
 	esac
315 315
 	return 1
316 316
 }
317
+
318
+#-------------------------------------------------------------------------------
319
+# Downloads Portage tree ready t ouse at production and creates a snapshot
320
+# Parameters: %address% %protocol%
321
+#-------------------------------------------------------------------------------
322
+function snapshotPortage() {
323
+	local SOURCE="${1}"
324
+	local TARBALL="portage-$(date +${TARBALLDATE}).tar.${TARBALLFORMAT}"
325
+	if [ ! -d ${SNAPSHOTSDIR} ]; then
326
+		makeDirectory ${SNAPSHOTSDIR} || return 1
327
+	elif [ ! -f ${SNAPSHOTSDIR}/${TARBALL} ]; then
328
+		rm -rf "${TEMPDIR}/portage"
329
+		case ${2} in
330
+			[Gg][Ii][Tt])
331
+				originGitPortage ${TEMPDIR}/portage ${SOURCE} || return 1
332
+				;;
333
+			[Rr][Ss][Yy][Nn][Cc])
334
+				originRsyncPortage ${TEMPDIR}/portage ${SOURCE} || return 1
335
+				;;
336
+			*)
337
+				printWarn "Tried to pull data using unsupported protocol (${2})!"
338
+				return 1
339
+				;;
340
+		esac
341
+		TARBALL=${TARBALL%.*}
342
+		run "tar -c -C ${TEMPDIR} portage > ${SNAPSHOTSDIR}/${TARBALL}"
343
+		if [ ${?} -ne 0 ]; then
344
+			rm -f ${SNAPSHOTSDIR}/${TARBALL}
345
+			return 1
346
+		fi
347
+		case ${TARBALLFORMAT} in
348
+			bz2)
349
+				if [ -e /usr/bin/pbzip2 ]; then
350
+					run "pbzip2 -p${MAXJOBS} ${SNAPSHOTSDIR}/${TARBALL}"
351
+				else
352
+					run "bzip2 ${SNAPSHOTSDIR}/${TARBALL}"
353
+				fi
354
+				;;
355
+			gz)
356
+				run "gzip -9 ${SNAPSHOTSDIR}/${TARBALL}"
357
+				;;
358
+			xz)
359
+				run "xz ${SNAPSHOTSDIR}/${TARBALL}"
360
+				;;
361
+		esac
362
+		if [ ${?} -ne 0 ]; then
363
+			rm -f ${SNAPSHOTSDIR}/${TARBALL}
364
+			rm -f ${SNAPSHOTSDIR}/${TARBALL}.${TARBALLFORMAT}
365
+			return 1
366
+		fi
367
+	fi
368
+	return 0
369
+}

Loading…
Cancel
Save