From c8c343a29241abba33ad0b0590305b30d3a54011 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sun, 2 Jan 2011 14:35:02 -0600 Subject: [PATCH] update: add -n flag to avoid syncing and snapshotting an upstream tree that you know has not changed; useful for pushing overlay changes to the tree --- update | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/update b/update index 7d9d736..00bc7ae 100755 --- a/update +++ b/update @@ -4,12 +4,16 @@ [ "$(id -u)" -eq 0 ] || exec sudo "${0}" "${@}" cd "$(dirname "${0}")" +[ "${1}" = "-n" ] && NO_SYNC=true + meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; } omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; } wtf() { printf " \033[1;31m*\033[0m %s\n" "${*}"; kill $$; exit 1; } sync="rsync://paka/freebsd-ports" +sync_opts="--archive --compress --delete --hard-links --sparse --stats --verbose" + ports=alba/ports upstream=alba/srcs/freebsd/ports/upstream prepare=alba/srcs/freebsd/ports/prepare @@ -18,34 +22,47 @@ today="$(date +%Y-%m-%d)" ports_origin="$(zfs get -H -o value origin "${ports}")" ports_origin="${ports_origin%%@*}" ports_fs="$(zfs get -H -o value mountpoint "${ports}")" +ports_fs="${ports_fs:-/usr/ports}" upstream_fs="$(zfs get -H -o value mountpoint "${upstream}")" # Make sure the ports tree is a descendent of the ports upstream [ "${ports_origin}" = "${upstream}" ] || wtf "Target ${ports} is not a child of ${upstream} (is ${ports_origin})" -# Compute the next available snapshot -last_snapshot="$(zfs list -rHt snapshot -o name "${upstream}" | grep "@${today}_" | sort | tail -n 1 | sed -e 's/^.*_\([0-9]\{2\}\)$/\1/')" -if [ "${last_snapshot}" ] +if [ -z "${NO_SYNC}" ] then - snapshot="$(printf "${today}_%02u" "$(( ${last_snapshot} + 1 ))")" - echo "${today}_${last_snapshot} -> ${snapshot}" + # Compute the next available snapshot + last_snapshot="$(zfs list -rHt snapshot -o name "${upstream}" | grep "@${today}_" | sort | tail -n 1 | sed -e 's/^.*_\([0-9]\{2\}\)$/\1/')" + if [ "${last_snapshot}" ] + then + snapshot="$(printf "${today}_%02u" "$(( ${last_snapshot} + 1 ))")" + echo "${today}_${last_snapshot} -> ${snapshot}" + else + snapshot="${today}_00" + echo "None -> ${snapshot}" + fi else - snapshot="${today}_00" - echo "None -> ${snapshot}" + # Don't bother creating a new snapshot if the tree will not be synchronized + last_snapshot="$(zfs list -rHt snapshot -o name "${upstream}" | sort | tail -n 1)" + snapshot="${last_snapshot##*@}" + echo "Using existing snapshot ${snapshot}" fi # Bail out if anything is / [ -z "${ports_fs}" -o -z "${upstream_fs}" ] && wtf "Writing to /? Are you nuts?" -meh "Update" -rsync --archive --compress --delete --hard-links --sparse --stats --verbose "${sync}/" "${upstream_fs}/" || wtf "update failed" +if [ -z "${NO_SYNC}" ] +then + meh "Update" + rsync ${sync_opts} "${sync}/" "${upstream_fs}/" || wtf "update failed" -meh "Snapshot" -zfs snapshot "${upstream}@${snapshot}" || wtf "snapshot failed" + meh "Snapshot" + zfs snapshot "${upstream}@${snapshot}" || wtf "snapshot failed" +fi meh "Clone" zfs clone "${upstream}@${snapshot}" "${prepare}" || wtf "clone failed" +zfs set atime=off "${prepare}" || wtf "atime-off failed" # Resolve filesystem mountpoints, now that everything should exist prepare_fs="$(zfs get -H -o value mountpoint "${prepare}")" @@ -61,6 +78,8 @@ do done meh "Install" +zfs set readonly=on "${prepare}" || wtf "readonly failed" +# Only move old ports tree out of the way if it exists zfs rename "${ports}" "${ports}-bak" || wtf "backup rename failed" zfs rename "${prepare}" "${ports}" || wtf "rename prepare -> ports failed" zfs inherit mountpoint "${ports}-bak" || wtf "inherit failed" -- 2.42.0