summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornirav <nirav@teisuu.com>2018-11-17 13:01:14 +0000
committernirav <nirav@teisuu.com>2018-11-17 13:01:14 +0000
commita12c4f3c43a618fcc03aede18baa7b93bbda54f1 (patch)
treeae00eb8da77e9cba54f116cc743c6f2f22a6187e
downloadesync-master.tar.gz
esync-master.zip
Initial commitHEADmaster
-rwxr-xr-xesync37
1 files changed, 37 insertions, 0 deletions
diff --git a/esync b/esync
new file mode 100755
index 0000000..cf9d5d7
--- /dev/null
+++ b/esync
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+#SNAPSHOT_URL="http://distfiles.gentoo.org/snapshots/squashfs/gentoo-current.xz.sqfs"
+SNAPSHOT_URL="http://distfiles.gentoo.org/snapshots/squashfs/gentoo-20190524.xz.sqfs"
+DOWNLOAD_CMD="axel -an 16"
+DEST_FILE="/usr/portage.xz.sqfs"
+MOUNT_PATH="/usr/portage"
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+[[ $EUID -eq 0 ]] || die "This script must be run as root"
+
+echo "Downloading $SNAPSHOT_URL"
+$DOWNLOAD_CMD "$SNAPSHOT_URL" -o "${DEST_FILE}.NEW" &> /dev/null \
+ || die "Failed to download file"
+
+if [[ -f "$DEST_FILE" ]]; then
+ echo "Backing up $DEST_FILE"
+ mv "$DEST_FILE" "${DEST_FILE}.OLD" || die "Filed to move file"
+fi
+
+mv "${DEST_FILE}.NEW" "$DEST_FILE" || die "Filed to move file"
+
+echo "Remounting $MOUNT_PATH"
+if mount | grep "$MOUNT_PATH" > /dev/null; then
+ umount "$MOUNT_PATH" || die "Failed to unmount $MOUNT_PATH"
+fi
+mount "$MOUNT_PATH" || die "Failed to mount $MOUNT_PATH"
+
+if [[ -f "${DEST_FILE}.OLD" ]]; then
+ echo "Cleaning up"
+ rm "${DEST_FILE}.OLD"
+fi
+
+echo "Done"