rwx/sh/main.sh

81 lines
1.9 KiB
Bash
Raw Normal View History

#! /usr/bin/env sh
2025-06-28 04:36:16 +02:00
# ╭──────╮
# │ main │
# ╰──────╯
# ╭──────┬───────────╮
# │ main │ constants │
# ╰──────┴───────────╯
2025-07-09 23:12:57 +02:00
# project parent directory
2025-07-09 16:23:27 +02:00
RWX_MAIN_PARENT="/usr/local/lib"
2025-07-09 23:12:57 +02:00
# project name
2025-07-09 16:42:08 +02:00
RWX_MAIN_NAME="rwx"
2025-07-09 23:12:57 +02:00
# project entrypoint module
2025-07-09 16:42:08 +02:00
RWX_MAIN_MODULE="main"
2025-07-09 23:12:57 +02:00
# shell modules extension
2025-07-09 16:42:08 +02:00
RWX_MAIN_EXTENSION="sh"
# ╭──────┬───────────╮
# │ main │ variables │
# ╰──────┴───────────╯
2025-07-09 23:12:57 +02:00
# project main root directory
2025-07-09 16:35:11 +02:00
rwx_main_root="${RWX_MAIN_PARENT}/${RWX_MAIN_NAME}"
2025-07-10 01:49:19 +02:00
# project main entrypoint file
rwx_main_file="${RWX_MAIN_MODULE}/${RWX_MAIN_EXTENSION}"
# path to the entrypoint main file of the project
rwx_main_path="${rwx_main_root}/${rwx_main_file}"
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-10 22:43:25 +02:00
# FIXME separate in two functions
2025-07-09 23:12:57 +02:00
# find root directory shell modules
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-09 07:26:17 +02:00
# ╭──────┬──────╮
# │ main │ main │
# ╰──────┴──────╯
2025-07-08 01:12:02 +02:00
2025-07-09 23:12:57 +02:00
# run required initial steps
2025-07-09 07:26:17 +02:00
#< core/code
2025-07-10 04:33:43 +02:00
#< core/shell
2025-07-09 07:26:17 +02:00
rwx_main_main() {
2025-07-09 23:12:57 +02:00
local module
local modules
# find main modules
2025-07-09 16:35:11 +02:00
modules="$(rwx_main_find "${rwx_main_root}")"
2025-07-09 23:12:57 +02:00
# source main modules
2025-07-08 01:12:02 +02:00
while IFS= read -r module; do
2025-07-09 23:12:57 +02:00
# except currently running main module
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 16:35:11 +02:00
. "${rwx_main_root}/${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-09 23:12:57 +02:00
# run code module main function with found main modules
2025-07-09 07:26:17 +02:00
rwx_code_main "${modules}" "${@}"
2025-07-10 04:33:43 +02:00
# run shell module main function
rwx_shell_main
2025-07-08 00:48:18 +02:00
}
# run main function
2025-07-08 05:50:46 +02:00
rwx_main_main "${@}"