From 7e1357144f8baea6b22deac7e69ef7087e14bb21 Mon Sep 17 00:00:00 2001 From: Tobias Powalowski Date: Wed, 1 Feb 2023 14:46:33 +0100 Subject: [PATCH] apply normal bash setup to archboot environment with /root/.bash* files --- .../archboot/installer/autoconfiguration.sh | 30 ++++--------------- usr/lib/initcpio/install/archboot_base_common | 23 +++++++------- .../base/etc/profile.d/custom-bash-aliases.sh | 14 --------- .../base/etc/profile.d/custom-bash-history.sh | 9 ------ .../base/etc/profile.d/custom-bash-options.sh | 24 +++++++++++++++ .../base/etc/profile.d/custom-bash-prompt.sh | 14 --------- 6 files changed, 43 insertions(+), 71 deletions(-) delete mode 100644 usr/share/archboot/base/etc/profile.d/custom-bash-aliases.sh delete mode 100644 usr/share/archboot/base/etc/profile.d/custom-bash-history.sh create mode 100644 usr/share/archboot/base/etc/profile.d/custom-bash-options.sh delete mode 100644 usr/share/archboot/base/etc/profile.d/custom-bash-prompt.sh diff --git a/usr/lib/archboot/installer/autoconfiguration.sh b/usr/lib/archboot/installer/autoconfiguration.sh index 0751717b3..13f1439d8 100644 --- a/usr/lib/archboot/installer/autoconfiguration.sh +++ b/usr/lib/archboot/installer/autoconfiguration.sh @@ -231,30 +231,12 @@ _auto_nano_syntax() { _auto_bash(){ if [[ ! -f ${_DESTDIR}/etc/profile.d/custom-bash-prompt.sh ]]; then - _dialog --infobox "Enable custom bash prompt on installed system..." 3 70 - ! grep -qw 'custom-bash-prompt.sh' "${_DESTDIR}/etc/skel/.bashrc" &&\ - echo ". /etc/profile.d/custom-bash-prompt.sh" >> "${_DESTDIR}/etc/skel/.bashrc" - ! grep -qw 'custom-bash-prompt.sh' "${_DESTDIR}/root/.bashrc" &&\ - echo ". /etc/profile.d/custom-bash-prompt.sh" >> "${_DESTDIR}/root/.bashrc" - cp /etc/profile.d/custom-bash-prompt.sh "${_DESTDIR}"/etc/profile.d/ - sleep 2 - fi - if [[ ! -f ${_DESTDIR}/etc/profile.d/custom-bash-aliases.sh ]]; then - _dialog --infobox "Enable custom bash aliases on installed system..." 3 70 - ! grep -qw 'custom-bash-aliases.sh' "${_DESTDIR}/etc/skel/.bashrc" &&\ - echo ". /etc/profile.d/custom-bash-aliases.sh" >> "${_DESTDIR}/etc/skel/.bashrc" - ! grep -qw 'custom-bash-aliases.sh' "${_DESTDIR}/root/.bashrc" &&\ - echo ". /etc/profile.d/custom-bash-aliases.sh" >> "${_DESTDIR}/root/.bashrc" - cp /etc/profile.d/custom-bash-aliases.sh "${_DESTDIR}"/etc/profile.d/ - sleep 2 - fi - if [[ ! -f ${_DESTDIR}/etc/profile.d/custom-bash-history.sh ]]; then - _dialog --infobox "Enable custom bash history on installed system..." 3 70 - ! grep -qw 'custom-bash-history.sh' "${_DESTDIR}/etc/skel/.bashrc" &&\ - echo ". /etc/profile.d/custom-bash-history.sh" >> "${_DESTDIR}/etc/skel/.bashrc" - ! grep -qw 'custom-bash-history.sh' "${_DESTDIR}/root/.bashrc" &&\ - echo ". /etc/profile.d/custom-bash-history.sh" >> "${_DESTDIR}/root/.bashrc" - cp /etc/profile.d/custom-bash-history.sh "${_DESTDIR}"/etc/profile.d/ + _dialog --infobox "Enable custom bash options on installed system..." 3 70 + ! grep -qw 'custom-bash-options.sh' "${_DESTDIR}/etc/skel/.bashrc" &&\ + echo ". /etc/profile.d/custom-bash-options.sh" >> "${_DESTDIR}/etc/skel/.bashrc" + ! grep -qw 'custom-bash-options.sh' "${_DESTDIR}/root/.bashrc" &&\ + echo ". /etc/profile.d/custom-bash-options.sh" >> "${_DESTDIR}/root/.bashrc" + cp /etc/profile.d/custom-bash-options.sh "${_DESTDIR}"/etc/profile.d/ sleep 2 fi } diff --git a/usr/lib/initcpio/install/archboot_base_common b/usr/lib/initcpio/install/archboot_base_common index 2dff881f8..92bc5f69d 100644 --- a/usr/lib/initcpio/install/archboot_base_common +++ b/usr/lib/initcpio/install/archboot_base_common @@ -8,7 +8,7 @@ build () add_checked_modules 'virtio|zram|btrfs|libcrc32|zstd|sg|pkcs8_key_parser' ### setting up base structure - map add_dir "/mnt" "/install" "/var/log" "/home" "/var/tmp" + map add_dir "/root /mnt" "/install" "/var/log" "/home" "/var/tmp" add_symlink /var/run ../run add_symlink /var/lock ../run/lock @@ -50,7 +50,7 @@ build () map add_file "/etc/profile" "/etc/shells" basic_config="os-release hostname modprobe.d/modprobe.conf" for i in $basic_config; do - add_file "/usr/share/archboot/base/etc/$i" "/etc/$i" + add_file "/usr/share/archboot/base/etc/${i}" "/etc/${i}" done ### add bash configuration @@ -60,14 +60,17 @@ build () # use color bash prompt # unlock and delete root password, if not set by user! # use color grep and ls output - for i in custom-bash-prompt.sh archboot-reset-root-password.sh \ - custom-bash-aliases.sh custom-bash-history.sh; do - add_file "/usr/share/archboot/base/etc/profile.d/$i" "/etc/profile.d/$i" + for i in custom-bash-options.sh archboot-reset-root-password.sh; do + add_file "/usr/share/archboot/base/etc/profile.d/${i}" "/etc/profile.d/${i}" done - echo ". /etc/profile.d/custom-bash-prompt.sh" >> "$BUILDROOT/etc/bash.bashrc" - echo ". /etc/profile.d/custom-bash-aliases.sh" >> "$BUILDROOT/etc/bash.bashrc" - echo ". /etc/profile.d/custom-bash-history.sh" >> "$BUILDROOT/etc/bash.bashrc" - + # add default bash setup + for i in .bashrc .bash_profile .bash_logout; do + add_file "/etc/skel/${i}" "$BUILDROOT/root/${i}" + done + # add custom bash options + echo ". /etc/profile.d/custom-bash-options.sh" >> "$BUILDROOT/root/.bashrc" + # add /etc/skel + add_full_dir /etc/skel ### add kmod related config file(s) add_file "/usr/lib/depmod.d/search.conf" @@ -125,7 +128,7 @@ build () map add_file "/usr/lib/libnss_compat.so.2" "/usr/lib/libnsl.so.1" ## fix for systemd >=245 set default.target # remove initrd-release to allow normal systemd boot without initrd.target - rm -f /tmp/*/root/etc/initrd-release + rm -f $BUILDROOT/etc/initrd-release add_symlink "/etc/systemd/system/default.target" "/usr/lib/systemd/system/multi-user.target" # mask systemd-gpt-auto-generator, errors out on initramfs usage add_symlink "/etc/systemd/system-generators/systemd-gpt-auto-generator" "/dev/null" diff --git a/usr/share/archboot/base/etc/profile.d/custom-bash-aliases.sh b/usr/share/archboot/base/etc/profile.d/custom-bash-aliases.sh deleted file mode 100644 index 8788fe501..000000000 --- a/usr/share/archboot/base/etc/profile.d/custom-bash-aliases.sh +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# created by Tobias Powalowski -# check on bash -[[ -n "${BASH_VERSION:-}" ]] || return -# Not an interactive shell? -[[ $- == *i* ]] || return -# color output -alias ls='ls --color=auto' -alias grep='grep --color=auto' -# set neovim as default editor -alias vi='nvim' -alias vim='nvim' -alias edit='nvim' - diff --git a/usr/share/archboot/base/etc/profile.d/custom-bash-history.sh b/usr/share/archboot/base/etc/profile.d/custom-bash-history.sh deleted file mode 100644 index d9524a6f8..000000000 --- a/usr/share/archboot/base/etc/profile.d/custom-bash-history.sh +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# created by Tobias Powalowski -# check on bash -[[ -n "${BASH_VERSION:-}" ]] || return -# Not an interactive shell? -[[ $- == *i* ]] || return -# keep history clean from dups and spaces -HISTCONTROL="erasedups:ignorespace" - diff --git a/usr/share/archboot/base/etc/profile.d/custom-bash-options.sh b/usr/share/archboot/base/etc/profile.d/custom-bash-options.sh new file mode 100644 index 000000000..11d512422 --- /dev/null +++ b/usr/share/archboot/base/etc/profile.d/custom-bash-options.sh @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-only +# created by Tobias Powalowski +# check on bash +[[ -n "${BASH_VERSION:-}" ]] || return +# Not an interactive shell? +[[ $- == *i* ]] || return +# keep history clean from dups and spaces +[[ $- == *i* ]] || return +if [[ "${UID}" == 0 ]]; then + # red for root user, host green, print full working dir + PS1='[\e[1;31m\u\e[m@\e[1;32m\h\e[m \w]\$ ' +else + # blue for normal user,host green, print full working dir + PS1='[\e[1;34m\u\e[m@\e[1;32m\h\e[m \w]\$ ' +fi +HISTCONTROL="erasedups:ignorespace" +# color output +alias grep='grep --color=auto' +# if installed set neovim as default editor +if command -v nvim 2&1>/dev/null; then + alias vi='nvim' + alias vim='nvim' + alias edit='nvim' +fi diff --git a/usr/share/archboot/base/etc/profile.d/custom-bash-prompt.sh b/usr/share/archboot/base/etc/profile.d/custom-bash-prompt.sh deleted file mode 100644 index 27db13637..000000000 --- a/usr/share/archboot/base/etc/profile.d/custom-bash-prompt.sh +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# created by Tobias Powalowski -# check on bash -[[ -n "${BASH_VERSION:-}" ]] || return -# Not an interactive shell? -[[ $- == *i* ]] || return -if [[ "${UID}" == 0 ]]; then - # red for root user - PS1='[\e[1;31m\u\e[m@\e[1;32m\h\e[m \w]\$ ' -else - # blue for normal user - PS1='[\e[1;34m\u\e[m@\e[1;32m\h\e[m \w]\$ ' -fi -