From b21b0df6a666936b48592aa825fe1950d32ff21a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 11 Nov 2012 23:28:52 +0100 Subject: [PATCH] Import bash startfiles from IPFire 3.x. --- config/bash/dot_bash_logout | 7 ++ config/bash/dot_bash_profile | 12 ++++ config/bash/dot_bashrc | 12 ++++ config/etc/bashrc | 116 +++++++++++++++++++++--------- config/etc/inputrc | 56 +++++++-------- config/etc/profile | 112 ++++++++++++++++------------- config/profile.d/colorls.sh | 40 +++++++++++ config/profile.d/dircolors.sh | 9 --- config/profile.d/extrapaths.sh | 15 ---- config/profile.d/i18n.sh | 10 ++- config/profile.d/lang.sh | 90 +++++++++++++++++++++++ config/profile.d/term256.sh | 26 +++++++ config/rootfiles/common/coreutils | 2 +- config/rootfiles/common/stage2 | 9 ++- lfs/coreutils | 2 +- lfs/stage2 | 6 +- 16 files changed, 381 insertions(+), 143 deletions(-) create mode 100644 config/bash/dot_bash_logout create mode 100644 config/bash/dot_bash_profile create mode 100644 config/bash/dot_bashrc create mode 100644 config/profile.d/colorls.sh delete mode 100644 config/profile.d/dircolors.sh delete mode 100644 config/profile.d/extrapaths.sh create mode 100644 config/profile.d/lang.sh create mode 100644 config/profile.d/term256.sh diff --git a/config/bash/dot_bash_logout b/config/bash/dot_bash_logout new file mode 100644 index 000000000..3762d94b5 --- /dev/null +++ b/config/bash/dot_bash_logout @@ -0,0 +1,7 @@ +# Begin ~/.bash_logout + +# Personal items to perform on logout. + +echo "Bye bye." + +# End ~/.bash_logout diff --git a/config/bash/dot_bash_profile b/config/bash/dot_bash_profile new file mode 100644 index 000000000..3dc099a2f --- /dev/null +++ b/config/bash/dot_bash_profile @@ -0,0 +1,12 @@ +# .bash_profile + +# Get the aliases and functions +if [ -f ~/.bashrc ]; then + . ~/.bashrc +fi + +# User specific environment and startup programs + +PATH=$PATH:$HOME/bin + +export PATH diff --git a/config/bash/dot_bashrc b/config/bash/dot_bashrc new file mode 100644 index 000000000..6e6d1e1f1 --- /dev/null +++ b/config/bash/dot_bashrc @@ -0,0 +1,12 @@ +# .bashrc + +# User specific aliases and functions + +alias rm='rm -i' +alias cp='cp -i' +alias mv='mv -i' + +# Source global definitions +if [ -f /etc/bashrc ]; then + . /etc/bashrc +fi diff --git a/config/etc/bashrc b/config/etc/bashrc index fb0c31e08..901f5d57f 100644 --- a/config/etc/bashrc +++ b/config/etc/bashrc @@ -1,41 +1,89 @@ -# Begin /etc/bashrc -# Written for Beyond Linux From Scratch -# by James Robertson -# updated by Bruce Dubbs +# /etc/bashrc -# Make sure that the terminal is set up properly for each shell +# System wide functions and aliases +# Environment stuff goes in /etc/profile -if [ -f /etc/profile.d/tinker-term.sh ]; then - source /etc/profile.d/tinker-term.sh -fi - -# System wide aliases and functions. - -# System wide environment variables and startup programs should go into -# /etc/profile. Personal environment variables and startup programs -# should go into ~/.bash_profile. Personal aliases and functions should -# go into ~/.bashrc +# It's NOT a good idea to change this file unless you know what you +# are doing. It's much better to create a custom.sh shell script in +# /etc/profile.d/ to make custom changes to your environment, as this +# will prevent the need for merging in future updates. -# Provides a colored /bin/ls command. Used in conjunction with code in -# /etc/profile. - -alias ls='ls --color=auto' -alias ll='ls -la' -alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' +# are we an interactive shell? +if [ "$PS1" ]; then + if [ -z "$PROMPT_COMMAND" ]; then + case $TERM in + xterm*) + if [ -e /etc/sysconfig/bash-prompt-xterm ]; then + PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm + else + PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' + fi + ;; + screen) + if [ -e /etc/sysconfig/bash-prompt-screen ]; then + PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen + else + PROMPT_COMMAND='printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' + fi + ;; + *) + [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default + ;; + esac + fi + # Turn on parallel history + shopt -s histappend + history -a + # Turn on checkwinsize + shopt -s checkwinsize + [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ " + # You might want to have e.g. tty in prompt (e.g. more virtual machines) + # and console windows + # If you want to do so, just add e.g. + # if [ "$PS1" ]; then + # PS1="[\u@\h:\l \W]\\$ " + # fi + # to your custom modification shell script in /etc/profile.d/ directory +fi -# Make the shell a little bit more interactive -# to prevent the deletion of some files -alias mv='mv -i' -alias rm='rm -i' -alias cp='cp -i' +if ! shopt -q login_shell ; then # We're not a login shell + # Need to redefine pathmunge, it get's undefined at the end of /etc/profile + pathmunge () { + case ":${PATH}:" in + *:"$1":*) + ;; + *) + if [ "$2" = "after" ] ; then + PATH=$PATH:$1 + else + PATH=$1:$PATH + fi + esac + } -# Provides prompt for non-login shells, specifically shells started -# in the X environment. [Review the LFS archive thread titled -# PS1 Environment Variable for a great case study behind this script -# addendum.] + # By default, we want umask to get set. This sets it for non-login shell. + # Current threshold for system reserved uid/gids is 200 + # You could check uidgid reservation validity in + # /usr/share/doc/setup-*/uidgid file + if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then + umask 002 + else + umask 022 + fi -#export PS1="\033[0m[\033[1;33m\u\033[1;37m@\033[1;32m\]\h \033[1;31m\w\033[0m]\\$ " -export PS1="[\u@\h \w]\\$ " -#export PS1='\u@\h:\w\$ ' + # 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 -# End /etc/bashrc + unset i + unset -f pathmunge +fi +# vim:ts=4:sw=4 diff --git a/config/etc/inputrc b/config/etc/inputrc index 7a7908cc8..883686c59 100644 --- a/config/etc/inputrc +++ b/config/etc/inputrc @@ -1,42 +1,42 @@ -# Begin /etc/inputrc +# do not bell on tab-completion +#set bell-style none -# Allow the command prompt to wrap to the next line -set horizontal-scroll-mode Off +set meta-flag on +set input-meta on +set convert-meta off +set output-meta on -# Enable 8bit input -set meta-flag On -set input-meta On +# Completed names which are symbolic links to +# directories have a slash appended. +set mark-symlinked-directories on -# Turns off 8th bit stripping -set convert-meta Off +$if mode=emacs -# Keep the 8th bit for display -set output-meta On - -# none, visible or audible -set bell-style none - -# All of the following map the escape sequence of the -# value contained inside the 1st argument to the -# readline specific functions - -"\eOd": backward-word -"\eOc": forward-word - -# for linux console +# for linux console and RH/Debian xterm "\e[1~": beginning-of-line "\e[4~": end-of-line -"\e[5~": beginning-of-history -"\e[6~": end-of-history +# commented out keymappings for pgup/pgdown to reach begin/end of history +#"\e[5~": beginning-of-history +#"\e[6~": end-of-history +"\e[5~": history-search-backward +"\e[6~": history-search-forward "\e[3~": delete-char "\e[2~": quoted-insert +"\e[5C": forward-word +"\e[5D": backward-word +"\e[1;5C": forward-word +"\e[1;5D": backward-word -# for xterm +# for rxvt +"\e[8~": end-of-line +"\eOc": forward-word +"\eOd": backward-word + +# for non RH/Debian xterm, can't hurt for RH/DEbian xterm "\eOH": beginning-of-line "\eOF": end-of-line -# for Konsole +# for freebsd console "\e[H": beginning-of-line "\e[F": end-of-line - -# End /etc/inputrc +$endif diff --git a/config/etc/profile b/config/etc/profile index 3c2921908..cc638788a 100644 --- a/config/etc/profile +++ b/config/etc/profile @@ -1,64 +1,76 @@ -# Begin /etc/profile -# Written for Beyond Linux From Scratch -# by James Robertson -# modifications by Dagmar d'Surreal +# /etc/profile -# System wide environment variables and startup programs. +# System wide environment and startup programs, for login setup +# Functions and aliases go in /etc/bashrc -# System wide aliases and functions should go in /etc/bashrc. Personal -# environment variables and startup programs should go into -# ~/.bash_profile. Personal aliases and functions should go into -# ~/.bashrc. +# It's NOT a good idea to change this file unless you know what you +# are doing. It's much better to create a custom.sh shell script in +# /etc/profile.d/ to make custom changes to your environment, as this +# will prevent the need for merging in future updates. -# Functions to help us manage paths. Second argument is the name of the -# path variable to be modified (default: PATH) -pathremove () { - local IFS=':' - local NEWPATH - local DIR - local PATHVARIABLE=${2:-PATH} - for DIR in ${!PATHVARIABLE} ; do - if [ "$DIR" != "$1" ] ; then - NEWPATH=${NEWPATH:+$NEWPATH:}$DIR - fi - done - export $PATHVARIABLE="$NEWPATH" +pathmunge () { + case ":${PATH}:" in + *:"$1":*) + ;; + *) + if [ "$2" = "after" ] ; then + PATH=$PATH:$1 + else + PATH=$1:$PATH + fi + esac } -pathprepend () { - pathremove $1 $2 - local PATHVARIABLE=${2:-PATH} - export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}" -} - -pathappend () { - pathremove $1 $2 - local PATHVARIABLE=${2:-PATH} - export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1" -} +if [ -x /usr/bin/id ]; then + if [ -z "$EUID" ]; then + # ksh workaround + EUID=`id -u` + UID=`id -ru` + fi + USER="`id -un`" + LOGNAME=$USER + MAIL="/var/spool/mail/$USER" +fi -# Set the initial path -export PATH=/bin:/usr/bin +# Path manipulation +if [ "$EUID" = "0" ]; then + pathmunge /usr/sbin + pathmunge /usr/local/sbin +else + pathmunge /usr/local/sbin after + pathmunge /usr/sbin after +fi -if [ $EUID -eq 0 ] ; then - pathappend /sbin:/usr/sbin - unset HISTFILE +HOSTNAME=`/usr/bin/hostname 2>/dev/null` +HISTSIZE=1000 +if [ "$HISTCONTROL" = "ignorespace" ] ; then + export HISTCONTROL=ignoreboth +else + export HISTCONTROL=ignoredups fi -# Setup some environment variables. -export HISTSIZE=1000 -export HISTIGNORE="&:[bf]g:exit" -export PS1="[\u@\h \w]\\$ " -#export PS1='\u@\h:\w\$ ' +export PATH USER LOGNAME MAIL 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 200 +# You could check uidgid reservation validity in +# /usr/share/doc/setup-*/uidgid file +if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then + umask 002 +else + umask 022 +fi -for script in /etc/profile.d/*.sh ; do - if [ -r $script ] ; then - . $script +for i in /etc/profile.d/*.sh ; do + if [ -r "$i" ]; then + if [ "${-#*i}" != "$-" ]; then + . "$i" + else + . "$i" >/dev/null 2>&1 fi + fi done -# Now to clean up -unset pathremove pathprepend pathappend - -# End /etc/profile +unset i +unset pathmunge diff --git a/config/profile.d/colorls.sh b/config/profile.d/colorls.sh new file mode 100644 index 000000000..dc5c22332 --- /dev/null +++ b/config/profile.d/colorls.sh @@ -0,0 +1,40 @@ +# color-ls initialization + +#when USER_LS_COLORS defined do not override user LS_COLORS, but use them. +if [ -z "$USER_LS_COLORS" ]; then + + alias ll='ls -l' 2>/dev/null + alias l.='ls -d .*' 2>/dev/null + + + # Skip the rest for noninteractive shells. + [ -z "$PS1" ] && return + + COLORS= + + for colors in "$HOME/.dir_colors.$TERM" "$HOME/.dircolors.$TERM" \ + "$HOME/.dir_colors" "$HOME/.dircolors"; do + [ -e "$colors" ] && COLORS="$colors" && break + done + + [ -z "$COLORS" ] && [ -e "/etc/DIR_COLORS.256color" ] && \ + [ "x`tty -s && tput colors 2>/dev/null`" = "x256" ] && \ + COLORS="/etc/DIR_COLORS.256color" + + if [ -z "$COLORS" ]; then + for colors in "/etc/DIR_COLORS.$TERM" "/etc/DIR_COLORS" ; do + [ -e "$colors" ] && COLORS="$colors" && break + done + fi + + # Existence of $COLORS already checked above. + [ -n "$COLORS" ] || return + + eval "`dircolors --sh "$COLORS" 2>/dev/null`" + [ -z "$LS_COLORS" ] && return + grep -qi "^COLOR.*none" $COLORS >/dev/null 2>/dev/null && return +fi + +alias ll='ls -l --color=auto' 2>/dev/null +alias l.='ls -d .* --color=auto' 2>/dev/null +alias ls='ls --color=auto' 2>/dev/null diff --git a/config/profile.d/dircolors.sh b/config/profile.d/dircolors.sh deleted file mode 100644 index 873d91b9b..000000000 --- a/config/profile.d/dircolors.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Setup for /bin/ls to support color, the alias is in /etc/bashrc. -if [ -f "/etc/dircolors" ] ; then - eval $(dircolors -b /etc/dircolors) - - if [ -f "$HOME/.dircolors" ] ; then - eval $(dircolors -b $HOME/.dircolors) - fi -fi -alias ls='ls --color=auto' diff --git a/config/profile.d/extrapaths.sh b/config/profile.d/extrapaths.sh deleted file mode 100644 index bb8f72093..000000000 --- a/config/profile.d/extrapaths.sh +++ /dev/null @@ -1,15 +0,0 @@ -if [ -d /usr/local/bin ]; then - pathprepend /usr/local/bin -fi -if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then - pathprepend /usr/local/sbin -fi -for directory in $(find /opt/*/bin -type d 2>/dev/null); do - pathappend $directory -done -if [ -d ~/bin ]; then - pathprepend ~/bin -fi -#if [ $EUID -gt 99 ]; then -# pathappend . -#fi diff --git a/config/profile.d/i18n.sh b/config/profile.d/i18n.sh index ac68d6782..2f66e89c3 100644 --- a/config/profile.d/i18n.sh +++ b/config/profile.d/i18n.sh @@ -1,2 +1,10 @@ # Set up i18n variables -export LANG=en_US.utf8 + +if [ -f "/etc/sysconfig/console" ]; then + . /etc/sysconfig/console +else + LANG=en_US.UTF-8 +fi + +unset KEYMAP FONT UNICODE KEYMAP_CORRECTIONS LEGACY_CHARSET +export LANG diff --git a/config/profile.d/lang.sh b/config/profile.d/lang.sh new file mode 100644 index 000000000..5be62ad81 --- /dev/null +++ b/config/profile.d/lang.sh @@ -0,0 +1,90 @@ +# /etc/profile.d/lang.sh - set i18n stuff + +sourced=0 + +if [ -n "$LANG" ]; then + saved_lang="$LANG" + [ -f "$HOME/.i18n" ] && . "$HOME/.i18n" && sourced=1 + LANG="$saved_lang" + unset saved_lang +else + for langfile in /etc/sysconfig/i18n "$HOME/.i18n" ; do + [ -f $langfile ] && . $langfile && sourced=1 + done +fi + +if [ "$sourced" = 1 ]; then + [ -n "$LANG" ] && export LANG || unset LANG + [ -n "$LC_ADDRESS" ] && export LC_ADDRESS || unset LC_ADDRESS + [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE + [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE + [ -n "$LC_IDENTIFICATION" ] && export LC_IDENTIFICATION || unset LC_IDENTIFICATION + [ -n "$LC_MEASUREMENT" ] && export LC_MEASUREMENT || unset LC_MEASUREMENT + [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES + [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY + [ -n "$LC_NAME" ] && export LC_NAME || unset LC_NAME + [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC + [ -n "$LC_PAPER" ] && export LC_PAPER || unset LC_PAPER + [ -n "$LC_TELEPHONE" ] && export LC_TELEPHONE || unset LC_TELEPHONE + [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME + if [ -n "$LC_ALL" ]; then + if [ "$LC_ALL" != "$LANG" ]; then + export LC_ALL + else + unset LC_ALL + fi + else + unset LC_ALL + fi + [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE + [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS + [ -n "$_XKB_CHARSET" ] && export _XKB_CHARSET || unset _XKB_CHARSET + + consoletype=$CONSOLETYPE + if [ -z "$consoletype" ]; then + consoletype=$(/sbin/consoletype stdout) + fi + + if [ -n "$LANG" ]; then + case $LANG in + *.utf8*|*.UTF-8*) + if [ "$TERM" = "linux" ]; then + if [ "$consoletype" = "vt" ]; then + case $LANG in + ja*) LANG=en_US.UTF-8 ;; + ko*) LANG=en_US.UTF-8 ;; + si*) LANG=en_US.UTF-8 ;; + zh*) LANG=en_US.UTF-8 ;; + ar*) LANG=en_US.UTF-8 ;; + fa*) LANG=en_US.UTF-8 ;; + he*) LANG=en_US.UTF-8 ;; + en_IN*) ;; + *_IN*) LANG=en_US.UTF-8 ;; + esac + fi + fi + ;; + *) + if [ "$TERM" = "linux" ]; then + if [ "$consoletype" = "vt" ]; then + case $LANG in + ja*) LANG=en_US ;; + ko*) LANG=en_US ;; + si*) LANG=en_US ;; + zh*) LANG=en_US ;; + ar*) LANG=en_US ;; + fa*) LANG=en_US ;; + he*) LANG=en_US ;; + en_IN*) ;; + *_IN*) LANG=en_US ;; + esac + fi + fi + ;; + esac + fi + + unset SYSFONTACM SYSFONT consoletype +fi +unset sourced +unset langfile diff --git a/config/profile.d/term256.sh b/config/profile.d/term256.sh new file mode 100644 index 000000000..546f67bcb --- /dev/null +++ b/config/profile.d/term256.sh @@ -0,0 +1,26 @@ +# Enable 256 color capabilities for appropriate terminals + +# Set this variable in your local shell config (such as ~/.bashrc) +# if you want remote xterms connecting to this system, to be sent 256 colors. +# This must be set before reading global initialization such as /etc/bashrc. +# SEND_256_COLORS_TO_REMOTE=1 + +# Terminals with any of the following set, support 256 colors (and are local) +local256="$COLORTERM$XTERM_VERSION$ROXTERM_ID$KONSOLE_DBUS_SESSION" + +if [ -n "$local256" ] || [ -n "$SEND_256_COLORS_TO_REMOTE" ]; then + + case "$TERM" in + 'xterm') TERM=xterm-256color;; + 'screen') TERM=screen-256color;; + 'Eterm') TERM=Eterm-256color;; + esac + export TERM + + if [ -n "$TERMCAP" ] && [ "$TERM" = "screen-256color" ]; then + TERMCAP=$(echo "$TERMCAP" | sed -e 's/Co#8/Co#256/g') + export TERMCAP + fi +fi + +unset local256 diff --git a/config/rootfiles/common/coreutils b/config/rootfiles/common/coreutils index 61e9106af..5b55a3a53 100644 --- a/config/rootfiles/common/coreutils +++ b/config/rootfiles/common/coreutils @@ -20,7 +20,7 @@ bin/sleep bin/sync bin/true bin/uname -etc/dircolors +etc/DIR_COLORS usr/bin/[ usr/bin/basename #usr/bin/cksum diff --git a/config/rootfiles/common/stage2 b/config/rootfiles/common/stage2 index 3d21e4e2a..b01290c5e 100644 --- a/config/rootfiles/common/stage2 +++ b/config/rootfiles/common/stage2 @@ -31,11 +31,11 @@ etc/nsswitch.conf etc/passwd etc/profile #etc/profile.d -etc/profile.d/bashrc.sh -etc/profile.d/dircolors.sh -etc/profile.d/extrapaths.sh +etc/profile.d/colorls.sh etc/profile.d/i18n.sh +etc/profile.d/lang.sh etc/profile.d/readline.sh +etc/profile.d/term256.sh etc/profile.d/umask.sh etc/resolv.conf etc/securetty @@ -51,6 +51,9 @@ media/usbkey mnt #opt #root +root/.bash_logout +root/.bash_profile +root/.bashrc root/ipfire #sbin #srv diff --git a/lfs/coreutils b/lfs/coreutils index c8b4d284b..d0f35c205 100644 --- a/lfs/coreutils +++ b/lfs/coreutils @@ -109,7 +109,7 @@ ifeq "$(ROOT)" "" mv -v /usr/bin/{head,sleep,nice} /bin ln -sf test /bin/[ #ln -sf ../../bin/install /usr/bin - dircolors -p > /etc/dircolors + dircolors -p > /etc/DIR_COLORS else rm /tools/bin/hostname endif diff --git a/lfs/stage2 b/lfs/stage2 index 04291d6e4..43edd8612 100644 --- a/lfs/stage2 +++ b/lfs/stage2 @@ -83,7 +83,11 @@ $(TARGET) : [ -f $$i ] && cp $$i /etc/profile.d; \ done chmod 755 /etc/bashrc - ln -svf ../bashrc /etc/profile.d/bashrc.sh + + # Install root's bash files. + for i in $(DIR_SRC)/config/bash/dot_*; do \ + [ -f $$i ] && cp $$i /root/$$(basename $${i/dot_/\.}); \ + done # Scripts for i in `find $(DIR_SRC)/src/scripts -maxdepth 1 -type f`; do \ -- 2.39.2