V8.00.000.2025.06.17
All checks were successful
🛡️ Retrieve DNSSEC status of coresecret.dev. / 🛡️ Retrieve DNSSEC status of coresecret.dev. (push) Successful in 34s
🔁 Render Graphviz Diagrams. / 🔁 Render Graphviz Diagrams. (push) Successful in 24s
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m35s
All checks were successful
🛡️ Retrieve DNSSEC status of coresecret.dev. / 🛡️ Retrieve DNSSEC status of coresecret.dev. (push) Successful in 34s
🔁 Render Graphviz Diagrams. / 🔁 Render Graphviz Diagrams. (push) Successful in 24s
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m35s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
127
lib/1042_arg_parser.sh
Normal file
127
lib/1042_arg_parser.sh
Normal file
@@ -0,0 +1,127 @@
|
||||
#!/bin/bash
|
||||
# SPDX-Version: 3.0
|
||||
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
|
||||
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
|
||||
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
|
||||
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
|
||||
# SPDX-FileType: SOURCE
|
||||
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
|
||||
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
|
||||
# SPDX-PackageName: CISS.debian.installer
|
||||
# SPDX-Security-Contact: security@coresecret.eu
|
||||
|
||||
#######################################
|
||||
# Argument Parser
|
||||
# Globals:
|
||||
# VAR_AUTO_INSTALL
|
||||
# VAR_IN_DIALOG_WR
|
||||
# VAR_PRIORITY
|
||||
# VAR_REIONICE_CLASS
|
||||
# VAR_REIONICE_PRIORITY
|
||||
# Arguments:
|
||||
# None
|
||||
#######################################
|
||||
arg_parser() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
declare argument="${1}"
|
||||
case "${argument,,}" in
|
||||
|
||||
-a | --autoinstall)
|
||||
if [[ -n "${2}" && "${2}" != -* ]]; then arg_mismatch "--autoinstall MUST NOT be followed by an argument."; fi
|
||||
shift 1
|
||||
;;
|
||||
|
||||
-c | --contact)
|
||||
if [[ -n "${2}" && "${2}" != -* ]]; then arg_mismatch "--contact MUST NOT be followed by an argument."; fi
|
||||
shift 1
|
||||
;;
|
||||
|
||||
-d | --debug)
|
||||
shift 1
|
||||
while [[ $# -gt 0 && ! "$1" =~ ^- ]]; do
|
||||
shift 1
|
||||
done
|
||||
;;
|
||||
|
||||
-h | --help)
|
||||
if [[ -n "${2}" && "${2}" != -* ]]; then arg_mismatch "--help MUST NOT be followed by an argument."; fi
|
||||
shift 1
|
||||
;;
|
||||
|
||||
-l | --log)
|
||||
case "${2,,}" in
|
||||
info)
|
||||
declare -gx DEFAULT_LOG_LEVEL="$2"
|
||||
shift 2
|
||||
;;
|
||||
notice)
|
||||
declare -gx DEFAULT_LOG_LEVEL="$2"
|
||||
shift 2
|
||||
;;
|
||||
warn)
|
||||
declare -gx DEFAULT_LOG_LEVEL="$2"
|
||||
shift 2
|
||||
;;
|
||||
error)
|
||||
declare -gx DEFAULT_LOG_LEVEL="$2"
|
||||
shift 2
|
||||
;;
|
||||
emergency)
|
||||
declare -gx DEFAULT_LOG_LEVEL="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
if [[ "${VAR_AUTO_INSTALL}" == false && "${VAR_IN_DIALOG_WR}" == true ]]; then dialog_gauge_cleaner; fi
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
-v | --version)
|
||||
if [[ -n "${2}" && "${2}" != -* ]]; then arg_mismatch "--version MUST NOT be followed by an argument."; fi
|
||||
shift 1
|
||||
;;
|
||||
|
||||
--renice-priority)
|
||||
if [[ -n ${2} && ${2} =~ ^-?[0-9]+$ && ${2} -ge -19 && ${2} -le 19 ]]; then
|
||||
declare -gix VAR_PRIORITY="${2}"
|
||||
shift 2
|
||||
else
|
||||
arg_mismatch "--renice-priority MUST be an integer between '-19' and '19'."
|
||||
fi
|
||||
;;
|
||||
|
||||
--reionice-priority)
|
||||
if [[ -z "${2}" ]]; then
|
||||
arg_mismatch "--reionice-priority no values provided."
|
||||
else
|
||||
if [[ "${2}" =~ ^[1-3]$ ]]; then
|
||||
declare -gix VAR_REIONICE_CLASS="${2}"
|
||||
if [[ -z "${3}" ]]; then
|
||||
:
|
||||
else
|
||||
if [[ "${3}" =~ ^[0-7]$ ]]; then
|
||||
declare -gix VAR_REIONICE_PRIORITY="${3}"
|
||||
else
|
||||
arg_mismatch "--reionice-priority PRIORITY MUST be an integer between '0' and '7'."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
arg_mismatch "--reionice-priority CLASS MUST be an integer between '1' and '3'."
|
||||
fi
|
||||
fi
|
||||
if [[ -n ${VAR_REIONICE_PRIORITY} ]]; then
|
||||
shift 3
|
||||
else
|
||||
shift 2
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
if [[ "${VAR_AUTO_INSTALL}" == false && "${VAR_IN_DIALOG_WR}" == true ]]; then dialog_gauge_cleaner; fi
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
Reference in New Issue
Block a user