Compare commits

...

2 commits

Author SHA1 Message Date
82a527b9c7
Update homedir detection & config creation code 2024-06-03 02:10:47 +02:00
2f72de023c
Safety++ 2024-06-03 02:10:23 +02:00

View file

@ -1,9 +1,20 @@
#!/usr/bin/env bash
# shellcheck disable=SC2154
set -eo pipefail
cd "${HOME:?}/.bashrc.d" || (
# Define variables
export "BASHRCD_FALLBACK=exec env --ignore-environment bash --norc --noprofile"
if [ -z "${BASHRCD_SYSTEM}" ]; then
export "BASHRCD_HOMEDIR=${HOME:?}/.bashrc.d"
else
export "BASHRCD_HOMEDIR=/etc/bashrc.d"
fi
# cd into to home directory
cd "${BASHRCD_HOMEDIR}" || (
echo ":: Can't cd into ${HOME:?}/.bashrc.d"
exit 1
${BASHRCD_FALLBACK}
)
# Initialize basic stuff
@ -13,7 +24,11 @@ cd "${HOME:?}/.bashrc.d" || (
[[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh"
# Create new configuration file
[[ ! -f "config.sh" ]] && $(which cat) << EOF >> config.sh
if [ ! -f "config.sh" ]; then
if [ -n "${BASHRCD_SYSTEM}" ] && [ "${UID}" != "0" ]; then
echo ":: Warning: Can't create system-wide configuration file as normal user."
else
$(which cat) << EOF >> config.sh
#!/usr/bin/env bash
CONFIG_FLOW_CONTROL=0
CONFIG_AUTOSAVE_HISTORY=1
@ -22,6 +37,8 @@ CONFIG_EDITOR=nano
CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman
CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru
EOF
fi
fi
# Load configuration file
source "config.sh"
@ -62,3 +79,5 @@ for file in startup.d/*; do
# shellcheck disable=SC1090
source "${file}"
done
set +eo pipefail