diff --git a/config b/config index bd360bd..3cca83e 100644 --- a/config +++ b/config @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GRUB_BTRFS_VERSION=4.12-master-2022-11-26T16:44:06+00:00 +GRUB_BTRFS_VERSION=4.12-master-2022-11-26T16:46:45+00:00 # Disable grub-btrfs. # Default: "false" diff --git a/grub-btrfsd b/grub-btrfsd index 1c84c4c..8f28268 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 @@ -31,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,6 +45,7 @@ print_help() { echo "-c, --no-color Disable colors in output" echo "-l, --log-file Specify a logfile to write to" echo "-s, --syslog Write to syslog" + echo "-o, --timeshift-old Look for snapshots in directory of Timeshift &2 + exit 1 +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 @@ -204,6 +218,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}" @@ -217,7 +240,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 @@ -225,7 +248,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 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