diff options
author | nirav <nirav@teisuu.com> | 2018-11-17 13:01:14 +0000 |
---|---|---|
committer | nirav <nirav@teisuu.com> | 2018-11-17 13:01:14 +0000 |
commit | a12c4f3c43a618fcc03aede18baa7b93bbda54f1 (patch) | |
tree | ae00eb8da77e9cba54f116cc743c6f2f22a6187e | |
download | esync-a12c4f3c43a618fcc03aede18baa7b93bbda54f1.tar.gz esync-a12c4f3c43a618fcc03aede18baa7b93bbda54f1.zip |
-rwxr-xr-x | esync | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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" |