grub-btrfs: print version of the script with --version

Close #225

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
This commit is contained in:
Pascal Jäger
2022-11-21 08:59:06 +01:00
parent 1969132073
commit 33810a9274
3 changed files with 36 additions and 1 deletions

21
41_snapshots-btrfs Normal file → Executable file
View File

@@ -51,6 +51,27 @@ print_error()
exit 0
}
# parse arguments
while getopts :V-: opt; do
case "$opt" in
-)
case "${OPTARG}" in
version)
printf "Version %s\n" "${GRUB_BTRFS_VERSION}" >&2 ;
exit 0
;;
esac;;
V)
printf "Version %s\n" "${GRUB_BTRFS_VERSION}" >&2 ;
exit 0
;;
*)
printf "Unknown flag, exiting...\n"
exit 0
;;
esac
done
## Exit the script, if:
[[ "${GRUB_BTRFS_DISABLE,,}" == "true" ]] && print_error "GRUB_BTRFS_DISABLE is set to true (default=false)"
if ! type btrfs >/dev/null 2>&1; then print_error "btrfs-progs isn't installed"; fi

2
config
View File

@@ -1,5 +1,7 @@
#!/usr/bin/env bash
GRUB_BTRFS_VERSION=4.11-20221121
# Disable grub-btrfs.
# Default: "false"
#GRUB_BTRFS_DISABLE="true"

View File

@@ -18,6 +18,12 @@ RED=$'\033[0;31m'
CYAN=$'\033[;36m'
RESET=$'\033[0m'
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"
print_help() {
echo "${CYAN}[?] Usage:"
echo "${0##*/} [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] [-v, --verbose] [-s, --syslog] SNAPSHOTS_DIR"
@@ -29,7 +35,9 @@ print_help() {
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 "-h, --help Display this message${RESET}"
echo "-h, --help Display this message"
echo
echo "Version ${GRUB_BTRFS_VERSION}${RESET}"
}
log() {
@@ -81,6 +89,10 @@ while getopts :l:tvsh-: opt; do
syslog)
syslog=true
;;
help)
print_help
exit 0
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
err "[!] Unknown option --${OPTARG}" "${RED}" >&2