#!/bin/bash
#
# This script is called when "snapper rollback" is executed.
# It should stay in /usr/lib/snapper/plugins/rollback
#
# Arguments: old_snapshot new_snapshot
#
# the old snapshot is read-only, the new snapshot is read-write
#

VARDIR=/var/lib/rollback
OLD=$1
NEW=$2

# Write flag file into VARDIR; if this directory is part of the root file
# system (e.g. when using an old subvolume layout) then write to the *new*
# snapshot directory, otherwise the file won't be visible to the new snapshot.
if [ "$(findmnt --noheadings --output TARGET --target "${VARDIR}")" = "/" ]; then
  VARDIR="${NEW}/${VARDIR}"
fi
test -d "${VARDIR}" || mkdir -p "${VARDIR}/"
touch "${VARDIR}/check-registration"
