From 14f12a7778a3195d8d1ff56e46c05860ee9e5912 Mon Sep 17 00:00:00 2001 From: nephros Date: Fri, 26 May 2023 11:01:25 +0200 Subject: [PATCH 1/5] remove superfluous 'else' --- src/tools/patchmanager-tool | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/tools/patchmanager-tool b/src/tools/patchmanager-tool index 3a2907ae..aae8a5c7 100644 --- a/src/tools/patchmanager-tool +++ b/src/tools/patchmanager-tool @@ -63,13 +63,11 @@ case "$1" in operation="-a" shift surplus "$*" + if [ -r $PM_CONF ] && [ -s $PM_CONF ] && [ -f $PM_CONF ]; then + patchlist="$(grep '^applied=' $PM_CONF | cut -s -d "=" -f 2- | tr ',[:blank:]' ' ' | tr -s ' ')" else - if [ -r $PM_CONF ] && [ -s $PM_CONF ] && [ -f $PM_CONF ]; then - patchlist="$(grep '^applied=' $PM_CONF | cut -s -d "=" -f 2- | tr ',[:blank:]' ' ' | tr -s ' ')" - else - printf 'File "%s" does not exist, is empty, not readable or not a regular file!\n' $PM_CONF >&2 - exit 2 - fi + printf 'File "%s" does not exist, is empty, not readable or not a regular file!\n' $PM_CONF >&2 + exit 2 fi ;; -d|-u|--deactivate) From 9a233b04d5b6d483e31a4bd4e8c7552b01cbe0a3 Mon Sep 17 00:00:00 2001 From: nephros Date: Fri, 26 May 2023 11:02:35 +0200 Subject: [PATCH 2/5] add missing 'else/fi' --- src/tools/patchmanager-tool | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/patchmanager-tool b/src/tools/patchmanager-tool index aae8a5c7..cba66d9c 100644 --- a/src/tools/patchmanager-tool +++ b/src/tools/patchmanager-tool @@ -116,9 +116,11 @@ case "$1" in grep '^applied=' $PM_CONF | cut -s -d "=" -f 2- > "$filepath" exit 0 fi + else surplus "$*" printf '%s\n' "$(grep '^applied=' $PM_CONF | cut -s -d "=" -f 2-)" exit 0 + fi ;; -h|--help) usage From b8283f37e1d281aec458dc25f2737443df5b7d2d Mon Sep 17 00:00:00 2001 From: nephros Date: Fri, 26 May 2023 11:08:53 +0200 Subject: [PATCH 3/5] guard against unassigned/unbound variable (set -u) --- src/tools/patchmanager-tool | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/tools/patchmanager-tool b/src/tools/patchmanager-tool index cba66d9c..793413d8 100644 --- a/src/tools/patchmanager-tool +++ b/src/tools/patchmanager-tool @@ -101,26 +101,28 @@ case "$1" in ;; -e|--export) shift - if [ "$1" = "-f" ] || [ "$1" = "--file" ]; then - shift - filepath="$1" - shift - surplus "$*" - if [ ! -w $(dirname "$filepath") ]; then - printf 'Cannot write to given directory: %s\n' "$filepath" >&2 - exit 2 - elif [ -e "$filepath" ]; then - printf 'File %s exists, will not overwrite.\n' "$filepath" >&2 - exit 2 - else - grep '^applied=' $PM_CONF | cut -s -d "=" -f 2- > "$filepath" - exit 0 + if [ $# -ge 1 ]; then + if [ "$1" = "-f" ] || [ "$1" = "--file" ]; then + shift + filepath="$1" + shift + surplus "$*" + if [ ! -w $(dirname "$filepath") ]; then + printf 'Cannot write to given directory: %s\n' "$filepath" >&2 + exit 2 + elif [ -e "$filepath" ]; then + printf 'File %s exists, will not overwrite.\n' "$filepath" >&2 + exit 2 + else + grep '^applied=' $PM_CONF | cut -s -d "=" -f 2- > "$filepath" + exit 0 + fi fi - else - surplus "$*" - printf '%s\n' "$(grep '^applied=' $PM_CONF | cut -s -d "=" -f 2-)" - exit 0 - fi + else + surplus "$*" + printf '%s\n' "$(grep '^applied=' $PM_CONF | cut -s -d "=" -f 2-)" + exit 0 + fi ;; -h|--help) usage From c64e83fca798ca76dd65fb4d824230e8962b88cb Mon Sep 17 00:00:00 2001 From: nephros Date: Fri, 26 May 2023 11:13:54 +0200 Subject: [PATCH 4/5] fail on unknown parameter --- src/tools/patchmanager-tool | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/patchmanager-tool b/src/tools/patchmanager-tool index 793413d8..d21c6bb9 100644 --- a/src/tools/patchmanager-tool +++ b/src/tools/patchmanager-tool @@ -117,6 +117,9 @@ case "$1" in grep '^applied=' $PM_CONF | cut -s -d "=" -f 2- > "$filepath" exit 0 fi + else + printf 'Unknown parameter: %s.\nIf you meant to export to a file, use "--export --file %s"\n' "$1" "$1" >&2 + exit 1 fi else surplus "$*" From 1a013d95c26b3f813fc31e5bfe6315ee1bca3af8 Mon Sep 17 00:00:00 2001 From: olf Date: Sat, 27 May 2023 04:16:27 +0200 Subject: [PATCH 5/5] [patchmanager-tool] Rectify indentation --- src/tools/patchmanager-tool | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/patchmanager-tool b/src/tools/patchmanager-tool index d21c6bb9..1dfc3ae5 100644 --- a/src/tools/patchmanager-tool +++ b/src/tools/patchmanager-tool @@ -118,8 +118,8 @@ case "$1" in exit 0 fi else - printf 'Unknown parameter: %s.\nIf you meant to export to a file, use "--export --file %s"\n' "$1" "$1" >&2 - exit 1 + printf 'Unknown parameter: %s.\nIf you meant to export to a file, use "--export --file %s"\n' "$1" "$1" >&2 + exit 1 fi else surplus "$*"