Skip to content

Commit aea2b0a

Browse files
authored
#423 remove unneeded log messages (#435)
* Refactor error handling to logging functions
1 parent 85589d7 commit aea2b0a

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

‎41_snapshots-btrfs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
4444
[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config"
4545
[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub"
4646

47-
## Error Handling
47+
## Logging
48+
print_info()
49+
{
50+
printf "grub-btrfs: %s\n" "$*" >&2
51+
}
52+
53+
print_warning()
54+
{
55+
printf "grub-btrfs: Warning: %s\n" "$*" >&2
56+
}
57+
4858
print_error()
4959
{
50-
local err_msg="$*"
5160
local bug_report="If you think an error has occurred, please file a bug report at \"https://github.com/Antynea/grub-btrfs\""
52-
printf "%s\n" "${err_msg}" "${bug_report}" >&2 ;
61+
printf "grub-btrfs: Error: %s\n" "$*" "${bug_report}" >&2
5362
exit 0
5463
}
5564

@@ -75,10 +84,10 @@ while getopts :V-: opt; do
7584
done
7685

7786
## Exit the script, if:
78-
[ "$(echo "$GRUB_BTRFS_DISABLE" | tr '[:upper:]' '[:lower:]')" = 'true' ] && print_error "GRUB_BTRFS_DISABLE is set to true (default=false)"
79-
if ! type btrfs >/dev/null 2>&1; then print_error "btrfs-progs isn't installed"; fi
87+
[ "$(echo "$GRUB_BTRFS_DISABLE" | tr '[:upper:]' '[:lower:]')" = 'true' ] && { print_info "GRUB_BTRFS_DISABLE is set to true (default=false)"; exit 0; }
88+
if ! type btrfs >/dev/null 2>&1; then print_info "btrfs-progs isn't installed"; exit 0; fi
8089
[ -f "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" ] && . "${GRUB_BTRFS_MKCONFIG_LIB:-/usr/share/grub/grub-mkconfig_lib}" || print_error "grub-mkconfig_lib couldn't be found"
81-
[[ "$(btrfs filesystem df / 2>&1)" == *"not a btrfs filesystem"* ]] && print_error "Root filesystem isn't btrfs"
90+
[[ "$(btrfs filesystem df / 2>&1)" == *"not a btrfs filesystem"* ]] && { print_info "Root filesystem isn't btrfs"; exit 0; }
8291

8392
printf "Detecting snapshots ...\n" >&2 ;
8493

@@ -686,7 +695,7 @@ fi
686695
# if no snapshot found, delete the "$grub_btrfs_directory/grub-btrfs.new" file and the "$grub_btrfs_directory/grub-btrfs.cfg.bkp" file and exit
687696
if [ "${count_limit_snap}" = "0" ] || [ -z "${count_limit_snap}" ]; then
688697
rm -f "$grub_btrfs_directory/grub-btrfs.new" "$grub_btrfs_directory/grub-btrfs.cfg.bkp"
689-
print_error "No snapshots found."
698+
print_info "No snapshots found."; exit 0
690699
fi
691700
# Move "grub-btrfs.new" to "grub-btrfs.cfg"
692701
header_menu

0 commit comments

Comments
 (0)