From 8230c3996b8934648078630dbce88be152ffcf6c Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 18 Jan 2018 21:22:09 +0100 Subject: [PATCH] Add bash startup files, fix bash startup - Add startup files - Fix initrd to no leak environment variables - Start bash from initrd as login shell (for now) Signed-off-by: David Oberhollenzer --- pkg/bash/bashrc | 51 ++++++++++++++++++++++++++++++++++++++++++ pkg/bash/build | 4 ++++ pkg/bash/profile | 51 ++++++++++++++++++++++++++++++++++++++++++ pkg/initrd/initrd.skel | 4 +++- 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 pkg/bash/bashrc create mode 100644 pkg/bash/profile diff --git a/pkg/bash/bashrc b/pkg/bash/bashrc new file mode 100644 index 0000000..5fe33a5 --- /dev/null +++ b/pkg/bash/bashrc @@ -0,0 +1,51 @@ +# /etc/bashrc + +# System wide functions and aliases +# Environment stuff goes in /etc/profile + +# Prevent doublesourcing +if [ -z "$BASHRCSOURCED" ]; then + BASHRCSOURCED="Y" + + # are we an interactive shell? + if [ "$PS1" ]; then + shopt -s histappend + shopt -s checkwinsize + history -a + + PROMPT_COMMAND="" + + if test "$UID" = 0 ; then + PS1="\[\033[1;31m\][\u@\h \W]# \[\033[0m\]" + else + PS1="\[\033[0;32m\][\u@\h \W]$ \[\033[0m\]" + fi + fi + + # We're not a login shell + if ! shopt -q login_shell ; then + # By default, we want umask to get set. This sets it for non-login shell. + # Current threshold for system reserved uid/gids is 1000 + if [ $UID -gt 999 ] && [ "`id -gn`" = "`id -un`" ]; then + umask 002 + else + umask 022 + fi + + SHELL=/bin/bash + + # Only display echos from profile.d scripts if we are no login shell + # and interactive - otherwise just process them to set envvars + for i in /etc/profile.d/*.sh; do + if [ -r "$i" ]; then + if [ "$PS1" ]; then + . "$i" + else + . "$i" >/dev/null + fi + fi + done + + unset i + fi +fi diff --git a/pkg/bash/build b/pkg/bash/build index cdc7ffc..e1d6bbd 100755 --- a/pkg/bash/build +++ b/pkg/bash/build @@ -37,4 +37,8 @@ deploy() { mv "$DEPLOY/lib" "$DEVDEPLOY" mv "$DEPLOY/include" "$DEVDEPLOY" + + mkdir -p "$DEPLOY/etc/" + cp "$SCRIPTDIR/pkg/bash/bashrc" "$DEPLOY/etc/" + cp "$SCRIPTDIR/pkg/bash/profile" "$DEPLOY/etc/" } diff --git a/pkg/bash/profile b/pkg/bash/profile new file mode 100644 index 0000000..9235acb --- /dev/null +++ b/pkg/bash/profile @@ -0,0 +1,51 @@ +# /etc/profile + +# System wide environment and startup programs, for login setup +# Functions and aliases go in /etc/bashrc + +if [ -x /bin/id ]; then + if [ -z "$EUID" ]; then + # ksh workaround + EUID=`id -u` + UID=`id -ru` + fi + + USER="`id -un`" + LOGNAME=$USER +fi + +HOSTNAME=$(/bin/cat /etc/hostname) +HISTSIZE=1000 +HISTCONTROL=ignoreboth +PATH=/bin + +export PATH USER LOGNAME HOSTNAME HISTSIZE HISTCONTROL + +# By default, we want umask to get set. This sets it for login shell +# Current threshold for system reserved uid/gids is 1000 +if [ $UID -gt 999 ] && [ "`id -gn`" = "`id -un`" ]; then + umask 002 +else + umask 022 +fi + +for i in /etc/profile.d/*.sh ; do + if [ -r "$i" ]; then + if [ "${-#*i}" != "$-" ]; then + . "$i" + else + . "$i" >/dev/null + fi + fi +done + +unset i + +if [ -n "${BASH_VERSION-}" ] ; then + if [ -f /etc/bashrc ] ; then + # Bash login shells run only /etc/profile + # Bash non-login shells run only /etc/bashrc + # Check for double sourcing is done in /etc/bashrc. + . /etc/bashrc + fi +fi diff --git a/pkg/initrd/initrd.skel b/pkg/initrd/initrd.skel index 5814019..3fdf133 100644 --- a/pkg/initrd/initrd.skel +++ b/pkg/initrd/initrd.skel @@ -107,4 +107,6 @@ umount -l /dev umount /sys umount /proc -exec /bin/busybox switch_root /newroot /bin/bash +unset -v singleuser overlay_dev root root_sfs + +exec /bin/busybox switch_root /newroot /bin/bash --login