Compare commits
9 commits
428b3dbe4d
...
2a9169947e
Author | SHA1 | Date | |
---|---|---|---|
2a9169947e | |||
bb8bedae27 | |||
2a6bfab4f9 | |||
72200668a9 | |||
12561ee505 | |||
94689a23bf | |||
8c55351aae | |||
ebc41e8a53 | |||
706847f746 |
2 changed files with 58 additions and 12 deletions
62
sh/main.sh
62
sh/main.sh
|
@ -37,8 +37,10 @@ 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}"; then
|
if ! rwx_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
||||||
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -53,26 +55,72 @@ 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 path="${1}"
|
local root="${1}"
|
||||||
[ -d "${path}" ] ||
|
[ -d "${root}" ] ||
|
||||||
return 1
|
return 1
|
||||||
|
local file="${2}"
|
||||||
local count module
|
local count module
|
||||||
count=0
|
count=0
|
||||||
__rwx_log "" \
|
__rwx_log "" \
|
||||||
". ${path}"
|
". ${root}"
|
||||||
rwx_ifs_set
|
rwx_ifs_set
|
||||||
for module in $(rwx_find_shell "${path}" "${RWX_MAIN_NAME}"); do
|
for module in $(rwx_find_shell "${root}" "${file}"); 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
|
||||||
. "${module}"
|
. "${root}/${module}"
|
||||||
|
# cache code
|
||||||
|
rwx_cache "${root}" "${module}"
|
||||||
done
|
done
|
||||||
rwx_ifs_unset
|
rwx_ifs_unset
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,9 @@ rwx_remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_root() {
|
rwx_root() {
|
||||||
if [ "$(id --user)" -eq 0 ]; then
|
local user_id
|
||||||
return 0
|
user_id="$(id --user)"
|
||||||
else
|
[ "${user_id}" -eq 0 ] || return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_warn_wipe() {
|
rwx_warn_wipe() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue