#!/bin/zsh
set -x
read revno rest <~ccx/bzr/prosys/.bzr/branch/last-revision
[[ -d $1 ]] || exit 1
NEW=${1/-o???-/-o$revno-}
[[ -d $NEW ]] && btrfs sub del $NEW
btrfs sub snap $1 $NEW || exit $?
pushd $NEW/var/portage/prosys || exit $?
bzr pull --overwrite ~ccx/bzr/prosys || exit $?
popd || exit $?
$NEW/chroot.sh /var/portage/prosys/overlay/scripts/update_profiles || exit $?
$NEW/chroot.sh /usr/bin/emerge -vuDN @world || exit $?