diff --git a/startup.sh b/startup.sh index 4bc58ac..f4ce4b4 100755 --- a/startup.sh +++ b/startup.sh @@ -2,9 +2,19 @@ # 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 @@ -14,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 @@ -23,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"