use snapper configuration file

This commit is contained in:
James Barnett 2016-04-26 08:23:50 -05:00
parent 769673531a
commit 088c4a630a
3 changed files with 46 additions and 40 deletions

View file

@ -20,15 +20,23 @@ the scripts are located at `/usr/share/libalpm/hooks.bin/snap-pac`.
## Configuration ## Configuration
The configuration file is located at `/etc/snap-pac.conf`. There you can choose Configuration is done via the snapper configuration files, with extra variables
which snapper configurations, descriptions, and cleanup algorithm to use. specific to these pacman hooks. The defaults should be suitable for most users.
Changing the file should be self-explanatory. The defaults should be sufficient The following are possible settings you can place in each snapper configuration
for most users. file:
By default, the snapshots are set up to use snapper's `number` algorithm. * `PACMAN_PRE_POST` - perform pacman pre/post snapshots for this configuration.
Additionally, by default, snapshots are only taken of the subvolume Default is `"no"` for all configurations, except for the `root` configuration
corresponding with the `root` snapper configuration. Descriptions are of the which is "`yes"`.
pacman command that initiated the snapshots. * `PACMAN_CLEANUP_ALGORITHM` - snapper algorithm used in cleaning up the pacman pre/post
snapshots. Default is `"number"`.
* `PACMAN_PRE_DESCRIPTION` - snapper description used for the pacman pre snapshot.
Default is the pacman command that called the snapshot.
* `PACMAN_POST_DESCRIPTION` - snapper description used for the pacman post snapshot.
Default is the pacman command that called the snapshot.
These settings only need to be added to the snapper configuration files if you
want to change the default.
## Usage ## Usage

View file

@ -21,33 +21,46 @@
# Main script. Is sourced in hooks and functions are called. # Main script. Is sourced in hooks and functions are called.
# e.g.: bash -c ". snap-pac; pre" # e.g.: bash -c ". snap-pac; pre"
if [ -f /etc/snap-pac.conf ]; then
source /etc/snap-pac.conf
else
echo "WARNING: /etc/snap-pac.conf is missing. Using default settings."
fi
declare -r cleanupalgo=${CLEANUP_ALGORITHM:-"number"}
declare -r description=${POST_DESCRIPTION:-"$(echo $(ps -C pacman -o args=) | sed 'sX/usr/bin/pacmanXpacmanXg')"}
declare -r configurations=${CONFIGS:-"root"}
declare -r prefile_prefix="/usr/share/libalpm/hooks.bin/snap-pac/.pre" declare -r prefile_prefix="/usr/share/libalpm/hooks.bin/snap-pac/.pre"
declare -i i=0
for x in $(ls /etc/snapper/configs); do
source /etc/snapper/configs/$x
if [[ $x == "root" ]]; then
take_snapshot[i]=${PACMAN_PRE_POST:-"yes"}
else
take_snapshot[i]=${PACMAN_PRE_POST:-"no"}
fi
cleanupalgo[i]=${PACMAN_CLEANUP_ALGORITHM:-"number"}
pre_description[i]=${PACMAN_PRE_DESCRIPTION:-"$(echo $(ps -C pacman -o args=) | sed 'sX/usr/bin/pacmanXpacmanXg')"}
post_description[i]=${PACMAN_POST_DESCRIPTION:-"$(echo $(ps -C pacman -o args=) | sed 'sX/usr/bin/pacmanXpacmanXg')"}
i=$(($i+1))
done
function pre function pre
{ {
for x in $configurations; do declare -i i=0
snapper --config $x create --type pre --cleanup-algorithm $cleanupalgo --print-number --description "$description" > $prefile_prefix"_"$x for x in $(ls /etc/snapper/configs); do
if [[ ${take_snapshot[i]} == "yes" ]];then
snapper --config $x create --type pre --cleanup-algorithm ${cleanupalgo[i]} --print-number --description "${pre_description[i]}" > $prefile_prefix"_"$x
fi
i=$(($i+1))
done done
} }
function post function post
{ {
for x in $configurations; do declare -i i=0
for x in $(ls /etc/snapper/configs); do
if [[ ${take_snapshot[i]} == "yes" ]];then
if [ -f $prefile_prefix"_"$x ]; then if [ -f $prefile_prefix"_"$x ]; then
snapper --config $x create --cleanup-algorithm $cleanupalgo --type post --pre-number $(cat $prefile_prefix"_"$x) --description "$description" snapper --config $x create --cleanup-algorithm ${cleanupalgo[i]} --type post --pre-number $(cat $prefile_prefix"_"$x) --description "${post_description[i]}"
rm $prefile_prefix"_"$x rm $prefile_prefix"_"$x
else else
echo "WARNING: $prefile_prefix"_"$x does not exist, so no post snapshot will be taken. If you are initially installing snap-pac, this is normal." echo "WARNING: $prefile_prefix"_"$x does not exist, so no post snapshot for $x configuration will be taken. If you are initially installing snap-pac, this is normal."
fi fi
fi
i=$(($i+1))
done done
} }

View file

@ -1,15 +0,0 @@
# snap-pac configuration file
# Snapper configurations of which you want to take pre/post snapshot set.
# Default is just the root configuration. Uses spaces between each configuration
# name.
#CONFIGS="root"
#CONFIGS="root home"
# The description of the pre/post snapshots. Default is the pacman command that
# called the hook
#PRE_DESCRIPTION="$(echo $(ps -C pacman -o args=) | sed 'sX/usr/bin/pacmanXpacmanXg')"
#POST_DESCRIPTION="$(echo $(ps -C pacman -o args=) | sed 'sX/usr/bin/pacmanXpacmanXg')"
# Snapper cleanup algorithm to use.
#CLEANUP_ALGORITHM="number"