Check for shell option support before setting

This commit is contained in:
Juno Takano 2024-07-18 10:10:18 -03:00
parent 18af77ba26
commit 4566955440
2 changed files with 22 additions and 11 deletions

View file

@ -16,9 +16,21 @@ log() {
set_opts() { set_opts() {
sign="$1" sign="$1"
set "${sign}o" errexit set_opt() {
set "${sign}o" nounset local opt="$1"
set "${sign}o" pipefail
if set -o | grep -q "^$opt[[:space:]]"; then
set "${sign}o" "$opt"
log debug "[set_opts] Set: $(set -o | grep -q "^$opt[[:space:]]")"
else
log fatal "Unsupported shell: no $opt option support"
return 1
fi
}
set_opt errexit
set_opt nounset
set_opt pipefail
} }
prepare_directories() { prepare_directories() {

15
tori
View file

@ -2,17 +2,13 @@
main() { main() {
# paths # paths
VERSION="0.4.1 2024-07-14" VERSION="0.5.0 2024-07-18"
TORI_ROOT="$HOME/.local/share/tori" TORI_ROOT="$HOME/.local/share/tori"
CONFIG_ROOT="$HOME/.config/tori" CONFIG_ROOT="$HOME/.config/tori"
TMP_DIR="/tmp/tori" TMP_DIR="/tmp/tori"
CACHE_DIR="$HOME/.cache/tori" CACHE_DIR="$HOME/.cache/tori"
check_core_paths # os-independent state
. "$TORI_ROOT/src/index.sh"
# state
DEBUG=$DEBUG DEBUG=$DEBUG
@ -20,13 +16,16 @@ main() {
argument="$1" argument="$1"
parameter="$2" parameter="$2"
# import source
check_core_paths
. "$TORI_ROOT/src/index.sh"
set_opts - set_opts -
## global constants ## os-dependent state
OS="$(get_operating_system)" OS="$(get_operating_system)"
PACKAGE_CACHE="$CACHE_DIR/${OS}_packages.cache" PACKAGE_CACHE="$CACHE_DIR/${OS}_packages.cache"
## global state
base_files= base_files=
bkp_files= bkp_files=
user_packages= user_packages=