From 91c4aac82cffbfefe9cb1cd1b81788c98b1f1f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20J=C3=A4ger?= Date: Fri, 25 Nov 2022 08:52:49 +0100 Subject: [PATCH 1/4] grub-btrfsd: make dir check of snapshots dir a warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug #234 Signed-off-by: Pascal Jäger --- grub-btrfsd | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/grub-btrfsd b/grub-btrfsd index 1c84c4c..4855895 100755 --- a/grub-btrfsd +++ b/grub-btrfsd @@ -174,9 +174,7 @@ vlog "Timestift autodetection: $timeshift_auto" vlog "Logfile: $logfile" if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then - err "[!] No directory found at ${snapshots}" "${RED}" >&2 - err "[!] Please specify a valid snapshot directory" "${RED}" >&2 - exit 1 + log "[!] No directory found at ${snapshots}" "${CYAN}" >&2 fi if [ ${timeshift_auto} = true ]; then From 4942989d7fdb76d9f7595690460c5970b5a194bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20J=C3=A4ger?= Date: Fri, 25 Nov 2022 16:58:07 +0100 Subject: [PATCH 2/4] grub-btrfsd: add flag or old timeshift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pascal Jäger --- grub-btrfsd | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/grub-btrfsd b/grub-btrfsd index 4855895..0f68698 100755 --- a/grub-btrfsd +++ b/grub-btrfsd @@ -9,6 +9,7 @@ watchtime=0 logfile=0 snapshots=-1 timeshift_auto=false +timeshift_old=false verbose=false syslog=false @@ -43,6 +44,7 @@ print_help() { echo "Optional arguments:" echo "-c, --no-color Disable colors in output" echo "-l, --log-file Specify a logfile to write to" + echo "-o, --timeshift-old Look for snapshots in directory of Timeshift &2 + exit 1 +else + vlog "Arguments:" vlog "Snapshot directory: $snapshots" vlog "Timestift autodetection: $timeshift_auto" vlog "Logfile: $logfile" if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then - log "[!] No directory found at ${snapshots}" "${CYAN}" >&2 + err "[!] No directory found at ${snapshots}" "${RED}" >&2 + err "[!] Please specify a valid snapshot directory" "${RED}" >&2 + exit 1 fi if [ ${timeshift_auto} = true ]; then @@ -202,6 +217,15 @@ create_grub_menu() { fi } +set_snapshot_dir() { + # old timeshift has it's snapshot dir in a different location + if [ ${timeshift_old} = true ]; then + snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" + else + snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots" + fi +} + # start the actual daemon vlog "Snapshot dir watchtimeout: $watchtime" vlog "Entering infinite while" "${GREEN}" @@ -215,7 +239,7 @@ while true; do fi timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}') if [ "${#timeshift_pid}" -gt 0 ]; then - snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots" + set_snapshot_dir log "detected running Timeshift at daemon startup, PID is: $timeshift_pid" vlog "new snapshots directory is $snapshots" else @@ -223,7 +247,7 @@ while true; do inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && { sleep 1 timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}') - snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots" + set_snapshot_dir log "detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}" vlog "new snapshots directory is $snapshots" "${CYAN}" (create_grub_menu) # create the grub menu once immidiatly in a forking process. Snapshots from commandline using timeshift --create need this From 6f154329c7a059f0d3417d882aba0fd06de7acd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20J=C3=A4ger?= Date: Sat, 26 Nov 2022 10:02:41 +0100 Subject: [PATCH 3/4] grub-btrfsd: fix if...else in daemon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add description of feature in manpage fix non sh compatible commands in daemon Signed-off-by: Pascal Jäger --- config | 2 +- grub-btrfsd | 13 +++++++------ manpages/grub-btrfsd.8.man | 6 +++++- manpages/grub-btrfsd.8.org | 5 ++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/config b/config index 159c798..a2e2384 100644 --- a/config +++ b/config @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GRUB_BTRFS_VERSION=4.12-20221123 +GRUB_BTRFS_VERSION=4.12-20221126-fix-snap-dir # Disable grub-btrfs. # Default: "false" diff --git a/grub-btrfsd b/grub-btrfsd index 0f68698..e9f616d 100755 --- a/grub-btrfsd +++ b/grub-btrfsd @@ -32,8 +32,8 @@ setcolors true # normally we want colors sysconfdir="/etc" grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config" # source config file -[[ -f "$grub_btrfs_config" ]] && . "$grub_btrfs_config" -[[ -f "${sysconfdir}/default/grub" ]] && . "${sysconfdir}/default/grub" +[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config" +[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub" print_help() { echo "${CYAN}[?] Usage:" @@ -44,8 +44,8 @@ print_help() { echo "Optional arguments:" echo "-c, --no-color Disable colors in output" echo "-l, --log-file Specify a logfile to write to" - echo "-o, --timeshift-old Look for snapshots in directory of Timeshift &2 + err "[!] Flag --timeshift-old requires flag --timeshift-auto" "${RED}" >&2 exit 1 -else +fi vlog "Arguments:" vlog "Snapshot directory: $snapshots" vlog "Timestift autodetection: $timeshift_auto" +vlog "Timeshift old: $timeshift_old" vlog "Logfile: $logfile" if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then @@ -219,7 +220,7 @@ create_grub_menu() { set_snapshot_dir() { # old timeshift has it's snapshot dir in a different location - if [ ${timeshift_old} = true ]; then + if [ "${timeshift_old}" = true ]; then snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" else snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots" diff --git a/manpages/grub-btrfsd.8.man b/manpages/grub-btrfsd.8.man index 5c4ad74..8d4805c 100644 --- a/manpages/grub-btrfsd.8.man +++ b/manpages/grub-btrfsd.8.man @@ -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] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP +\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 .SH "DESCRIPTION" .PP @@ -38,6 +38,10 @@ Write to syslog .PP This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. Where \fC$PID\fP is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument \fCSNAPSHOTS_DIR\fP has no effect. +.SS "\fC\-o / \-\-timeshift\-old\fP" +.PP +Look for snapshots in \fC/run/timeshift/backup/timeshift\-btrfs\fP instead of \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. This is to be used for Timeshift versions <22.06. + .SS "\fC\-v / \-\-verbose\fP" .PP Let the log of the daemon be more verbose diff --git a/manpages/grub-btrfsd.8.org b/manpages/grub-btrfsd.8.org index 37329af..156233b 100644 --- a/manpages/grub-btrfsd.8.org +++ b/manpages/grub-btrfsd.8.org @@ -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] [-v, --verbose] SNAPSHOTS_DIR~ +~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-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. @@ -33,6 +33,9 @@ Write to syslog ** ~-t / --timeshift-auto~ This is a flag to activate the auto detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to ~/run/timeshift/$PID/backup/timeshift-btrfs~. Where ~$PID~ is the process ID of the currently running Timeshift session. The PID is changing every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument ~SNAPSHOTS_DIR~ has no effect. +** ~-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. + ** ~-v / --verbose~ Let the log of the daemon be more verbose From efc4657aab32bb6cb6a6518b3787f3f8d3be1ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20J=C3=A4ger?= Date: Sat, 26 Nov 2022 14:16:37 +0100 Subject: [PATCH 4/4] grub-btrfsd: fixed message about flag dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pascal Jäger --- config | 2 +- grub-btrfsd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config b/config index a2e2384..a56c607 100644 --- a/config +++ b/config @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GRUB_BTRFS_VERSION=4.12-20221126-fix-snap-dir +GRUB_BTRFS_VERSION=4.12-fix-snap-dir-check-2022-11-26T14:06:44+00:00 # Disable grub-btrfs. # Default: "false" diff --git a/grub-btrfsd b/grub-btrfsd index e9f616d..8f28268 100755 --- a/grub-btrfsd +++ b/grub-btrfsd @@ -176,7 +176,7 @@ else inotify_qiet_flag=" -q -q " fi -if [ ${timeshift_auto} = false ] && [ ${timeshift_old} = false ]; then +if [ ${timeshift_auto} = false ] && [ ${timeshift_old} = true ]; then err "[!] Flag --timeshift-old requires flag --timeshift-auto" "${RED}" >&2 exit 1 fi