added script for post-lfs bash setup
This commit is contained in:
parent
4d28b0a4f3
commit
57b1490701
421
bash-setup.sh
Normal file
421
bash-setup.sh
Normal file
@ -0,0 +1,421 @@
|
||||
#!/bin/bash
|
||||
|
||||
source vars.sh
|
||||
|
||||
mkdir /etc/skel
|
||||
|
||||
echo "Setting up a base /etc/profile"
|
||||
|
||||
cat > /etc/profile << "EOF"
|
||||
# Begin /etc/profile
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
# modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
||||
|
||||
# System wide environment variables and startup programs.
|
||||
|
||||
# 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.
|
||||
|
||||
# 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"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
export -f pathremove pathprepend pathappend
|
||||
|
||||
# Set the initial path
|
||||
export PATH=/usr/bin
|
||||
|
||||
# Attempt to provide backward compatibility with LFS earlier than 11
|
||||
if [ ! -L /bin ]; then
|
||||
pathappend /bin
|
||||
fi
|
||||
|
||||
if [ $EUID -eq 0 ] ; then
|
||||
pathappend /usr/sbin
|
||||
if [ ! -L /sbin ]; then
|
||||
pathappend /sbin
|
||||
fi
|
||||
unset HISTFILE
|
||||
fi
|
||||
|
||||
# Set up some environment variables.
|
||||
export HISTSIZE=1000
|
||||
export HISTIGNORE="&:[bf]g:exit"
|
||||
|
||||
# Set some defaults for graphical systems
|
||||
export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share/}
|
||||
export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg/}
|
||||
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}
|
||||
|
||||
# Set up a red prompt for root and a green one for users.
|
||||
NORMAL="\[\e[0m\]"
|
||||
RED="\[\e[1;31m\]"
|
||||
GREEN="\[\e[1;32m\]"
|
||||
if [[ $EUID == 0 ]] ; then
|
||||
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
||||
else
|
||||
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
||||
fi
|
||||
|
||||
for script in /etc/profile.d/*.sh ; do
|
||||
if [ -r $script ] ; then
|
||||
. $script
|
||||
fi
|
||||
done
|
||||
|
||||
unset script RED GREEN NORMAL
|
||||
|
||||
# End /etc/profile
|
||||
EOF
|
||||
|
||||
echo "Creating the /etc/profile.d directory for individual initialization scripts"
|
||||
|
||||
install --directory --mode=0755 --owner=root --group=root /etc/profile.d
|
||||
|
||||
echo "Installing /etc/profile.d/bash_completion.sh to allow TAB command line completion"
|
||||
|
||||
cat > /etc/profile.d/bash_completion.sh << "EOF"
|
||||
# Begin /etc/profile.d/bash_completion.sh
|
||||
# Import bash completion scripts
|
||||
|
||||
# If the bash-completion package is installed, use its configuration instead
|
||||
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||||
|
||||
# Check for interactive bash and that we haven't already been sourced.
|
||||
if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
|
||||
|
||||
# Check for recent enough version of bash.
|
||||
if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
|
||||
[ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
|
||||
[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
|
||||
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
|
||||
if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
|
||||
# Source completion code.
|
||||
. /usr/share/bash-completion/bash_completion
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
# bash-completions are not installed, use only bash completion directory
|
||||
if shopt -q progcomp; then
|
||||
for script in /etc/bash_completion.d/* ; do
|
||||
if [ -r $script ] ; then
|
||||
. $script
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# End /etc/profile.d/bash_completion.sh
|
||||
EOF
|
||||
|
||||
echo "Installing the required directory"
|
||||
|
||||
install --directory --mode=0755 --owner=root --group=root /etc/bash_completion.d
|
||||
|
||||
echo "Installing /etc/profile.d/dircolors.sh for files to control the colors of file names in a directory listing"
|
||||
|
||||
cat > /etc/profile.d/dircolors.sh << "EOF"
|
||||
# Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
|
||||
if [ -f "/etc/dircolors" ] ; then
|
||||
eval $(dircolors -b /etc/dircolors)
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.dircolors" ] ; then
|
||||
eval $(dircolors -b $HOME/.dircolors)
|
||||
fi
|
||||
|
||||
alias ls='ls --color=auto'
|
||||
alias grep='grep --color=auto'
|
||||
EOF
|
||||
|
||||
echo "Installing /etc/profile.d/extrapaths.sh which adds some useful paths to the PATH and can be used to customize other PATH related environment variables"
|
||||
|
||||
cat > /etc/profile.d/extrapaths.sh << "EOF"
|
||||
if [ -d /usr/local/lib/pkgconfig ] ; then
|
||||
pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
|
||||
fi
|
||||
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
|
||||
|
||||
if [ -d /usr/local/share ]; then
|
||||
pathprepend /usr/local/share XDG_DATA_DIRS
|
||||
fi
|
||||
|
||||
# Set some defaults before other applications add to these paths.
|
||||
pathappend /usr/share/man MANPATH
|
||||
pathappend /usr/share/info INFOPATH
|
||||
EOF
|
||||
|
||||
echo "Installing /etc/profile.d/readline.sh which allows users to define individual settings"
|
||||
|
||||
cat > /etc/profile.d/readline.sh << "EOF"
|
||||
# Set up the INPUTRC environment variable.
|
||||
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
|
||||
INPUTRC=/etc/inputrc
|
||||
fi
|
||||
export INPUTRC
|
||||
EOF
|
||||
|
||||
echo "Installing /etc/profile.d/umask.sh which turns off default group write permissions for system users and when the user name and group name are not the same"
|
||||
|
||||
cat > /etc/profile.d/umask.sh << "EOF"
|
||||
# By default, the umask should be set.
|
||||
if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
|
||||
umask 002
|
||||
else
|
||||
umask 022
|
||||
fi
|
||||
EOF
|
||||
|
||||
echo "Installing /etc/profile.d/i18n.sh which sets an environment variable necessary for native language support"
|
||||
|
||||
cat > /etc/profile.d/i18n.sh << "EOF"
|
||||
# Set up i18n variables
|
||||
. /etc/locale.conf
|
||||
export LANG
|
||||
EOF
|
||||
|
||||
echo "Installing a base /etc/bashrc"
|
||||
|
||||
cat > /etc/bashrc << "EOF"
|
||||
# Begin /etc/bashrc
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
# updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>
|
||||
|
||||
# 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
|
||||
|
||||
# Provides colored /bin/ls and /bin/grep commands. Used in conjunction
|
||||
# with code in /etc/profile.
|
||||
|
||||
alias ls='ls --color=auto'
|
||||
alias grep='grep --color=auto'
|
||||
|
||||
# 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.]
|
||||
|
||||
NORMAL="\[\e[0m\]"
|
||||
RED="\[\e[1;31m\]"
|
||||
GREEN="\[\e[1;32m\]"
|
||||
if [[ $EUID == 0 ]] ; then
|
||||
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
||||
else
|
||||
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
||||
fi
|
||||
|
||||
unset RED GREEN NORMAL
|
||||
|
||||
# End /etc/bashrc
|
||||
EOF
|
||||
|
||||
echo "Installing .bash_profile for the current user and as template for new users"
|
||||
|
||||
cat > ~/.bash_profile << "EOF"
|
||||
# Begin ~/.bash_profile
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
# updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>
|
||||
|
||||
# Personal environment variables and startup programs.
|
||||
|
||||
# Personal aliases and functions should go in ~/.bashrc. System wide
|
||||
# environment variables and startup programs are in /etc/profile.
|
||||
# System wide aliases and functions are in /etc/bashrc.
|
||||
|
||||
if [ -f "$HOME/.bashrc" ] ; then
|
||||
source $HOME/.bashrc
|
||||
fi
|
||||
|
||||
if [ -d "$HOME/bin" ] ; then
|
||||
pathprepend $HOME/bin
|
||||
fi
|
||||
|
||||
# Having . in the PATH is dangerous
|
||||
#if [ $EUID -gt 99 ]; then
|
||||
# pathappend .
|
||||
#fi
|
||||
|
||||
# End ~/.bash_profile
|
||||
EOF
|
||||
|
||||
cat > /etc/skel/.bash_profile << "EOF"
|
||||
# Begin ~/.bash_profile
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
# updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>
|
||||
|
||||
# Personal environment variables and startup programs.
|
||||
|
||||
# Personal aliases and functions should go in ~/.bashrc. System wide
|
||||
# environment variables and startup programs are in /etc/profile.
|
||||
# System wide aliases and functions are in /etc/bashrc.
|
||||
|
||||
if [ -f "$HOME/.bashrc" ] ; then
|
||||
source $HOME/.bashrc
|
||||
fi
|
||||
|
||||
if [ -d "$HOME/bin" ] ; then
|
||||
pathprepend $HOME/bin
|
||||
fi
|
||||
|
||||
# Having . in the PATH is dangerous
|
||||
#if [ $EUID -gt 99 ]; then
|
||||
# pathappend .
|
||||
#fi
|
||||
|
||||
# End ~/.bash_profile
|
||||
EOF
|
||||
|
||||
echo "Installing .profile for the current user and as template for new users"
|
||||
|
||||
cat > ~/.profile << "EOF"
|
||||
# Begin ~/.profile
|
||||
# Personal environment variables and startup programs.
|
||||
|
||||
if [ -d "$HOME/bin" ] ; then
|
||||
pathprepend $HOME/bin
|
||||
fi
|
||||
|
||||
# Set up user specific i18n variables
|
||||
#export LANG=<ll>_<CC>.<charmap><@modifiers>
|
||||
export LANG=LFS_LOCALE
|
||||
|
||||
# End ~/.profile
|
||||
EOF
|
||||
|
||||
sed -i s"/LFS_LOCALE/$LOCALE"/g ~/.profile
|
||||
|
||||
cat > /etc/skel/.profile << "EOF"
|
||||
# Begin ~/.profile
|
||||
# Personal environment variables and startup programs.
|
||||
|
||||
if [ -d "$HOME/bin" ] ; then
|
||||
pathprepend $HOME/bin
|
||||
fi
|
||||
|
||||
# Set up user specific i18n variables
|
||||
#export LANG=<ll>_<CC>.<charmap><@modifiers>
|
||||
export LANG=LFS_LOCALE
|
||||
|
||||
# End ~/.profile
|
||||
EOF
|
||||
|
||||
sed -i s"/LFS_LOCALE/$LOCALE"/g /etc/skel/.profile
|
||||
|
||||
echo "Installing .bashrc for the current user and as template for new users"
|
||||
|
||||
cat > ~/.bashrc << "EOF"
|
||||
# Begin ~/.bashrc
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
|
||||
# Personal aliases and functions.
|
||||
|
||||
# Personal environment variables and startup programs should go in
|
||||
# ~/.bash_profile. System wide environment variables and startup
|
||||
# programs are in /etc/profile. System wide aliases and functions are
|
||||
# in /etc/bashrc.
|
||||
|
||||
if [ -f "/etc/bashrc" ] ; then
|
||||
source /etc/bashrc
|
||||
fi
|
||||
|
||||
# Set up user specific i18n variables
|
||||
#export LANG=<ll>_<CC>.<charmap><@modifiers>
|
||||
export LANG=LFS_LOCALE
|
||||
|
||||
# End ~/.bashrc
|
||||
EOF
|
||||
|
||||
sed -i s"/LFS_LOCALE/$LOCALE"/g ~/.bashrc
|
||||
|
||||
cat > /etc/skel/.bashrc << "EOF"
|
||||
# Begin ~/.bashrc
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
|
||||
# Personal aliases and functions.
|
||||
|
||||
# Personal environment variables and startup programs should go in
|
||||
# ~/.bash_profile. System wide environment variables and startup
|
||||
# programs are in /etc/profile. System wide aliases and functions are
|
||||
# in /etc/bashrc.
|
||||
|
||||
if [ -f "/etc/bashrc" ] ; then
|
||||
source /etc/bashrc
|
||||
fi
|
||||
|
||||
# Set up user specific i18n variables
|
||||
#export LANG=<ll>_<CC>.<charmap><@modifiers>
|
||||
export LANG=LFS_LOCALE
|
||||
|
||||
# End ~/.bashrc
|
||||
EOF
|
||||
|
||||
sed -i s"/LFS_LOCALE/$LOCALE"/g /etc/skel/.bashrc
|
||||
|
||||
echo "Installing .bash_logout for the current user and as template for new users"
|
||||
|
||||
cat > ~/.bash_logout << "EOF"
|
||||
# Begin ~/.bash_logout
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
|
||||
# Personal items to perform on logout.
|
||||
|
||||
# End ~/.bash_logout
|
||||
EOF
|
||||
|
||||
cat > /etc/skel/.bash_logout << "EOF"
|
||||
# Begin ~/.bash_logout
|
||||
# Written for Beyond Linux From Scratch
|
||||
# by James Robertson <jameswrobertson@earthlink.net>
|
||||
|
||||
# Personal items to perform on logout.
|
||||
|
||||
# End ~/.bash_logout
|
||||
EOF
|
||||
|
||||
echo "Installing a configuration for the dircolors capability"
|
||||
|
||||
dircolors -p > /etc/dircolors
|
@ -1160,4 +1160,6 @@ cat > /etc/systemd/coredump.conf.d/maxuse.conf << EOF
|
||||
MaxUse=5G
|
||||
EOF
|
||||
|
||||
echo "Optionally run bash-setup.sh to set up a basic configuration regarding the shell prompt and colors etc"
|
||||
echo "bash bash-setup.sh"
|
||||
echo "Continue with chapter 10.2. Creating the /etc/fstab File"
|
||||
|
Loading…
x
Reference in New Issue
Block a user