mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-04 04:35:00 +08:00
grub-btrfsd: watch snapshots directory recursively
Fix: #262 Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
This commit is contained in:
@@ -103,6 +103,8 @@ E.g. for Snapper this would be `/.snapshots`
|
||||
Disable colors in output.
|
||||
* `-l / --log-file`
|
||||
This arguments specifies a file where grub-btrfsd should write log messages.
|
||||
* `-r / --recursive`
|
||||
Watch the snapshots directory recursively
|
||||
* `-s / --syslog`
|
||||
* `-o / --timeshift-old`
|
||||
Look for snapshots in `/run/timeshift/backup/timeshift-btrfs` instead of `/run/timeshift/$PID/backup/timeshift-btrfs.` This is to be used for Timeshift versions <22.06.
|
||||
|
||||
10
config
10
config
@@ -1,15 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
GRUB_BTRFS_VERSION=4.12-HEAD-2023-03-26T17:46:23+00:00
|
||||
=======
|
||||
GRUB_BTRFS_VERSION=4.12-HEAD-2023-03-26T17:46:23+00:00
|
||||
>>>>>>> 02513bb (grub-btrfs: get bach the grub_btrfs_search_directory functionality)
|
||||
=======
|
||||
GRUB_BTRFS_VERSION=4.12-HEAD-2023-03-26T17:46:23+00:00
|
||||
>>>>>>> 4b564c1 (grub-btrfs: update comments)
|
||||
GRUB_BTRFS_VERSION=4.12-master-2023-03-26T18:44:50+00:00
|
||||
|
||||
# Disable grub-btrfs.
|
||||
# Default: "false"
|
||||
|
||||
31
grub-btrfsd
31
grub-btrfsd
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2022 Pascal Jaeger
|
||||
# Copyright 2023 Pascal Jaeger
|
||||
# Distributed under the terms of the GNU General Public License v3
|
||||
# Update GRUB when new BTRFS snapshots are created.
|
||||
|
||||
@@ -12,6 +12,7 @@ timeshift_auto=false
|
||||
timeshift_old=false
|
||||
verbose=false
|
||||
syslog=false
|
||||
recursive=false
|
||||
|
||||
setcolors() {
|
||||
if [ "${1}" = true ]; then
|
||||
@@ -37,13 +38,14 @@ grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
|
||||
|
||||
print_help() {
|
||||
echo "${CYAN}[?] Usage:"
|
||||
echo "${0##*/} [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR"
|
||||
echo "${0##*/} [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-r, --recursive] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR"
|
||||
echo
|
||||
echo "SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto"
|
||||
echo
|
||||
echo "Optional arguments:"
|
||||
echo "-c, --no-color Disable colors in output"
|
||||
echo "-l, --log-file Specify a logfile to write to"
|
||||
echo "-r, --recursive Watch snapshots directory recursively"
|
||||
echo "-s, --syslog Write to syslog"
|
||||
echo "-o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)"
|
||||
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
|
||||
@@ -59,7 +61,7 @@ log() {
|
||||
logger -p user.notice -t ${0##*/}"["$$"]" "$1"
|
||||
fi
|
||||
if [ ${#logfile} -gt 1 ]; then
|
||||
echo "$(date) ${1}" >> ${logfile}
|
||||
echo "$(date) ${1}" >> "${logfile}"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -70,7 +72,7 @@ vlog() {
|
||||
logger -p user.notice -t ${0##*/} "$1"
|
||||
fi
|
||||
if [ ${#logfile} -gt 1 ]; then
|
||||
echo "$(date) ${1}" >> ${logfile}
|
||||
echo "$(date) ${1}" >> "${logfile}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -81,12 +83,12 @@ err() {
|
||||
logger -p user.error -t ${0##*/} "$1"
|
||||
fi
|
||||
if [ ${#logfile} -gt 1 ]; then
|
||||
echo "$(date) error: ${1}" >> ${logfile}
|
||||
echo "$(date) error: ${1}" >> "${logfile}"
|
||||
fi
|
||||
}
|
||||
|
||||
# parse arguments
|
||||
while getopts :l:ctvsh-: opt; do
|
||||
while getopts :l:ctvrsh-: opt; do
|
||||
case "$opt" in
|
||||
-)
|
||||
case "${OPTARG}" in
|
||||
@@ -105,6 +107,9 @@ while getopts :l:ctvsh-: opt; do
|
||||
verbose)
|
||||
verbose=true
|
||||
;;
|
||||
recursive)
|
||||
recursive=true
|
||||
;;
|
||||
syslog)
|
||||
syslog=true
|
||||
;;
|
||||
@@ -136,6 +141,9 @@ while getopts :l:ctvsh-: opt; do
|
||||
v)
|
||||
verbose=true
|
||||
;;
|
||||
r)
|
||||
recursive=true
|
||||
;;
|
||||
s)
|
||||
syslog=true
|
||||
;;
|
||||
@@ -176,6 +184,12 @@ else
|
||||
inotify_qiet_flag=" -q -q "
|
||||
fi
|
||||
|
||||
if [ ${recursive} = true ]; then
|
||||
inotify_recursive_flag=" -r "
|
||||
else
|
||||
inotify_recursive_flag=""
|
||||
fi
|
||||
|
||||
if [ ${timeshift_auto} = false ] && [ ${timeshift_old} = true ]; then
|
||||
err "[!] Flag --timeshift-old requires flag --timeshift-auto" "${RED}" >&2
|
||||
exit 1
|
||||
@@ -186,6 +200,7 @@ vlog "Snapshot directory: $snapshots"
|
||||
vlog "Timestift autodetection: $timeshift_auto"
|
||||
vlog "Timeshift old: $timeshift_old"
|
||||
vlog "Logfile: $logfile"
|
||||
vlog "Recursive: $recursive"
|
||||
|
||||
if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then
|
||||
err "[!] No directory found at ${snapshots}" "${RED}" >&2
|
||||
@@ -210,7 +225,7 @@ create_grub_menu() {
|
||||
err "[!] Error during grub submenu creation (grub-btrfs error)" "${RED}"
|
||||
fi
|
||||
else
|
||||
if ${GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o ${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub.cfg; then
|
||||
if ${GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}"/grub.cfg; then
|
||||
log "Grub menu recreated" "${GREEN}"
|
||||
else
|
||||
err "[!] Error during grub menu creation (grub/ grub-btrfs error)" "${RED}"
|
||||
@@ -264,7 +279,7 @@ while true; do
|
||||
vlog "Watching $snapshots for new snapshots..." "${CYAN}"
|
||||
fi
|
||||
runs=true
|
||||
inotifywait ${inotify_qiet_flag} -e create -e delete -e unmount -t "$watchtime" "$snapshots" && {
|
||||
inotifywait ${inotify_qiet_flag} ${inotify_recursive_flag} -e create -e delete -e unmount -t "$watchtime" "$snapshots" && {
|
||||
log "Detected snapshot creation/ deletion, recreating Grub menu" "${CYAN}"
|
||||
sleep 5
|
||||
create_grub_menu
|
||||
|
||||
@@ -9,7 +9,7 @@ when a new btrfs snapshot is created.
|
||||
|
||||
.SH "SYNOPSIS"
|
||||
.PP
|
||||
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-o, \-\-timeshift\-old] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP
|
||||
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-r, \-\-recursive] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-o, \-\-timeshift\-old] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP
|
||||
|
||||
.SH "DESCRIPTION"
|
||||
.PP
|
||||
@@ -30,6 +30,10 @@ Disable colors in output.
|
||||
.PP
|
||||
This arguments specifies a file where grub-btrfsd should write log messages.
|
||||
|
||||
.SS "\fC\-r / \-\-recursive\fP"
|
||||
.PP
|
||||
Watch snapshot directory recursively
|
||||
|
||||
.SS "\fC\-s / \-\-syslog\fP"
|
||||
.PP
|
||||
Write to syslog
|
||||
@@ -50,8 +54,6 @@ Let the log of the daemon be more verbose
|
||||
.PP
|
||||
Displays a short help message.
|
||||
|
||||
|
||||
|
||||
.SH "CONFIGURATION"
|
||||
.PP
|
||||
The daemon is usually configured via the file \fC/etc/conf.d/grub\-btrfsd\fP on openrc-init systems and \fCsudo systemctl edit \-\-full grub\-btrfsd\fP on systemd systems. In this file the arguments (See OPTIONS), that OpenRC passes to the daemon when it is started, can be configured.
|
||||
|
||||
@@ -10,7 +10,7 @@ grub-btrfsd - An OpenRC daemon to automatically update the grub menu with
|
||||
when a new btrfs snapshot is created.
|
||||
|
||||
* SYNOPSIS
|
||||
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-o, --timeshift-old] [-v, --verbose] SNAPSHOTS_DIR~
|
||||
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-r, --recursive] [-s, --syslog] [-t, --timeshift-auto] [-o, --timeshift-old] [-v, --verbose] SNAPSHOTS_DIR~
|
||||
|
||||
* DESCRIPTION
|
||||
Grub-btrfsd is a shell script which is meant to be run as a daemon.
|
||||
@@ -27,6 +27,9 @@ Disable colors in output.
|
||||
** ~-l / --log-file~
|
||||
This arguments specifies a file where grub-btrfsd should write log messages.
|
||||
|
||||
** ~-r / --recursive~
|
||||
Watch snapshot directory recursively
|
||||
|
||||
** ~-s / --syslog~
|
||||
Write to syslog
|
||||
|
||||
@@ -42,8 +45,6 @@ Let the log of the daemon be more verbose
|
||||
** ~-h / --help~
|
||||
Displays a short help message.
|
||||
|
||||
|
||||
|
||||
* CONFIGURATION
|
||||
The daemon is usually configured via the file ~/etc/conf.d/grub-btrfsd~ on openrc-init systems and ~sudo systemctl edit --full grub-btrfsd~ on systemd systems. In this file the arguments (See OPTIONS), that OpenRC passes to the daemon when it is started, can be configured.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user