2025-01-13 07:02:35 +01:00
|
|
|
# meta doc
|
|
|
|
rwx_doc() {
|
|
|
|
local name="${1}"
|
|
|
|
[ -n "${name}" ] || return
|
|
|
|
local doc line module
|
|
|
|
rwx_ifs_set
|
|
|
|
for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do
|
|
|
|
while read -r line; do
|
|
|
|
case "${line}" in
|
2025-01-13 07:44:14 +01:00
|
|
|
"#"*) doc="${doc}${line}" ;;
|
|
|
|
"${name}() {")
|
|
|
|
echo "${doc}"
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
*) doc="" ;;
|
2025-01-13 07:02:35 +01:00
|
|
|
esac
|
2025-01-13 07:44:14 +01:00
|
|
|
done <"${RWX_ROOT_SYSTEM}/${module}"
|
2025-01-13 07:02:35 +01:00
|
|
|
done
|
|
|
|
rwx_ifs_unset
|
|
|
|
}
|
|
|
|
|
2024-12-22 23:51:32 +01:00
|
|
|
# ╭──────┬───────╮
|
|
|
|
# │ self │ check │
|
|
|
|
# ╰──────┴───────╯
|
|
|
|
|
|
|
|
# check source code
|
|
|
|
rwx_self_check() {
|
|
|
|
# check format
|
|
|
|
rwx_log
|
|
|
|
rwx_shfmt "${RWX_ROOT_SYSTEM}"
|
|
|
|
# check syntax
|
|
|
|
rwx_log
|
|
|
|
rwx_shellcheck "${RWX_ROOT_SYSTEM}"
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:24:27 +01:00
|
|
|
# ╭──────┬──────────╮
|
|
|
|
# │ self │ commands │
|
|
|
|
# ╰──────┴──────────╯
|
|
|
|
|
2024-12-01 21:22:35 +01:00
|
|
|
# get commands from root
|
|
|
|
rwx_self_commands() {
|
|
|
|
grep \
|
|
|
|
--directories "recurse" \
|
|
|
|
--no-filename \
|
2024-12-01 21:48:04 +01:00
|
|
|
"^${RWX_SELF_COMMAND}" "${RWX_ROOT_SYSTEM}" |
|
2024-12-01 21:22:35 +01:00
|
|
|
cut --delimiter "(" --fields 1 |
|
2024-12-01 21:48:04 +01:00
|
|
|
sed "s|^${RWX_SELF_COMMAND}||"
|
2024-12-01 21:22:35 +01:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:24:27 +01:00
|
|
|
# ╭──────┬───────────╮
|
|
|
|
# │ self │ functions │
|
|
|
|
# ╰──────┴───────────╯
|
|
|
|
|
2024-12-01 21:22:35 +01:00
|
|
|
# get functions from root
|
2024-11-30 00:10:16 +01:00
|
|
|
rwx_self_functions() {
|
|
|
|
grep \
|
|
|
|
--directories "recurse" \
|
|
|
|
--no-filename \
|
|
|
|
"()" "${RWX_ROOT_SYSTEM}" |
|
|
|
|
cut --delimiter "(" --fields 1
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:24:27 +01:00
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ self │ help │
|
|
|
|
# ╰──────┴──────╯
|
|
|
|
|
2024-11-29 22:54:00 +01:00
|
|
|
# output help message
|
|
|
|
rwx_self_help() {
|
|
|
|
rwx_log \
|
|
|
|
"rwx_… = functions" \
|
|
|
|
" a__… = aliases" \
|
|
|
|
" u__… = user"
|
|
|
|
}
|
2024-12-01 18:58:27 +01:00
|
|
|
|
2024-12-02 15:24:27 +01:00
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ self │ init │
|
|
|
|
# ╰──────┴──────╯
|
|
|
|
|
|
|
|
rwx_self_init() {
|
|
|
|
# run interactive extras
|
|
|
|
if rwx_shell_interactive; then
|
|
|
|
# help
|
|
|
|
rwx_log
|
|
|
|
rwx_self_help
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬─────────╮
|
|
|
|
# │ self │ install │
|
|
|
|
# ╰──────┴─────────╯
|
|
|
|
|
2024-12-01 22:28:22 +01:00
|
|
|
_rwx_cmd_rwx_install() { rwx_self_install "${@}"; }
|
2024-12-01 18:58:27 +01:00
|
|
|
rwx_self_install() {
|
|
|
|
local target="${1}"
|
2024-12-08 22:37:36 +01:00
|
|
|
local command file root
|
|
|
|
# code
|
2025-01-12 17:04:28 +01:00
|
|
|
if [ -n "${target}" ]; then
|
|
|
|
root="${target}${RWX_ROOT_SYSTEM}"
|
|
|
|
rwx_remove "${root}"
|
|
|
|
cp --recursive "${RWX_ROOT_SYSTEM}" "${root}"
|
|
|
|
fi
|
2024-12-01 21:37:55 +01:00
|
|
|
# commands
|
2024-12-08 22:37:36 +01:00
|
|
|
root="${target}/usr/local/bin"
|
2024-12-01 21:37:55 +01:00
|
|
|
for command in $(rwx_self_commands); do
|
|
|
|
file="${root}/${command}"
|
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
|
|
|
done
|
2024-12-01 18:58:27 +01:00
|
|
|
# sh
|
|
|
|
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
|
2024-12-01 19:06:44 +01:00
|
|
|
rwx_remove "${file}"
|
2024-12-08 21:57:14 +01:00
|
|
|
rwx_file_write "${file}" "\
|
|
|
|
export ENV=\"${RWX_MAIN_PATH}\"
|
|
|
|
"
|
2024-12-01 18:58:27 +01:00
|
|
|
# bash
|
2024-12-08 21:51:24 +01:00
|
|
|
file="${target}/etc/bash.bashrc"
|
2024-12-01 19:06:44 +01:00
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
2024-12-01 18:58:27 +01:00
|
|
|
}
|
2024-12-02 00:06:42 +01:00
|
|
|
|
2024-12-02 15:24:27 +01:00
|
|
|
# ╭──────┬────────╮
|
|
|
|
# │ self │ subset │
|
|
|
|
# ╰──────┴────────╯
|
|
|
|
|
2024-12-02 00:06:42 +01:00
|
|
|
rwx_self_subset() {
|
|
|
|
local argument path
|
|
|
|
for argument in "${@}"; do
|
|
|
|
path="${RWX_ROOT_SYSTEM}/${argument}"
|
|
|
|
if [ -d "${path}" ]; then
|
2024-12-02 00:30:01 +01:00
|
|
|
local file
|
|
|
|
for file in $(rwx_find_shell "${path}"); do
|
|
|
|
echo "${argument}/${file}"
|
|
|
|
done
|
2024-12-02 00:06:42 +01:00
|
|
|
elif [ -f "${path}" ]; then
|
|
|
|
echo "${argument}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:24:27 +01:00
|
|
|
# ╭──────┬───────╮
|
|
|
|
# │ self │ write │
|
|
|
|
# ╰──────┴───────╯
|
|
|
|
|
2024-12-02 00:06:42 +01:00
|
|
|
rwx_self_write() {
|
|
|
|
local target="${1}"
|
|
|
|
if [ -n "${target}" ]; then
|
|
|
|
shift
|
|
|
|
local file text
|
|
|
|
text="#! /usr/bin/env sh
|
|
|
|
"
|
|
|
|
rwx_ifs_set
|
|
|
|
for file in $(rwx_self_subset "${@}"); do
|
|
|
|
text="${text}
|
2024-12-02 00:30:01 +01:00
|
|
|
$(cat "${RWX_ROOT_SYSTEM}/${file}")
|
|
|
|
"
|
2024-12-02 00:06:42 +01:00
|
|
|
done
|
|
|
|
rwx_ifs_unset
|
|
|
|
rwx_file_write "${target}" "${text}"
|
2024-12-02 00:39:16 +01:00
|
|
|
rwx_shfmt "${target}"
|
2024-12-02 00:46:30 +01:00
|
|
|
rwx_shellcheck_file "${target}"
|
2024-12-02 00:06:42 +01:00
|
|
|
fi
|
|
|
|
}
|