Compare commits
No commits in common. "8fd6beed112754931f3d491241cb75d8f6953029" and "428b3dbe4dce1da16a110ebad52fe08ef369f6fa" have entirely different histories.
8fd6beed11
...
428b3dbe4d
2 changed files with 12 additions and 90 deletions
94
sh/main.sh
94
sh/main.sh
|
@ -37,17 +37,13 @@ RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
||||||
|
|
||||||
# run initial steps
|
# run initial steps
|
||||||
rwx_main() {
|
rwx_main() {
|
||||||
# cache main
|
|
||||||
rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
|
|
||||||
# source system root
|
# source system root
|
||||||
if ! rwx_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
if ! rwx_source "${RWX_ROOT_SYSTEM}"; then
|
||||||
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# source user root
|
# source user root
|
||||||
rwx_source "${RWX_SELF_USER}"
|
rwx_source "${RWX_SELF_USER}"
|
||||||
# parse code cache
|
|
||||||
rwx_parse
|
|
||||||
# context / command
|
# context / command
|
||||||
if [ -n "${RWX_COMMAND_NAME}" ]; then
|
if [ -n "${RWX_COMMAND_NAME}" ]; then
|
||||||
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
|
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
|
||||||
|
@ -57,72 +53,26 @@ rwx_main() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
|
||||||
# │ main │ cache │
|
|
||||||
# ╰──────┴───────╯
|
|
||||||
|
|
||||||
rwx_cache() {
|
|
||||||
local root="${1}"
|
|
||||||
local module="${2}"
|
|
||||||
local name="${module%.sh}"
|
|
||||||
local path="${root}/${module}"
|
|
||||||
local fill text
|
|
||||||
fill="$(rwx_fill "${#name}" ─)"
|
|
||||||
text="$(cat "${path}")"
|
|
||||||
case "${text}" in
|
|
||||||
"#!"*)
|
|
||||||
RWX_CODE="${text}
|
|
||||||
|
|
||||||
# ╭───┬────┬─${fill}─╮
|
|
||||||
# │ ↖ │ sh │ ${name} │
|
|
||||||
# ╰───┴────┴─${fill}─╯"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
RWX_CODE="${RWX_CODE}
|
|
||||||
|
|
||||||
# ╭───┬────┬─${fill}─╮
|
|
||||||
# │ ↙ │ sh │ ${name} │
|
|
||||||
# ╰───┴────┴─${fill}─╯
|
|
||||||
|
|
||||||
${text}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬──────╮
|
|
||||||
# │ main │ fill │
|
|
||||||
# ╰──────┴──────╯
|
|
||||||
|
|
||||||
rwx_fill() {
|
|
||||||
local index="${1}"
|
|
||||||
while [ "${index}" -gt 0 ]; do
|
|
||||||
printf "%s" "${2}"
|
|
||||||
index=$((index - 1))
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬────────╮
|
# ╭──────┬────────╮
|
||||||
# │ main │ source │
|
# │ main │ source │
|
||||||
# ╰──────┴────────╯
|
# ╰──────┴────────╯
|
||||||
|
|
||||||
# source code from file path
|
# source code from file path
|
||||||
rwx_source() {
|
rwx_source() {
|
||||||
local root="${1}"
|
local path="${1}"
|
||||||
[ -d "${root}" ] ||
|
[ -d "${path}" ] ||
|
||||||
return 1
|
return 1
|
||||||
local file="${2}"
|
|
||||||
local count module
|
local count module
|
||||||
count=0
|
count=0
|
||||||
__rwx_log "" \
|
__rwx_log "" \
|
||||||
". ${root}"
|
". ${path}"
|
||||||
rwx_ifs_set
|
rwx_ifs_set
|
||||||
for module in $(rwx_find_shell "${root}" "${file}"); do
|
for module in $(rwx_find_shell "${path}" "${RWX_MAIN_NAME}"); do
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
|
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
|
||||||
|
module="${path}/${module}"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
. "${root}/${module}"
|
. "${module}"
|
||||||
# cache code
|
|
||||||
rwx_cache "${root}" "${module}"
|
|
||||||
done
|
done
|
||||||
rwx_ifs_unset
|
rwx_ifs_unset
|
||||||
}
|
}
|
||||||
|
@ -197,36 +147,6 @@ rwx_find_shell() {
|
||||||
rwx_find_extension "sh" "${@}"
|
rwx_find_extension "sh" "${@}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
|
||||||
# │ main │ parse │
|
|
||||||
# ╰──────┴───────╯
|
|
||||||
|
|
||||||
rwx_parse() {
|
|
||||||
local ws="[[:space:]]*"
|
|
||||||
local start="^${ws}"
|
|
||||||
local constant="[_A-Z][_0-9A-Z]*"
|
|
||||||
local setting="=.*"
|
|
||||||
local fn="${ws}(${ws})${ws}{"
|
|
||||||
local id="[_a-zA-Z][_a-z0-9A-Z]*"
|
|
||||||
local line
|
|
||||||
rwx_ifs_set
|
|
||||||
RWX_CONSTANTS=""
|
|
||||||
for line in $(echo "${RWX_CODE}" |
|
|
||||||
grep "${start}${constant}${setting}" |
|
|
||||||
sed "s|${start}\\(${constant}\\)${setting}|\\1|"); do
|
|
||||||
RWX_CONSTANTS="${RWX_CONSTANTS}${line}
|
|
||||||
"
|
|
||||||
done
|
|
||||||
RWX_FUNCTIONS=""
|
|
||||||
for line in $(echo "${RWX_CODE}" |
|
|
||||||
grep "${start}${id}${fn}" |
|
|
||||||
sed "s|${start}\\(${id}\\)${fn}.*|\\1|"); do
|
|
||||||
RWX_FUNCTIONS="${RWX_FUNCTIONS}${line}
|
|
||||||
"
|
|
||||||
done
|
|
||||||
rwx_ifs_unset
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬─────╮
|
# ╭──────┬─────╮
|
||||||
# │ main │ run │
|
# │ main │ run │
|
||||||
# ╰──────┴─────╯
|
# ╰──────┴─────╯
|
||||||
|
|
|
@ -49,9 +49,11 @@ rwx_remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_root() {
|
rwx_root() {
|
||||||
local user_id
|
if [ "$(id --user)" -eq 0 ]; then
|
||||||
user_id="$(id --user)"
|
return 0
|
||||||
[ "${user_id}" -eq 0 ] || return 1
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_warn_wipe() {
|
rwx_warn_wipe() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue