95 lines
2.1 KiB
Bash
Executable file
95 lines
2.1 KiB
Bash
Executable file
#! /usr/bin/env sh
|
|
# ╭──────╮
|
|
# │ main │
|
|
# ╰──────╯
|
|
# main module
|
|
|
|
# ╭──────┬───────────╮
|
|
# │ main │ constants │
|
|
# ╰──────┴───────────╯
|
|
|
|
# extension of shell modules
|
|
RWX_MAIN_EXTENSION="sh"
|
|
|
|
# name of the entrypoint module
|
|
RWX_MAIN_NAME="main"
|
|
# name of the project itself
|
|
RWX_SELF_NAME="rwx"
|
|
|
|
# ╭──────┬───────────╮
|
|
# │ main │ variables │
|
|
# ╰──────┴───────────╯
|
|
|
|
# TODO variablize
|
|
# system root directory of the project
|
|
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
|
|
|
# ╭──────┬──────╮
|
|
# │ main │ find │
|
|
# ╰──────┴──────╯
|
|
|
|
# find directory’s shell files
|
|
#| find
|
|
#| sed
|
|
#| sort
|
|
rwx_main_find() {
|
|
local root="${1}"
|
|
find \
|
|
"${root}" \
|
|
-name "*.${RWX_MAIN_EXTENSION}" \
|
|
-type "f" \
|
|
-printf "%P\n" |
|
|
sed "s|\\.[^.]*\$||" |
|
|
sort
|
|
}
|
|
|
|
# ╭──────┬───────╮
|
|
# │ main │ shell │
|
|
# ╰──────┴───────╯
|
|
|
|
# test if active shell is in interactive mode
|
|
rwx_main_interactive() {
|
|
case "${-}" in
|
|
*i*) ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
# ╭──────┬─────╮
|
|
# │ main │ log │
|
|
# ╰──────┴─────╯
|
|
|
|
_rwx_main_log() {
|
|
if rwx_main_interactive; then
|
|
[ ${#} -gt 0 ] || set -- ""
|
|
local line
|
|
for line in "${@}"; do
|
|
echo "${line}"
|
|
done
|
|
fi
|
|
}
|
|
|
|
# ╭──────┬──────╮
|
|
# │ main │ main │
|
|
# ╰──────┴──────╯
|
|
|
|
# run initial steps
|
|
#< core/code
|
|
rwx_main_main() {
|
|
local module modules
|
|
# find & source modules
|
|
modules="$(rwx_main_find "${RWX_ROOT_SYSTEM}")"
|
|
while IFS= read -r module; do
|
|
if [ "${module}" != "${RWX_MAIN_NAME}" ]; then
|
|
# shellcheck disable=SC1090
|
|
. "${RWX_ROOT_SYSTEM}/${module}.${RWX_MAIN_EXTENSION}"
|
|
fi
|
|
done <<EOF
|
|
${modules}
|
|
EOF
|
|
# run code main function
|
|
rwx_code_main "${modules}" "${@}"
|
|
}
|
|
|
|
# run main function
|
|
rwx_main_main "${@}"
|