2024-06-30 06:14:49 +02:00
|
|
|
# utility functions
|
|
|
|
|
|
|
|
log() {
|
2024-07-11 17:03:03 +02:00
|
|
|
local level="$1"
|
|
|
|
local message="$2"
|
|
|
|
|
|
|
|
if [ $level = fatal ]; then
|
|
|
|
printf "[tori] $(date "+%H:%M:%S"): $message\n" 1>&2
|
|
|
|
elif [ $level = user ]; then
|
|
|
|
printf "[tori] $(date "+%H:%M:%S"): $message\n" 1>&2
|
|
|
|
elif [ -n "$DEBUG" ] && [ $level = debug ]; then
|
|
|
|
printf "$(date "+%H:%M:%N") $message\n" 1>&2
|
|
|
|
fi
|
2024-06-30 06:14:49 +02:00
|
|
|
}
|
|
|
|
|
2024-07-07 21:15:44 +02:00
|
|
|
set_opts() {
|
|
|
|
sign="$1"
|
|
|
|
|
|
|
|
set "${sign}o" errexit
|
|
|
|
set "${sign}o" nounset
|
|
|
|
set "${sign}o" pipefail
|
|
|
|
}
|
|
|
|
|
2024-06-30 06:14:49 +02:00
|
|
|
prepare_directories() {
|
2024-07-11 17:03:03 +02:00
|
|
|
if ! [ -d "$TMP_DIR" ]; then
|
|
|
|
mkdir "$TMP_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -d "$CACHE_DIR" ]; then
|
|
|
|
mkdir -p "$CACHE_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -d "$CONFIG_ROOT" ]; then
|
|
|
|
log fatal "Configuration root not found at $CONFIG_ROOT"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-06-30 06:14:49 +02:00
|
|
|
}
|
|
|
|
|
2024-07-07 20:31:28 +02:00
|
|
|
print_help() {
|
2024-07-11 17:03:03 +02:00
|
|
|
printf "\n tori: configuration managent and system replication tool\n"
|
|
|
|
printf "\n Options:\n\n"
|
|
|
|
printf "\tcheck\t\tcompare configuration to system state\n"
|
|
|
|
printf "\tcache\t\trefresh the local package cache\n"
|
|
|
|
printf "\n"
|
|
|
|
printf "\tversion\t\tprint current version with release date\n"
|
|
|
|
printf "\thelp\t\tshow this help text\n"
|
2024-07-13 22:22:02 +02:00
|
|
|
printf "\n See 'man tori' or https://tori.jutty.dev/docs for more help\n\n"
|
2024-07-07 20:31:28 +02:00
|
|
|
}
|