rwx/sh/main.sh

96 lines
2.1 KiB
Bash
Raw Normal View History

#! /usr/bin/env sh
2025-06-28 04:36:16 +02:00
# ╭──────╮
# │ main │
# ╰──────╯
2025-07-06 04:21:03 +02:00
# main module
2025-06-28 04:36:16 +02:00
# ╭──────┬───────────╮
# │ main │ constants │
# ╰──────┴───────────╯
2025-07-09 02:20:50 +02:00
# extension of shell modules
RWX_MAIN_EXTENSION="sh"
2025-07-09 02:04:14 +02:00
# name of the entrypoint module
2025-07-09 16:13:16 +02:00
RWX_MAIN_MODULE="main"
2025-07-06 04:21:03 +02:00
# name of the project itself
RWX_SELF_NAME="rwx"
# ╭──────┬───────────╮
# │ main │ variables │
# ╰──────┴───────────╯
2025-07-08 04:35:32 +02:00
# TODO variablize
2025-07-06 20:53:47 +02:00
# system root directory of the project
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
2025-06-28 04:40:19 +02:00
# ╭──────┬──────╮
2025-06-28 04:50:53 +02:00
# │ main │ find │
2025-06-28 04:40:19 +02:00
# ╰──────┴──────╯
2025-07-09 01:04:59 +02:00
# find directory’s shell files
2025-07-08 03:40:08 +02:00
#| find
2025-07-09 02:04:14 +02:00
#| sed
2025-07-08 03:40:08 +02:00
#| sort
2025-07-09 01:04:59 +02:00
rwx_main_find() {
local root="${1}"
2025-07-09 02:04:14 +02:00
find \
2025-06-28 04:50:53 +02:00
"${root}" \
2025-07-09 02:20:50 +02:00
-name "*.${RWX_MAIN_EXTENSION}" \
2025-07-09 02:04:14 +02:00
-type "f" \
2025-06-28 04:50:53 +02:00
-printf "%P\n" |
2025-07-09 02:10:12 +02:00
sed "s|\\.[^.]*\$||" |
sort
2025-06-28 04:50:53 +02:00
}
2025-07-08 01:15:21 +02:00
# ╭──────┬───────╮
# │ main │ shell │
# ╰──────┴───────╯
# test if active shell is in interactive mode
2025-07-09 00:18:57 +02:00
rwx_main_interactive() {
2025-07-08 01:15:21 +02:00
case "${-}" in
*i*) ;;
*) return 1 ;;
esac
}
2025-07-08 01:13:06 +02:00
# ╭──────┬─────╮
# │ main │ log │
# ╰──────┴─────╯
2025-07-08 05:50:46 +02:00
_rwx_main_log() {
2025-07-09 00:18:57 +02:00
if rwx_main_interactive; then
2025-07-08 01:13:06 +02:00
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
echo "${line}"
done
fi
}
2025-07-09 07:26:17 +02:00
# ╭──────┬──────╮
# │ main │ main │
# ╰──────┴──────╯
2025-07-08 01:12:02 +02:00
2025-07-09 07:26:17 +02:00
# run initial steps
#< core/code
rwx_main_main() {
2025-07-09 04:57:58 +02:00
local module modules
2025-07-09 07:26:17 +02:00
# find & source modules
modules="$(rwx_main_find "${RWX_ROOT_SYSTEM}")"
2025-07-08 01:12:02 +02:00
while IFS= read -r module; do
2025-07-09 16:13:16 +02:00
if [ "${module}" != "${RWX_MAIN_MODULE}" ]; then
2025-07-09 02:04:14 +02:00
# shellcheck disable=SC1090
2025-07-09 07:26:17 +02:00
. "${RWX_ROOT_SYSTEM}/${module}.${RWX_MAIN_EXTENSION}"
2025-07-09 02:04:14 +02:00
fi
2025-07-08 01:12:02 +02:00
done <<EOF
${modules}
EOF
2025-07-08 04:35:32 +02:00
# run code main function
2025-07-09 07:26:17 +02:00
rwx_code_main "${modules}" "${@}"
2025-07-08 00:48:18 +02:00
}
# run main function
2025-07-08 05:50:46 +02:00
rwx_main_main "${@}"