Update homedir detection & config creation code
This commit is contained in:
parent
2f72de023c
commit
82a527b9c7
1 changed files with 19 additions and 3 deletions
22
startup.sh
22
startup.sh
|
@ -2,9 +2,19 @@
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
set -eo pipefail
|
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"
|
echo ":: Can't cd into ${HOME:?}/.bashrc.d"
|
||||||
exit 1
|
${BASHRCD_FALLBACK}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialize basic stuff
|
# Initialize basic stuff
|
||||||
|
@ -14,7 +24,11 @@ cd "${HOME:?}/.bashrc.d" || (
|
||||||
[[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh"
|
[[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh"
|
||||||
|
|
||||||
# Create new configuration file
|
# 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
|
#!/usr/bin/env bash
|
||||||
CONFIG_FLOW_CONTROL=0
|
CONFIG_FLOW_CONTROL=0
|
||||||
CONFIG_AUTOSAVE_HISTORY=1
|
CONFIG_AUTOSAVE_HISTORY=1
|
||||||
|
@ -23,6 +37,8 @@ CONFIG_EDITOR=nano
|
||||||
CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman
|
CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman
|
||||||
CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru
|
CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Load configuration file
|
# Load configuration file
|
||||||
source "config.sh"
|
source "config.sh"
|
||||||
|
|
Loading…
Reference in a new issue