From 897a092b64fc3575f49897e6957b133465b4a333 Mon Sep 17 00:00:00 2001 From: Zeckmathederg Date: Fri, 18 Oct 2024 13:50:25 -0600 Subject: [PATCH] Bash Startup Files: Added. --- introduction/welcome/bash-profile.xml | 285 +++++++++++++++++++++++ introduction/welcome/changelog.xml | 3 + introduction/welcome/welcome.xml | 1 + shareddeps/checkpoint/whatnow.xml | 6 + shareddeps/dps/basicx/x/basic-xorg-7.xml | 30 +-- shareddeps/drivers/rust.xml | 24 +- shareddeps/net/make-ca.xml | 27 +-- 7 files changed, 331 insertions(+), 45 deletions(-) create mode 100644 introduction/welcome/bash-profile.xml diff --git a/introduction/welcome/bash-profile.xml b/introduction/welcome/bash-profile.xml new file mode 100644 index 0000000000..80da36867f --- /dev/null +++ b/introduction/welcome/bash-profile.xml @@ -0,0 +1,285 @@ + + + %general-entities; +]> + + + + + + The Bash Shell Startup Files + + + Bash, or the shell, can source a file at startup that applies for all + users, which can be very helpful for many different purposes. This can + involve setting many useful variables to adding new functionality to the + shell, usually for convenience. This section is therefore recommended and + setting up packages in this book will rely on this section and the created + files. There is little downside to following this section unless you are + not able to copy and paste the following commands, in which case there will + be a lot of typing involved. Doing this in a chroot is recommended before + booting back into your LFS system. + + + + + Most of the instructions below are used to create files located in the + /etc directory structure which + requires you to execute the commands as the root user. If you elect to create the + files in user's home directories instead, you should run the commands + as an unprivileged user. + + + + + + There are more startup files that can be made. The ones here establish + a basic setup while offering convenience. For more startup files, see + BLFS Bash Startup Files. + + + + + + /etc/profile + + + /etc/profile + + + + Here is a base /etc/profile. This file starts by + setting up some helper functions and some basic parameters. It specifies + some bash history parameters and, for security + purposes, disables keeping a permanent history file for the root user. It also sets a default user + prompt. It then calls small, single purpose scripts in the /etc/profile.d directory to provide most + of the initialization. + + + + For more information on the escape sequences you can use for your prompt + (i.e., the PS1 environment variable) see info + bash -- Node: Printing a + Prompt. + + +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 + + + The /etc/profile.d Directory + + + /etc/profile.d + + + + Now create the /etc/profile.d + directory, where the individual initialization scripts are placed: + + +install --directory --mode=0755 --owner=root --group=root /etc/profile.d + + + + + /etc/profile.d/extrapaths.sh + + + /etc/profile.d/extrapaths.sh + + + + This script adds some useful paths to the PATH and + can be used to customize other PATH related environment variables + (e.g. LD_LIBRARY_PATH, etc) that may be needed for all users. + + +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/info INFOPATH +EOF + + + + The man program automatically deduce the search + path for man pages by examining the content of the + PATH variable, see + manpath(5) for + details. Setting the MANPATH variable may override + the automatic deduction, so the BLFS editors do not recommend to + set it. If you must set it for any reason, it's better to start + its value with a colon (:), for example + MANPATH=:/opt/somepkg/share/man:/opt/otherpkg/share/man + so the paths listed in the MANPATH variable will + be appended to the automatically deduced value instead of + overriding it. + + + + + + + /etc/profile.d/umask.sh + + + /etc/profile.d/umask.sh + + + + Setting the umask value is important for security. + Here the default group write permissions are turned off 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 + + + + + + /etc/profile.d/i18n.sh + + + /etc/profile.d/i18n.sh + + + + This script sets an environment variable necessary for + native language support. A full discussion on determining this + variable can be found on the + Configuring the System Locale page. + + +cat > /etc/profile.d/i18n.sh << "EOF" +# Set up i18n variables +for i in $(locale); do + unset ${i%=*} +done + +if [[ "$TERM" = linux ]]; then + export LANG=C.UTF-8 +else + export LANG=<ll>_<CC>.<charmap><@modifiers> +fi +EOF + + + + + + diff --git a/introduction/welcome/changelog.xml b/introduction/welcome/changelog.xml index 51d9a84395..af14d26cd8 100644 --- a/introduction/welcome/changelog.xml +++ b/introduction/welcome/changelog.xml @@ -42,6 +42,9 @@ October 18th, 2024 + + [Zeckmathederg] - Bash Startup Files: Added. + [Zeckmathederg] - wine/*: Added long build time notes. diff --git a/introduction/welcome/welcome.xml b/introduction/welcome/welcome.xml index 0176c2a2f7..57111cc2a0 100644 --- a/introduction/welcome/welcome.xml +++ b/introduction/welcome/welcome.xml @@ -39,5 +39,6 @@ + diff --git a/shareddeps/checkpoint/whatnow.xml b/shareddeps/checkpoint/whatnow.xml index 9dc98f5140..c87d065447 100644 --- a/shareddeps/checkpoint/whatnow.xml +++ b/shareddeps/checkpoint/whatnow.xml @@ -32,6 +32,12 @@ next chapters. + + While you are at it, make sure you have followed + if you have not already as the files in that + section set necessary variables. + + X11 diff --git a/shareddeps/dps/basicx/x/basic-xorg-7.xml b/shareddeps/dps/basicx/x/basic-xorg-7.xml index 0db6f93f0a..1909c4cb38 100644 --- a/shareddeps/dps/basicx/x/basic-xorg-7.xml +++ b/shareddeps/dps/basicx/x/basic-xorg-7.xml @@ -138,45 +138,33 @@ - The instructions below modify the current user's Bash - profile. If you plan on building the packages as the - root user, become that user - and run the following commands. If you want to install packages that - use the above variables both as the - root user and the regular user, - run the following commands for both users. + The instructions below depend on the files created in + . - Create an ~/xorg.sh configuration - file containing these variables: + Create an /etc/profile.d/xorg.sh configuration + file containing these variables as the &root; user: -cat > ~/xorg.sh << EOF +cat > /etc/profile.d/xorg.sh << EOF XORG_PREFIX="$XORG_PREFIX" XORG_CONFIG="--prefix=\$XORG_PREFIX --sysconfdir=/etc --localstatedir=/var --disable-static" export XORG_PREFIX XORG_CONFIG EOF - +chmod 644 /etc/profile.d/xorg.sh There is some confusion about the above 'here' document. The backslash in front of the dollar sign is correct. Bash - will remove it when creating ~/xorg.sh. However, if + will remove it when creating /etc/profile.d/xorg.sh. However, if you are creating the file with an editor, a copy and paste operation will not remove the backslash. It must then be removed manually. - - Now ensure that it will be used in the Bash - profile: - - -echo "source ~/xorg.sh" >> ~/.bash_profile - If you've installed sudo, ensure that XORG_PREFIX and XORG_CONFIG are available @@ -214,7 +202,7 @@ EOF user: -cat >> ~/xorg.sh << "EOF" +cat >> /etc/profile.d/xorg.sh << "EOF" pathappend $XORG_PREFIX/bin PATH pathappend $XORG_PREFIX/lib/pkgconfig PKG_CONFIG_PATH @@ -238,7 +226,7 @@ EOF automatic at login, but to activate it now, run: -source ~/xorg.sh +source /etc/profile.d/xorg.sh You should also add diff --git a/shareddeps/drivers/rust.xml b/shareddeps/drivers/rust.xml index d12e05b935..669916e25e 100644 --- a/shareddeps/drivers/rust.xml +++ b/shareddeps/drivers/rust.xml @@ -459,30 +459,32 @@ mv -v /etc/bash_completion.d/cargo \ is correctly found by other packages and system processes. + + + The following command depends on the files created in + . + + + - Create the ~/rustc.sh file: + Create the /etc/profile.d/rustc.sh startup file as + the &root; user: -cat > ~/rustc.sh << "EOF" -# Begin ~/rustc.sh +cat > /etc/profile.d/rustc.sh << "EOF" +# Begin /etc/profile.d/rustc.sh pathprepend /opt/rustc/bin PATH -# End ~/rustc.sh +# End /etc/profile.d/rustc.sh EOF - - Now ensure the script will be loaded when you are logged in: - - -echo "source ~/rustc.sh" >> ~/.bash_profile - Immediately after installation, update the current PATH for your current shell: - source ~/.bash_profile + source /etc/profile.d/rustc.sh diff --git a/shareddeps/net/make-ca.xml b/shareddeps/net/make-ca.xml index 273583ae92..37b95410cd 100644 --- a/shareddeps/net/make-ca.xml +++ b/shareddeps/net/make-ca.xml @@ -322,25 +322,26 @@ openssl x509 -in class3.crt -text -fingerprint -setalias "CAcert Class 3 root" \ + + + The instructions below depend on the files created in + . + + + - To use the system certificates in Python3 with - the GLFS profiles, add the following variable to your system or personal - profiles: + Now make sure the variable gets set at startup by creating the following + Bash startup file as the &root; user: -cat > ~/pythoncerts.sh << "EOF" -# Begin ~/pythoncerts.sh +cat > /etc/profile.d/pythoncerts.sh << "EOF" +# Begin /etc/profile.d/pythoncerts.sh export _PIP_STANDALONE_CERT=/etc/pki/tls/certs/ca-bundle.crt -# End ~/pythoncerts.sh -EOF - - - Now ensure the script will be loaded when you are logged in: - - -echo "source ~/pythoncerts.sh" >> ~/.bash_profile +# End /etc/profile.d/pythoncerts.sh +EOF +