about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--core/scripts/backup-ports.sh152
-rw-r--r--core/scripts/restore-ports.sh53
2 files changed, 136 insertions, 69 deletions
diff --git a/core/scripts/backup-ports.sh b/core/scripts/backup-ports.sh
index 46fd4c6..b5667e4 100644
--- a/core/scripts/backup-ports.sh
+++ b/core/scripts/backup-ports.sh
@@ -19,72 +19,86 @@ read BUILD_VERSION
 mkdir -p ${DEST_SYS}
 mkdir -p ${DEST_ARC}
 
-echo "${BUILD_NAME}-${BUILD_VERSION}" >> ${DEST_SYS}/build_version
-
-# archive pkgutils data
-tar --xattrs -zcpf ${DEST_SYS}/pkg-db.tar.gz \
-	/var/lib/pkg/db .
-
-# archive ports data
-tar --xattrs -zcpf ${DEST_SYS}/etc_ports.tar.gz \
-	--directory=/etc/ports \
-	.
-	    .	
-# must be using gwak instead of sed
-prt-get listinst -v | sed 's/ /#/g' | sed 's/$/.pkg.tar.gz/g' > ${DEST_SYS}/all-installed.pkg 
-
-for filename in /etc/ports/*.git; do
-	source $filename
-
-	echo "${NAME} port collection release (exp; ${BUILD_VERSION}):"
-
-	read RELEASE
-	# backup ports collection
-	echo "Backing up collection: 	${NAME}"
-	tar --xattrs -zcpf ${DEST_SYS}/${NAME}-ports-${RELEASE}.tar.gz \
-		--directory=/usr/ports/${NAME} \
-		--exclude=.git/ \
-		.
-
-	# create list of installed packages 
-	prt-get printf "%i %p %n\n" | grep "yes /usr/ports/${NAME}" | cut -d " " -f 3 > ${DEST_SYS}/${NAME}-installed.pkg
-
-	# backup collection packages
-	while read PORT_NAME; do
-		echo "Backing up package:	${NAME}/${PORT_NAME}"
-		# get installed version not version on ports
-		PACKAGE=$(grep "^${PORT_NAME}#" ${DEST_SYS}/all-installed.pkg)
-		echo "Package:	${PACKAGE}";
-
-		# check if binary package exist
-		if [ ! -f /usr/ports/packages/${PACKAGE} ]; then
-			echo "Building package: ${PACKAGE};"
-			sudo prt-get update ${PRT_GET_FLAGS} ${PORT_NAME}
-			#(cd /usr/ports/${NAME}/${line} \
-			#	&& sudo pkgmk -uf)
-		fi
-
-		if [ -f /usr/ports/packages/${PACKAGE} ]; then
-			echo ${PACKAGE} >> ${DEST_SYS}/${NAME}-backup.pkg
-			tar rvf ${DEST_SYS}/${NAME}-${RELEASE}.tar \
-				--directory=/usr/ports/packages \
-				${PACKAGE}
-		else
-			echo "Package ${PACKAGE} from ${PORT_NAME} port not found."
-			echo ${PACKAGE} >> ${DEST_SYS}/${NAME}-notfound.pkg
-		fi
-	done < ${DEST_SYS}/${NAME}-installed.pkg
-done
-
-echo "Creating  ${DEST_ARC}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz ..."
-tar --xattrs -zcpf ${DEST_ARC}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz \
-	--directory=${DEST_SYS} \
-	.
-
-echo "Creating links to /usr/ports/installed"
-rm -r /usr/ports/installed
-pkg_installed
-
-echo "Creating ports page"
-portspage --title=${BUILD_NAME}-${BUILD_VERSION} /usr/ports/installed > /usr/ports/installed/index.html
-
+backup_collections() {
+
+    # backup collection packages
+    while read COLL_VERSION; do
+        COLL_NAME=$(echo $COLL_VERSION | cut -d "-" -f 1)
+        COLL_RELEASE=$(echo $COLL_VERSION | cut -d "-" -f 2)
+
+        while read PORT_NAME; do
+            # get installed version not version on ports
+            PACKAGE=$(grep "^${PORT_NAME}#" ${DEST_SYS}/all-installed.pkg)
+            echo "Backing up package:	${PACKAGE}"
+
+            # check if binary package exist
+            if [ ! -f /usr/ports/packages/${PACKAGE} ]; then
+                echo "Building package: ${PACKAGE};"
+                sudo prt-get update ${PRT_GET_FLAGS} ${PORT_NAME}
+            fi
+
+            if [ -f /usr/ports/packages/${PACKAGE} ]; then
+                echo ${PACKAGE} >> ${DEST_SYS}/${COLL_NAME}-backup.pkg
+                tar rvf ${DEST_SYS}/${COLL_NAME}-${COLL_RELEASE}.tar --directory=/usr/ports/packages ${PACKAGE}
+            else
+                echo "Package ${PACKAGE} from ${PORT_NAME} port not found."
+                echo ${PACKAGE} >> ${DEST_SYS}/${COLL_NAME}-${COLL_RELEASE}-notfound.pkg
+            fi
+        done < ${DEST_SYS}/${COLL_NAME}-installed.pkg
+    done < ${DEST_SYS}/ports_versions.pkg
+}
+
+create_metadata() {
+    echo "${BUILD_NAME}-${BUILD_VERSION}" >> ${DEST_SYS}/build_version
+
+    # archive pkgutils data
+    tar --xattrs -zcpf ${DEST_SYS}/pkg-db.tar.gz /var/lib/pkg/db .
+
+    # archive ports data
+    tar --xattrs -zcpf ${DEST_SYS}/etc_ports.tar.gz --directory=/etc/ports .
+
+    # must be using gwak instead of sed
+    prt-get listinst -v | sed 's/ /#/g' | sed 's/$/.pkg.tar.gz/g' > ${DEST_SYS}/all-installed.pkg 
+
+    if [ -f ${DEST_SYS}/ports_versions ]; then
+        rm ${DEST_SYS}/ports_versions.pkg
+    fi
+
+    for filename in /etc/ports/*.git; do
+        source $filename
+
+        echo "${NAME} port collection release (exp; ${BUILD_VERSION}):"
+
+        read RELEASE
+        echo ${NAME}-${RELEASE} >> ${DEST_SYS}/ports_versions.pkg
+
+        # backup ports collection
+        echo "Backing up collection: 	${NAME}"
+        tar --xattrs -zcpf ${DEST_SYS}/${NAME}-ports-${RELEASE}.tar.gz \
+            --directory=/usr/ports/${NAME} \
+            --exclude=.git/ \
+            .
+
+        # create list of installed packages 
+        prt-get printf "%i %p %n\n" | grep "yes /usr/ports/${NAME}" | cut -d " " -f 3 > ${DEST_SYS}/${NAME}-installed.pkg
+    done
+}
+
+create_archive() {
+    echo "Creating  ${DEST_ARC}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz ..."
+    tar --xattrs -zcpf ${DEST_ARC}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz --directory=${DEST_SYS} .
+}
+
+update_host() {
+    echo "Creating links to /usr/ports/installed"
+    rm -r /usr/ports/installed
+    pkg_installed
+
+    echo "Creating ports page"
+    portspage --title=${BUILD_NAME}-${BUILD_VERSION} /usr/ports/installed > /usr/ports/installed/index.html
+}
+
+create_metadata
+backup_collections
+create_archive
+update_host
diff --git a/core/scripts/restore-ports.sh b/core/scripts/restore-ports.sh
new file mode 100644
index 0000000..39f5178
--- /dev/null
+++ b/core/scripts/restore-ports.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+BUILD_NAME=R1D9
+BUILD_VERSION=3.4.1
+WORK_DIR=/usr/ports/work/${BUILD_NAME}-${BUILD_VERSION}
+
+prepare_archive() {
+    mkdir -p ${WORK_DIR}
+    wget --directory-prefix=${WORK_DIR} https://hive.gnu.systems/mirror/releases/archives/${BUILD_NAME}-${BUILD_VERSION}.tar.gz
+    echo "extracting ${WORK_DIR}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz..."
+    tar -C ${WORK_DIR} -xf ${WORK_DIR}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz
+    rm ${WORK_DIR}/${BUILD_NAME}-${BUILD_VERSION}.tar.gz
+}
+
+extract_archives() {
+    while read COLL_VERSION; do
+        COLL_NAME=$(echo $COLL_VERSION | cut -d "-" -f 1)
+        COLL_RELEASE=$(echo $COLL_VERSION | cut -d "-" -f 2)
+        echo "extracting ${COLL_VERSION}.tar to /usr/ports/packages"
+        tar -C /usr/ports/packages -xf ${WORK_DIR}/${COLL_VERSION}.tar
+        rm ${WORK_DIR}/${COLL_VERSION}.tar
+    done < ${WORK_DIR}/ports_versions.pkg
+}
+
+update_system() {
+    mkdir -p ${WORK_DIR}/etc/ports
+    tar -C ${WORK_DIR}/etc/ports -xf ${WORK_DIR}/etc_ports.tar.gz
+    cp ${WORK_DIR}/etc/ports/*.git /etc/ports/
+
+    while read COLL_VERSION; do
+        COLL_NAME=$(echo $COLL_VERSION | cut -d "-" -f 1)
+        ports -u $COLL_NAME
+    done < ${WORK_DIR}/ports_versions.pkg
+
+    # first update with prt-get
+    prt-get sysup
+    prt-get --pre-install --post-install update $(prt-get listinst)
+    prt-get depinst $(prt-get printf "%p %n\n" | grep "/usr/ports/core" | cut -d " " -f 2)
+    prt-get update $(revdep)
+
+    rejmerge
+}
+
+install_distro() {
+    while read PACKAGE; do
+        prt-get depinst $(echo $PACKAGE | cut -d "#" -f 1);
+    done < ${WORK_DIR}/all-installed.pkg
+}
+
+prepare_archive
+extract_archives
+update_system
+install_distro