Skip to content

Commit 13b6df8

Browse files
committed
grub-btrfsd: Add flag for colorless output
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
1 parent 2186d83 commit 13b6df8

File tree

5 files changed

+71
-28
lines changed

5 files changed

+71
-28
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ On most distributions and installs, the grub installation resides in `/boot/grub
9595
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.
9696

9797
The daemon can be configured by passing different command line arguments to it.
98+
The arguments are:
99+
* `SNAPSHOTS_DIR`
100+
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.
101+
E.g. for Snapper this would be `/.snapshots`
102+
* `-c / --no-color`
103+
Disable colors in output.
104+
* `-l / --log-file`
105+
This arguments specifies a file where grub-btrfsd should write log messages.
106+
* `-s / --syslog`
107+
* `-t / --timeshift-auto`
108+
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.
109+
* `-v / --verbose`
110+
Let the log of the daemon be more verbose
111+
* `-h / --help`
112+
Displays a short help message.
98113

99114
##### Systemd instructions
100115
To edit the arguments that are passed to the daemon, use

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
GRUB_BTRFS_VERSION=4.11-20221123
3+
GRUB_BTRFS_VERSION=4.11-20221123-1
44

55
# Disable grub-btrfs.
66
# Default: "false"

grub-btrfsd

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ timeshift_auto=false
1212
verbose=false
1313
syslog=false
1414

15-
# helper functions
16-
GREEN=$'\033[0;32m'
17-
RED=$'\033[0;31m'
18-
CYAN=$'\033[;36m'
19-
RESET=$'\033[0m'
15+
setcolors() {
16+
if [ "${1}" = true ]; then
17+
GREEN=$'\033[0;32m'
18+
RED=$'\033[0;31m'
19+
CYAN=$'\033[;36m'
20+
RESET=$'\033[0m'
21+
fi
22+
if [ "${1}" = false ]; then
23+
GREEN=$'\033[0;0m'
24+
RED=$'\033[0;0m'
25+
CYAN=$'\033[;0m'
26+
RESET=$'\033[0m'
27+
fi
28+
}
29+
setcolors true # normally we want colors
2030

2131
sysconfdir="/etc"
2232
grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
@@ -26,15 +36,16 @@ grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
2636

2737
print_help() {
2838
echo "${CYAN}[?] Usage:"
29-
echo "${0##*/} [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] [-v, --verbose] [-s, --syslog] SNAPSHOTS_DIR"
39+
echo "${0##*/} [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR"
3040
echo
3141
echo "SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto"
3242
echo
3343
echo "Optional arguments:"
34-
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
44+
echo "-c, --no-color Disable colors in output"
3545
echo "-l, --log-file Specify a logfile to write to"
36-
echo "-v, --verbose Let the log of the daemon be more verbose"
3746
echo "-s, --syslog Write to syslog"
47+
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
48+
echo "-v, --verbose Let the log of the daemon be more verbose"
3849
echo "-h, --help Display this message"
3950
echo
4051
echo "Version ${GRUB_BTRFS_VERSION}${RESET}"
@@ -73,10 +84,13 @@ err() {
7384
}
7485

7586
# parse arguments
76-
while getopts :l:tvsh-: opt; do
87+
while getopts :l:ctvsh-: opt; do
7788
case "$opt" in
7889
-)
7990
case "${OPTARG}" in
91+
no-color)
92+
setcolors false
93+
;;
8094
log-file)
8195
logfile="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
8296
;;
@@ -102,6 +116,9 @@ while getopts :l:tvsh-: opt; do
102116
exit 1
103117
;;
104118
esac;;
119+
c)
120+
setcolors false
121+
;;
105122
l)
106123
logfile="${OPTARG}"
107124
;;

manpages/grub-btrfsd.8.man

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,44 @@ when a new btrfs snapshot is created.
99

1010
.SH "SYNOPSIS"
1111
.PP
12-
\fCgrub\-btrfsd [\-h, \-\-help] [\-t, \-\-timeshift\-auto] [\-l, \-\-log\-file LOG_FILE] [\-v, \-\-verbose] [\-s, \-\-syslog] SNAPSHOTS_DIR\fP
12+
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP
1313

1414
.SH "DESCRIPTION"
1515
.PP
16-
Grub-btrfs-openrc is a shell script which is meant to be run as a daemon.
17-
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.
16+
Grub-btrfsd is a shell script which is meant to be run as a daemon.
17+
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.
1818

1919
.SH "OPTIONS"
2020
.SS "\fCSNAPSHOTS_DIR\fP"
2121
.PP
2222
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.
2323
E.g. for Snapper this would be \fC/.snapshots\fP
2424

25-
.SS "\fC\-t / \-\-timeshift\-auto\fP"
25+
.SS "\fC\-c / \-\-no\-color\fP"
2626
.PP
27-
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.
27+
Disable colors in output.
2828

2929
.SS "\fC\-l / \-\-log\-file\fP"
3030
.PP
3131
This arguments specifies a file where grub-btrfsd should write log messages.
3232

33-
.SS "\fC\-h / \-\-help\fP"
33+
.SS "\fC\-s / \-\-syslog\fP"
3434
.PP
35-
Displays a short help message.
35+
Write to syslog
36+
37+
.SS "\fC\-t / \-\-timeshift\-auto\fP"
38+
.PP
39+
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.
3640

3741
.SS "\fC\-v / \-\-verbose\fP"
3842
.PP
3943
Let the log of the daemon be more verbose
4044

41-
.SS "\fC\-s / \-\-syslog\fP"
45+
.SS "\fC\-h / \-\-help\fP"
4246
.PP
43-
Write to syslog
47+
Displays a short help message.
48+
49+
4450

4551
.SH "CONFIGURATION"
4652
.PP

manpages/grub-btrfsd.8.org

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,36 @@ grub-btrfsd - An OpenRC daemon to automatically update the grub menu with
1010
when a new btrfs snapshot is created.
1111

1212
* SYNOPSIS
13-
~grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] [-v, --verbose] [-s, --syslog] SNAPSHOTS_DIR~
13+
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR~
1414

1515
* DESCRIPTION
16-
Grub-btrfs-openrc is a shell script which is meant to be run as a daemon.
17-
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.
16+
Grub-btrfsd is a shell script which is meant to be run as a daemon.
17+
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.
1818

1919
* OPTIONS
2020
** ~SNAPSHOTS_DIR~
2121
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.
2222
E.g. for Snapper this would be ~/.snapshots~
2323

24-
** ~-t / --timeshift-auto~
25-
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.
24+
** ~-c / --no-color~
25+
Disable colors in output.
2626

2727
** ~-l / --log-file~
2828
This arguments specifies a file where grub-btrfsd should write log messages.
2929

30-
** ~-h / --help~
31-
Displays a short help message.
30+
** ~-s / --syslog~
31+
Write to syslog
32+
33+
** ~-t / --timeshift-auto~
34+
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.
3235

3336
** ~-v / --verbose~
3437
Let the log of the daemon be more verbose
3538

36-
** ~-s / --syslog~
37-
Write to syslog
39+
** ~-h / --help~
40+
Displays a short help message.
41+
42+
3843

3944
* CONFIGURATION
4045
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.

0 commit comments

Comments
 (0)