2024-12-02 14:24:27 +00:00
|
|
|
# ╭──────┬──────────╮
|
|
|
|
# │ self │ commands │
|
|
|
|
# ╰──────┴──────────╯
|
|
|
|
|
2024-12-01 20:22:35 +00:00
|
|
|
# get commands from root
|
|
|
|
rwx_self_commands() {
|
|
|
|
grep \
|
|
|
|
--directories "recurse" \
|
|
|
|
--no-filename \
|
2024-12-01 20:48:04 +00:00
|
|
|
"^${RWX_SELF_COMMAND}" "${RWX_ROOT_SYSTEM}" |
|
2024-12-01 20:22:35 +00:00
|
|
|
cut --delimiter "(" --fields 1 |
|
2024-12-01 20:48:04 +00:00
|
|
|
sed "s|^${RWX_SELF_COMMAND}||"
|
2024-12-01 20:22:35 +00:00
|
|
|
}
|
|
|
|
|
2024-12-02 14:24:27 +00:00
|
|
|
# ╭──────┬───────────╮
|
|
|
|
# │ self │ functions │
|
|
|
|
# ╰──────┴───────────╯
|
|
|
|
|
2024-12-01 20:22:35 +00:00
|
|
|
# get functions from root
|
2024-11-29 23:10:16 +00:00
|
|
|
rwx_self_functions() {
|
|
|
|
grep \
|
|
|
|
--directories "recurse" \
|
|
|
|
--no-filename \
|
|
|
|
"()" "${RWX_ROOT_SYSTEM}" |
|
|
|
|
cut --delimiter "(" --fields 1
|
|
|
|
}
|
|
|
|
|
2024-12-02 14:24:27 +00:00
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ self │ help │
|
|
|
|
# ╰──────┴──────╯
|
|
|
|
|
2024-11-29 21:54:00 +00:00
|
|
|
# output help message
|
|
|
|
rwx_self_help() {
|
|
|
|
rwx_log \
|
|
|
|
"rwx_… = functions" \
|
|
|
|
" a__… = aliases" \
|
|
|
|
" u__… = user"
|
|
|
|
}
|
2024-12-01 17:58:27 +00:00
|
|
|
|
2024-12-02 14:24:27 +00:00
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ self │ init │
|
|
|
|
# ╰──────┴──────╯
|
|
|
|
|
|
|
|
rwx_self_init() {
|
|
|
|
# run interactive extras
|
|
|
|
if rwx_shell_interactive; then
|
|
|
|
# check format
|
|
|
|
rwx_log
|
|
|
|
rwx_shfmt "${RWX_ROOT_SYSTEM}"
|
|
|
|
# check syntax
|
|
|
|
rwx_log
|
|
|
|
rwx_shellcheck "${RWX_ROOT_SYSTEM}"
|
|
|
|
# help
|
|
|
|
rwx_log
|
|
|
|
rwx_self_help
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬─────────╮
|
|
|
|
# │ self │ install │
|
|
|
|
# ╰──────┴─────────╯
|
|
|
|
|
2024-12-01 21:28:22 +00:00
|
|
|
_rwx_cmd_rwx_install() { rwx_self_install "${@}"; }
|
2024-12-01 17:58:27 +00:00
|
|
|
rwx_self_install() {
|
|
|
|
local target="${1}"
|
2024-12-01 20:37:55 +00:00
|
|
|
local command file
|
|
|
|
# commands
|
|
|
|
local root="${target}/usr/local/bin"
|
|
|
|
for command in $(rwx_self_commands); do
|
|
|
|
file="${root}/${command}"
|
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
|
|
|
done
|
2024-12-01 17:58:27 +00:00
|
|
|
# sh
|
|
|
|
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
|
2024-12-01 18:06:44 +00:00
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_file_write "${file}" "export ENV=\"${RWX_MAIN_PATH}\""
|
2024-12-01 17:58:27 +00:00
|
|
|
# bash
|
|
|
|
file="/etc/bash.bashrc"
|
2024-12-01 18:06:44 +00:00
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
2024-12-01 17:58:27 +00:00
|
|
|
}
|
2024-12-01 23:06:42 +00:00
|
|
|
|
2024-12-02 14:24:27 +00:00
|
|
|
# ╭──────┬────────╮
|
|
|
|
# │ self │ subset │
|
|
|
|
# ╰──────┴────────╯
|
|
|
|
|
2024-12-01 23:06:42 +00:00
|
|
|
rwx_self_subset() {
|
|
|
|
local argument path
|
|
|
|
for argument in "${@}"; do
|
|
|
|
path="${RWX_ROOT_SYSTEM}/${argument}"
|
|
|
|
if [ -d "${path}" ]; then
|
2024-12-01 23:30:01 +00:00
|
|
|
local file
|
|
|
|
for file in $(rwx_find_shell "${path}"); do
|
|
|
|
echo "${argument}/${file}"
|
|
|
|
done
|
2024-12-01 23:06:42 +00:00
|
|
|
elif [ -f "${path}" ]; then
|
|
|
|
echo "${argument}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-12-02 14:24:27 +00:00
|
|
|
# ╭──────┬───────╮
|
|
|
|
# │ self │ write │
|
|
|
|
# ╰──────┴───────╯
|
|
|
|
|
2024-12-01 23:06:42 +00: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-01 23:30:01 +00:00
|
|
|
$(cat "${RWX_ROOT_SYSTEM}/${file}")
|
|
|
|
"
|
2024-12-01 23:06:42 +00:00
|
|
|
done
|
|
|
|
rwx_ifs_unset
|
|
|
|
rwx_file_write "${target}" "${text}"
|
2024-12-01 23:39:16 +00:00
|
|
|
rwx_shfmt "${target}"
|
2024-12-01 23:46:30 +00:00
|
|
|
rwx_shellcheck_file "${target}"
|
2024-12-01 23:06:42 +00:00
|
|
|
fi
|
|
|
|
}
|