From 47c8a75f97f21ae6cffa61e61e62000642f82ab7 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 6 Jan 2022 20:11:05 +0300 Subject: db.sh: add parse_mode function --- links-chmod | 2 +- links-update | 6 +++--- src/db.sh | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/links-chmod b/links-chmod index 9c7a427..8eb8849 100755 --- a/links-chmod +++ b/links-chmod @@ -79,7 +79,7 @@ parse_script_options() { update_shared_dir "$value" ;; -m|--mode) - mode="$value" + mode="$( parse_mode "$value" )" ;; *) script_usage "unrecognized parameter: $key" >&2 diff --git a/links-update b/links-update index 1e1c829..6a802bc 100755 --- a/links-update +++ b/links-update @@ -32,8 +32,6 @@ readonly script_dir src_dir="$( cd -- "$script_dir/src" && pwd )" readonly src_dir -mode='' - . "$src_dir/common.sh" . "$src_dir/os.sh" . "$src_dir/path.sh" @@ -93,7 +91,7 @@ parse_script_options() { update_shared_dir "$value" ;; -m|--mode) - mode="$value" + mode="$( parse_mode "$value" )" ;; *) script_usage "unrecognized parameter: $key" >&2 @@ -103,6 +101,8 @@ parse_script_options() { done } +mode='' + main() { parse_script_options "$@" check_symlinks_enabled diff --git a/src/db.sh b/src/db.sh index d987e85..b057202 100644 --- a/src/db.sh +++ b/src/db.sh @@ -263,6 +263,23 @@ unlink_obsolete_entries() { done } +parse_mode() { + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} MODE" >&2 + return 1 + fi + + local mode="$1" + shift + + if [ -z "$mode" ]; then + dump "mode cannot be empty" >&2 + return 1 + fi + + echo "$mode" +} + chmod_entries() { if [ "$#" -ne 1 ]; then echo "usage: ${FUNCNAME[0]} MODE" >&2 -- cgit v1.2.3