2024-11-18 11:41:12 +01:00
|
|
|
SH_NAME="sh"
|
2024-11-20 09:42:44 +01:00
|
|
|
SH_SHELL="$(cat /proc/${$}/comm)"
|
2024-11-18 11:41:12 +01:00
|
|
|
|
|
|
|
SH_ROOT="/etc/${SH_NAME}"
|
|
|
|
SH_USER="${HOME}/${SH_NAME}"
|
|
|
|
|
|
|
|
SH_MAIN="${SH_ROOT}/main.sh"
|
|
|
|
|
|
|
|
[ -n "${ENV}" ] || export ENV="${SH_MAIN}"
|
2024-11-15 16:43:48 +01:00
|
|
|
|
2024-11-25 13:28:42 +01:00
|
|
|
sh_source_check() {
|
|
|
|
local file=".shellcheck.sh"
|
|
|
|
find \
|
|
|
|
-type "f" \
|
|
|
|
-name "*.sh" \
|
2024-11-25 14:06:22 +01:00
|
|
|
-not \
|
|
|
|
-name "${file}" \
|
2024-11-25 13:28:42 +01:00
|
|
|
-printf ". \"%P\"\n" \
|
|
|
|
>"${file}"
|
2024-11-25 13:56:01 +01:00
|
|
|
shellcheck \
|
|
|
|
--check-sourced \
|
|
|
|
"${file}"
|
2024-11-25 13:28:42 +01:00
|
|
|
rm "${file}"
|
|
|
|
}
|
|
|
|
|
2024-11-19 14:11:11 +01:00
|
|
|
_sh_main_commands() {
|
2024-11-17 18:11:25 +01:00
|
|
|
local file="${1}"
|
2024-11-17 21:46:01 +01:00
|
|
|
grep "()" "${file}" |
|
2024-11-17 18:11:25 +01:00
|
|
|
cut --delimiter "(" --fields 1
|
|
|
|
}
|
|
|
|
|
2024-11-20 16:47:41 +01:00
|
|
|
_sh_main_log() {
|
|
|
|
case "${-}" in
|
|
|
|
*i*)
|
|
|
|
local argument
|
|
|
|
for argument in "${@}"; do
|
|
|
|
echo "${argument}"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-11-15 19:06:14 +01:00
|
|
|
main_source_directory() {
|
2024-11-15 19:02:22 +01:00
|
|
|
local path="${1}"
|
|
|
|
if [ -d "${path}" ]; then
|
2024-11-17 18:11:25 +01:00
|
|
|
local cmd count ifs module modules
|
2024-11-15 19:10:40 +01:00
|
|
|
modules="$(find "${path}" \
|
|
|
|
-type "f" \
|
|
|
|
-name "*.sh" \
|
2024-11-25 13:16:24 +01:00
|
|
|
-printf "%P\n" |
|
|
|
|
sort)"
|
2024-11-13 12:41:37 +01:00
|
|
|
ifs="${IFS}"
|
|
|
|
IFS="
|
|
|
|
"
|
2024-11-13 14:55:20 +01:00
|
|
|
count=0
|
2024-11-20 16:47:41 +01:00
|
|
|
_sh_main_log "" \
|
|
|
|
". ${path}"
|
2024-11-13 12:41:37 +01:00
|
|
|
for module in ${modules}; do
|
2024-11-13 14:55:20 +01:00
|
|
|
count=$((count + 1))
|
2024-11-20 15:48:10 +01:00
|
|
|
#printf "%02d" "${count}"
|
2024-11-20 16:47:41 +01:00
|
|
|
_sh_main_log "${module%.sh}"
|
2024-11-15 19:02:22 +01:00
|
|
|
module="${path}/${module}"
|
|
|
|
if [ "${module}" != "${ENV}" ]; then
|
2024-11-12 10:14:08 +01:00
|
|
|
. "${module}"
|
2024-11-19 14:11:11 +01:00
|
|
|
cmd="$(_sh_main_commands "${module}")"
|
2024-11-17 18:17:06 +01:00
|
|
|
if [ -n "${cmd}" ]; then
|
|
|
|
[ -n "${CMD}" ] && CMD="${CMD}
|
|
|
|
"
|
|
|
|
CMD="${CMD}${cmd}"
|
|
|
|
fi
|
2024-11-12 10:14:08 +01:00
|
|
|
fi
|
|
|
|
done
|
2024-11-13 12:41:37 +01:00
|
|
|
IFS="${ifs}"
|
2024-11-12 10:14:08 +01:00
|
|
|
else
|
2024-11-20 16:47:41 +01:00
|
|
|
_sh_main_log "Not a directory: ${path}"
|
2024-11-12 10:14:08 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2023-05-09 22:15:40 +02:00
|
|
|
}
|
2023-05-09 22:09:01 +02:00
|
|
|
|
2024-11-15 19:06:14 +01:00
|
|
|
main_source_file() {
|
2024-11-15 19:02:22 +01:00
|
|
|
local path="${1}"
|
|
|
|
if [ -f "${path}" ]; then
|
2024-11-15 19:11:16 +01:00
|
|
|
main_source_directory "$(dirname "${path}")"
|
2024-11-15 19:02:22 +01:00
|
|
|
else
|
2024-11-20 16:47:41 +01:00
|
|
|
_sh_main_log "Not a file: ${path}"
|
2024-11-15 19:02:22 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-11-21 11:25:40 +01:00
|
|
|
_sh_main() {
|
|
|
|
main_source_file "${ENV}"
|
|
|
|
main_source_directory "${SH_USER}"
|
|
|
|
_sh_main_log "" \
|
|
|
|
"sh_… = shell functions" \
|
|
|
|
"a__… = aliases" \
|
|
|
|
"u__… = user"
|
|
|
|
}
|
2024-11-19 12:32:29 +01:00
|
|
|
|
2024-11-21 11:25:40 +01:00
|
|
|
_sh_main
|