45 lines
899 B
Bash
45 lines
899 B
Bash
#! /usr/bin/env bash
|
|
|
|
MAIN_USERS_FILE="$(realpath --canonicalize-existing "${BASH_SOURCE[0]}")"
|
|
|
|
main_get_root() {
|
|
dirname "${MAIN_USERS_FILE}"
|
|
}
|
|
|
|
main_link_bashrc() {
|
|
local file="/etc/bash.bashrc"
|
|
rm --force "${file}"
|
|
ln --symbolic "${MAIN_USERS_FILE}" "${file}"
|
|
}
|
|
|
|
# import modules
|
|
main_import_modules() {
|
|
local file="${1}"
|
|
if [ -f "${file}" ]; then
|
|
local ifs module modules path root
|
|
path="$(realpath --canonicalize-existing "${file}")"
|
|
root="$(dirname "${path}")"
|
|
echo
|
|
echo "${root}"
|
|
modules="$(find "${root}" -type "f" -name "*.sh" -printf "%P
|
|
" | sort)"
|
|
ifs="${IFS}"
|
|
IFS="
|
|
"
|
|
for module in ${modules}; do
|
|
echo "${module%.sh}"
|
|
module="${root}/${module}"
|
|
if [ "${module}" != "${path}" ]; then
|
|
. "${module}"
|
|
fi
|
|
done
|
|
IFS="${ifs}"
|
|
return 0
|
|
else
|
|
log_fatal "No file: ${file}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# import modules
|
|
main_import_modules "${MAIN_USERS_FILE}"
|