From 13b6df8e9aca9b48501626dfbff837f69ee5463e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20J=C3=A4ger?= Date: Wed, 23 Nov 2022 15:54:31 +0100 Subject: [PATCH] grub-btrfsd: Add flag for colorless output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pascal Jäger --- README.md | 15 +++++++++++++++ config | 2 +- grub-btrfsd | 35 ++++++++++++++++++++++++++--------- manpages/grub-btrfsd.8.man | 24 +++++++++++++++--------- manpages/grub-btrfsd.8.org | 23 ++++++++++++++--------- 5 files changed, 71 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 3725f65..f31e89b 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,21 @@ On most distributions and installs, the grub installation resides in `/boot/grub Grub-btrfs comes with a daemon script that automatically updates the grub menu when it sees a snapshot being created or deleted in a directory it is given via command line. The daemon can be configured by passing different command line arguments to it. +The arguments are: +* `SNAPSHOTS_DIR` +This argument specifies the path where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots. +E.g. for Snapper this would be `/.snapshots` +* `-c / --no-color` +Disable colors in output. +* `-l / --log-file` +This arguments specifies a file where grub-btrfsd should write log messages. +* `-s / --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. +* `-v / --verbose` +Let the log of the daemon be more verbose +* `-h / --help` +Displays a short help message. ##### Systemd instructions To edit the arguments that are passed to the daemon, use diff --git a/config b/config index 47c1f78..5f53e83 100644 --- a/config +++ b/config @@ -1,6 +1,6 @@ #!/usr/bin/env bash -GRUB_BTRFS_VERSION=4.11-20221123 +GRUB_BTRFS_VERSION=4.11-20221123-1 # Disable grub-btrfs. # Default: "false" diff --git a/grub-btrfsd b/grub-btrfsd index b72e1d5..1c84c4c 100755 --- a/grub-btrfsd +++ b/grub-btrfsd @@ -12,11 +12,21 @@ timeshift_auto=false verbose=false syslog=false -# helper functions -GREEN=$'\033[0;32m' -RED=$'\033[0;31m' -CYAN=$'\033[;36m' -RESET=$'\033[0m' +setcolors() { + if [ "${1}" = true ]; then + GREEN=$'\033[0;32m' + RED=$'\033[0;31m' + CYAN=$'\033[;36m' + RESET=$'\033[0m' + fi + if [ "${1}" = false ]; then + GREEN=$'\033[0;0m' + RED=$'\033[0;0m' + CYAN=$'\033[;0m' + RESET=$'\033[0m' + fi +} +setcolors true # normally we want colors sysconfdir="/etc" grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config" @@ -26,15 +36,16 @@ grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config" print_help() { echo "${CYAN}[?] Usage:" - echo "${0##*/} [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] [-v, --verbose] [-s, --syslog] SNAPSHOTS_DIR" + echo "${0##*/} [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-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 "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory" + echo "-c, --no-color Disable colors in output" echo "-l, --log-file Specify a logfile to write to" - echo "-v, --verbose Let the log of the daemon be more verbose" echo "-s, --syslog Write to syslog" + echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory" + echo "-v, --verbose Let the log of the daemon be more verbose" echo "-h, --help Display this message" echo echo "Version ${GRUB_BTRFS_VERSION}${RESET}" @@ -73,10 +84,13 @@ err() { } # parse arguments -while getopts :l:tvsh-: opt; do +while getopts :l:ctvsh-: opt; do case "$opt" in -) case "${OPTARG}" in + no-color) + setcolors false + ;; log-file) logfile="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) ;; @@ -102,6 +116,9 @@ while getopts :l:tvsh-: opt; do exit 1 ;; esac;; + c) + setcolors false + ;; l) logfile="${OPTARG}" ;; diff --git a/manpages/grub-btrfsd.8.man b/manpages/grub-btrfsd.8.man index 9158d62..5c4ad74 100644 --- a/manpages/grub-btrfsd.8.man +++ b/manpages/grub-btrfsd.8.man @@ -9,12 +9,12 @@ when a new btrfs snapshot is created. .SH "SYNOPSIS" .PP -\fCgrub\-btrfsd [\-h, \-\-help] [\-t, \-\-timeshift\-auto] [\-l, \-\-log\-file LOG_FILE] [\-v, \-\-verbose] [\-s, \-\-syslog] SNAPSHOTS_DIR\fP +\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP .SH "DESCRIPTION" .PP -Grub-btrfs-openrc is a shell script which is meant to be run as a daemon. -Grub-btrfsd watches a directory where snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or \fC/etc/grub.d/41_snapshots\-btrfs\fP (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes. +Grub-btrfsd is a shell script which is meant to be run as a daemon. +Grub-btrfsd watches a directory where btrfs-snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or \fC/etc/grub.d/41_snapshots\-btrfs\fP (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes. .SH "OPTIONS" .SS "\fCSNAPSHOTS_DIR\fP" @@ -22,25 +22,31 @@ Grub-btrfsd watches a directory where snapshots are created or deleted via inoti This argument specifies the path where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots. E.g. for Snapper this would be \fC/.snapshots\fP -.SS "\fC\-t / \-\-timeshift\-auto\fP" +.SS "\fC\-c / \-\-no\-color\fP" .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. +Disable colors in output. .SS "\fC\-l / \-\-log\-file\fP" .PP This arguments specifies a file where grub-btrfsd should write log messages. -.SS "\fC\-h / \-\-help\fP" +.SS "\fC\-s / \-\-syslog\fP" .PP -Displays a short help message. +Write to syslog + +.SS "\fC\-t / \-\-timeshift\-auto\fP" +.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\-v / \-\-verbose\fP" .PP Let the log of the daemon be more verbose -.SS "\fC\-s / \-\-syslog\fP" +.SS "\fC\-h / \-\-help\fP" .PP -Write to syslog +Displays a short help message. + + .SH "CONFIGURATION" .PP diff --git a/manpages/grub-btrfsd.8.org b/manpages/grub-btrfsd.8.org index c6521fa..37329af 100644 --- a/manpages/grub-btrfsd.8.org +++ b/manpages/grub-btrfsd.8.org @@ -10,31 +10,36 @@ grub-btrfsd - An OpenRC daemon to automatically update the grub menu with when a new btrfs snapshot is created. * SYNOPSIS -~grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] [-v, --verbose] [-s, --syslog] SNAPSHOTS_DIR~ +~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR~ * DESCRIPTION -Grub-btrfs-openrc is a shell script which is meant to be run as a daemon. -Grub-btrfsd watches a directory where snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or ~/etc/grub.d/41_snapshots-btrfs~ (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes. +Grub-btrfsd is a shell script which is meant to be run as a daemon. +Grub-btrfsd watches a directory where btrfs-snapshots are created or deleted via inotifywait and runs grub-mkconfig (if grub-mkconfig never ran before since grub-btrfs was installed) or ~/etc/grub.d/41_snapshots-btrfs~ (when grub-mkconfig ran before with grub-btrfs installed) when something in that directory changes. * OPTIONS ** ~SNAPSHOTS_DIR~ This argument specifies the path where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots. E.g. for Snapper this would be ~/.snapshots~ -** ~-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. +** ~-c / --no-color~ +Disable colors in output. ** ~-l / --log-file~ This arguments specifies a file where grub-btrfsd should write log messages. -** ~-h / --help~ -Displays a short help message. +** ~-s / --syslog~ +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. ** ~-v / --verbose~ Let the log of the daemon be more verbose -** ~-s / --syslog~ -Write to syslog +** ~-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.