use snapper configuration file
This commit is contained in:
parent
769673531a
commit
088c4a630a
3 changed files with 46 additions and 40 deletions
24
README.md
24
README.md
|
|
@ -20,15 +20,23 @@ the scripts are located at `/usr/share/libalpm/hooks.bin/snap-pac`.
|
|||
|
||||
## Configuration
|
||||
|
||||
The configuration file is located at `/etc/snap-pac.conf`. There you can choose
|
||||
which snapper configurations, descriptions, and cleanup algorithm to use.
|
||||
Changing the file should be self-explanatory. The defaults should be sufficient
|
||||
for most users.
|
||||
Configuration is done via the snapper configuration files, with extra variables
|
||||
specific to these pacman hooks. The defaults should be suitable for most users.
|
||||
The following are possible settings you can place in each snapper configuration
|
||||
file:
|
||||
|
||||
By default, the snapshots are set up to use snapper's `number` algorithm.
|
||||
Additionally, by default, snapshots are only taken of the subvolume
|
||||
corresponding with the `root` snapper configuration. Descriptions are of the
|
||||
pacman command that initiated the snapshots.
|
||||
* `PACMAN_PRE_POST` - perform pacman pre/post snapshots for this configuration.
|
||||
Default is `"no"` for all configurations, except for the `root` configuration
|
||||
which is "`yes"`.
|
||||
* `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
|
||||
|
||||
|
|
|
|||
47
snap-pac
47
snap-pac
|
|
@ -21,33 +21,46 @@
|
|||
# Main script. Is sourced in hooks and functions are called.
|
||||
# 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 -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
|
||||
{
|
||||
for x in $configurations; do
|
||||
snapper --config $x create --type pre --cleanup-algorithm $cleanupalgo --print-number --description "$description" > $prefile_prefix"_"$x
|
||||
declare -i i=0
|
||||
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
|
||||
}
|
||||
|
||||
function post
|
||||
{
|
||||
for x in $configurations; do
|
||||
if [ -f $prefile_prefix"_"$x ]; then
|
||||
snapper --config $x create --cleanup-algorithm $cleanupalgo --type post --pre-number $(cat $prefile_prefix"_"$x) --description "$description"
|
||||
rm $prefile_prefix"_"$x
|
||||
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."
|
||||
declare -i i=0
|
||||
for x in $(ls /etc/snapper/configs); do
|
||||
if [[ ${take_snapshot[i]} == "yes" ]];then
|
||||
if [ -f $prefile_prefix"_"$x ]; then
|
||||
snapper --config $x create --cleanup-algorithm ${cleanupalgo[i]} --type post --pre-number $(cat $prefile_prefix"_"$x) --description "${post_description[i]}"
|
||||
rm $prefile_prefix"_"$x
|
||||
else
|
||||
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
|
||||
i=$(($i+1))
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
Loading…
Add table
Reference in a new issue