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() {
sign="$1"
set "${sign}o" errexit
set "${sign}o" nounset
set "${sign}o" pipefail
set_opt() {
local opt="$1"
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() {

15
tori
View file

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