From a12c4f3c43a618fcc03aede18baa7b93bbda54f1 Mon Sep 17 00:00:00 2001 From: nirav Date: Sat, 17 Nov 2018 13:01:14 +0000 Subject: Initial commit --- esync | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 esync 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" -- cgit v1.2.3