[ab4fdfc] | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
[6732c094] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[f8d632ac] | 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
[78b3cd61] | 8 | <sect1 id="postlfs-config-profile" xreflabel="The Bash Shell Startup Files">
|
---|
[2753b70b] | 9 | <?dbhtml filename="profile.html"?>
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | <title>The Bash Shell Startup Files</title>
|
---|
| 13 |
|
---|
[81a73ed8] | 14 | <para>
|
---|
| 15 | The shell program <filename>/bin/bash</filename> (hereafter referred to
|
---|
| 16 | as just "the shell") uses a collection of startup files to help create
|
---|
| 17 | an environment. Each file has a specific use and may affect login and
|
---|
| 18 | interactive environments differently. The files in the <filename
|
---|
| 19 | class="directory">/etc</filename> directory generally provide global
|
---|
| 20 | settings. If an equivalent file exists in your home directory it may
|
---|
| 21 | override the global settings.
|
---|
| 22 | </para>
|
---|
| 23 |
|
---|
| 24 | <para>
|
---|
| 25 | An interactive login shell is started after a successful login, using
|
---|
| 26 | <filename>/bin/login</filename>, by reading the
|
---|
| 27 | <filename>/etc/passwd</filename> file. This shell invocation normally reads
|
---|
| 28 | <filename>/etc/profile</filename> and its private equivalent
|
---|
| 29 | <filename>~/.bash_profile</filename> (or <filename>~/.profile</filename>
|
---|
| 30 | if called as <command>/bin/sh</command>) upon startup.
|
---|
[8558044] | 31 | </para>
|
---|
[81a73ed8] | 32 |
|
---|
| 33 | <para>
|
---|
| 34 | An interactive non-login shell is normally started at the command-line
|
---|
| 35 | using a shell program (e.g.,
|
---|
| 36 | <prompt>[prompt]$</prompt><command>/bin/bash</command>) or by the
|
---|
| 37 | <command>/bin/su</command> command. An interactive non-login shell is also
|
---|
| 38 | started with a terminal program such as <command>xterm</command> or
|
---|
| 39 | <command>konsole</command> from within a graphical environment. This type
|
---|
| 40 | of shell invocation normally copies the parent environment and then reads
|
---|
| 41 | the user's <filename>~/.bashrc</filename> file for additional startup
|
---|
| 42 | configuration instructions.
|
---|
| 43 | </para>
|
---|
| 44 |
|
---|
| 45 | <para>
|
---|
| 46 | A non-interactive shell is usually present when a shell script is
|
---|
| 47 | running. It is non-interactive because it is processing a script and not
|
---|
| 48 | waiting for user input between commands. For these shell invocations, only
|
---|
| 49 | the environment inherited from the parent shell is used.
|
---|
| 50 | </para>
|
---|
| 51 |
|
---|
| 52 | <para>
|
---|
| 53 | The file <filename>~/.bash_logout</filename> is not used for an
|
---|
| 54 | invocation of the shell. It is read and executed when a user exits from an
|
---|
| 55 | interactive login shell.
|
---|
| 56 | </para>
|
---|
| 57 |
|
---|
| 58 | <para>
|
---|
| 59 | Many distributions use <filename>/etc/bashrc</filename> for system wide
|
---|
| 60 | initialization of non-login shells. This file is usually called from the
|
---|
| 61 | user's <filename>~/.bashrc</filename> file and is not built directly into
|
---|
| 62 | <command>bash</command> itself. This convention is followed in this
|
---|
| 63 | section.
|
---|
| 64 | </para>
|
---|
| 65 |
|
---|
| 66 | <para>
|
---|
| 67 | For more information see <command>info bash</command> --
|
---|
| 68 | <emphasis role="strong">Nodes: Bash Startup Files and Interactive
|
---|
| 69 | Shells</emphasis>.
|
---|
| 70 | </para>
|
---|
[ba0deaad] | 71 |
|
---|
| 72 | <note>
|
---|
[81a73ed8] | 73 | <para>
|
---|
| 74 | Most of the instructions below are used to create files located in the
|
---|
| 75 | <filename class='directory'>/etc</filename> directory structure which
|
---|
| 76 | requires you to execute the commands as the <systemitem
|
---|
| 77 | class='username'>root</systemitem> user. If you elect to create the
|
---|
| 78 | files in user's home directories instead, you should run the commands
|
---|
| 79 | as an unprivileged user.
|
---|
| 80 | </para>
|
---|
[ba0deaad] | 81 | </note>
|
---|
[2753b70b] | 82 |
|
---|
[42ddc30] | 83 | <para condition="html" role="usernotes">Editor Notes:
|
---|
[1ef28cd2] | 84 | <ulink url="&blfs-wiki;/bash-shell-startup-files"/></para>
|
---|
[5c3f3856] | 85 |
|
---|
[2753b70b] | 86 | <sect2 id="etc-profile-profile">
|
---|
| 87 | <title>/etc/profile</title>
|
---|
| 88 |
|
---|
| 89 | <indexterm zone="postlfs-config-profile etc-profile-profile">
|
---|
| 90 | <primary sortas="e-etc-profile">/etc/profile</primary>
|
---|
| 91 | </indexterm>
|
---|
| 92 |
|
---|
[81a73ed8] | 93 | <para>
|
---|
| 94 | Here is a base <filename>/etc/profile</filename>. This file starts by
|
---|
| 95 | setting up some helper functions and some basic parameters. It specifies
|
---|
| 96 | some <command>bash</command> history parameters and, for security
|
---|
| 97 | purposes, disables keeping a permanent history file for the <systemitem
|
---|
| 98 | class="username">root</systemitem> user. It also sets a default user
|
---|
| 99 | prompt. It then calls small, single purpose scripts in the <filename
|
---|
| 100 | class='directory'>/etc/profile.d</filename> directory to provide most
|
---|
| 101 | of the initialization.
|
---|
| 102 | </para>
|
---|
| 103 |
|
---|
| 104 | <para>
|
---|
| 105 | For more information on the escape sequences you can use for your prompt
|
---|
| 106 | (i.e., the <envar>PS1</envar> environment variable) see <command>info
|
---|
| 107 | bash</command> -- <emphasis role="strong">Node: Printing a
|
---|
| 108 | Prompt</emphasis>.
|
---|
| 109 | </para>
|
---|
[2753b70b] | 110 |
|
---|
[8e37798] | 111 | <screen role="root"><?dbfo keep-together="auto"?><userinput>cat > /etc/profile << "EOF"
|
---|
[2753b70b] | 112 | <literal># Begin /etc/profile
|
---|
[b554263] | 113 | # Written for Beyond Linux From Scratch
|
---|
| 114 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[1a396398] | 115 | # modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
---|
[384039a] | 116 |
|
---|
[b554263] | 117 | # System wide environment variables and startup programs.
|
---|
[384039a] | 118 |
|
---|
[b554263] | 119 | # System wide aliases and functions should go in /etc/bashrc. Personal
|
---|
| 120 | # environment variables and startup programs should go into
|
---|
| 121 | # ~/.bash_profile. Personal aliases and functions should go into
|
---|
| 122 | # ~/.bashrc.
|
---|
[384039a] | 123 |
|
---|
[1a396398] | 124 | # Functions to help us manage paths. Second argument is the name of the
|
---|
| 125 | # path variable to be modified (default: PATH)
|
---|
| 126 | pathremove () {
|
---|
| 127 | local IFS=':'
|
---|
| 128 | local NEWPATH
|
---|
| 129 | local DIR
|
---|
| 130 | local PATHVARIABLE=${2:-PATH}
|
---|
| 131 | for DIR in ${!PATHVARIABLE} ; do
|
---|
| 132 | if [ "$DIR" != "$1" ] ; then
|
---|
| 133 | NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
|
---|
| 134 | fi
|
---|
| 135 | done
|
---|
| 136 | export $PATHVARIABLE="$NEWPATH"
|
---|
[b554263] | 137 | }
|
---|
[384039a] | 138 |
|
---|
[1a396398] | 139 | pathprepend () {
|
---|
| 140 | pathremove $1 $2
|
---|
| 141 | local PATHVARIABLE=${2:-PATH}
|
---|
| 142 | export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
|
---|
| 143 | }
|
---|
[384039a] | 144 |
|
---|
[1a396398] | 145 | pathappend () {
|
---|
| 146 | pathremove $1 $2
|
---|
| 147 | local PATHVARIABLE=${2:-PATH}
|
---|
| 148 | export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
|
---|
| 149 | }
|
---|
[384039a] | 150 |
|
---|
[ec7940be] | 151 | export -f pathremove pathprepend pathappend
|
---|
[e9ef7b5e] | 152 |
|
---|
| 153 | # Set the initial path
|
---|
[b149d10] | 154 | export PATH=/usr/bin
|
---|
| 155 |
|
---|
| 156 | # Attempt to provide backward compatibility with LFS earlier than 11
|
---|
| 157 | if [ ! -L /bin ]; then
|
---|
| 158 | pathappend /bin
|
---|
| 159 | fi
|
---|
[e9ef7b5e] | 160 |
|
---|
[1a396398] | 161 | if [ $EUID -eq 0 ] ; then
|
---|
[b149d10] | 162 | pathappend /usr/sbin
|
---|
| 163 | if [ ! -L /sbin ]; then
|
---|
| 164 | pathappend /sbin
|
---|
| 165 | fi
|
---|
[1a396398] | 166 | unset HISTFILE
|
---|
[b554263] | 167 | fi
|
---|
[384039a] | 168 |
|
---|
[b59e5eb3] | 169 | # Set up some environment variables.
|
---|
[1a396398] | 170 | export HISTSIZE=1000
|
---|
| 171 | export HISTIGNORE="&:[bf]g:exit"
|
---|
[0d7ec6f1] | 172 |
|
---|
[97c713e] | 173 | # Set some defaults for graphical systems
|
---|
[a4da374] | 174 | export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share}
|
---|
| 175 | export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg}
|
---|
[caee7667] | 176 | export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}
|
---|
[97c713e] | 177 |
|
---|
[b59e5eb3] | 178 | # Set up a red prompt for root and a green one for users.
|
---|
[0d7ec6f1] | 179 | NORMAL="\[\e[0m\]"
|
---|
| 180 | RED="\[\e[1;31m\]"
|
---|
| 181 | GREEN="\[\e[1;32m\]"
|
---|
| 182 | if [[ $EUID == 0 ]] ; then
|
---|
| 183 | PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
---|
| 184 | else
|
---|
| 185 | PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
---|
| 186 | fi
|
---|
[384039a] | 187 |
|
---|
[1a396398] | 188 | for script in /etc/profile.d/*.sh ; do
|
---|
[d3880c0] | 189 | if [ -r $script ] ; then
|
---|
[1a396398] | 190 | . $script
|
---|
| 191 | fi
|
---|
| 192 | done
|
---|
[384039a] | 193 |
|
---|
[f91e4b98] | 194 | unset script RED GREEN NORMAL
|
---|
[dc53944] | 195 |
|
---|
[2753b70b] | 196 | # End /etc/profile</literal>
|
---|
| 197 | EOF</userinput></screen>
|
---|
[1a396398] | 198 |
|
---|
[2753b70b] | 199 | <sect3 id="etc-profile.d">
|
---|
| 200 | <title>The /etc/profile.d Directory</title>
|
---|
[99e8a229] | 201 |
|
---|
[2753b70b] | 202 | <indexterm zone="postlfs-config-profile etc-profile.d">
|
---|
| 203 | <primary sortas="e-etc-profile.d">/etc/profile.d</primary>
|
---|
| 204 | </indexterm>
|
---|
[1a396398] | 205 |
|
---|
[81a73ed8] | 206 | <para>
|
---|
| 207 | Now create the <filename class='directory'>/etc/profile.d</filename>
|
---|
| 208 | directory, where the individual initialization scripts are placed:
|
---|
| 209 | </para>
|
---|
[1a396398] | 210 |
|
---|
[2753b70b] | 211 | <screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/profile.d</userinput></screen>
|
---|
[1a396398] | 212 |
|
---|
[2753b70b] | 213 | </sect3>
|
---|
[1a396398] | 214 |
|
---|
[931a597] | 215 | <sect3 id="etc-profile.d-bash-completion.sh">
|
---|
| 216 | <title>/etc/profile.d/bash_completion.sh</title>
|
---|
| 217 |
|
---|
| 218 | <indexterm zone="postlfs-config-profile etc-profile.d-bash-completion.sh">
|
---|
| 219 | <primary sortas="e-etc-profile.d-bash-completion.sh">/etc/profile.d/bash_completion.sh</primary>
|
---|
| 220 | </indexterm>
|
---|
| 221 |
|
---|
[81a73ed8] | 222 | <note>
|
---|
| 223 | <para>
|
---|
| 224 | Using the bash completion script below is controversial. Not all
|
---|
| 225 | users like it. It adds many (usually over 1000) lines to the bash
|
---|
| 226 | environment and makes it difficult to use the 'set' command to
|
---|
| 227 | examine simple environment variables. Omitting this script does
|
---|
| 228 | not interfere with the ability of bash to use the tab key for file
|
---|
| 229 | name completion.
|
---|
| 230 | </para>
|
---|
| 231 | </note>
|
---|
| 232 |
|
---|
| 233 | <para>
|
---|
| 234 | This script imports bash completion scripts, installed by many
|
---|
| 235 | other BLFS packages, to allow TAB command line completion.
|
---|
| 236 | </para>
|
---|
[931a597] | 237 |
|
---|
| 238 | <screen role="root"><userinput>cat > /etc/profile.d/bash_completion.sh << "EOF"
|
---|
| 239 | <literal># Begin /etc/profile.d/bash_completion.sh
|
---|
| 240 | # Import bash completion scripts
|
---|
| 241 |
|
---|
[5c3f3856] | 242 | # If the bash-completion package is installed, use its configuration instead
|
---|
| 243 | if [ -f /usr/share/bash-completion/bash_completion ]; then
|
---|
| 244 |
|
---|
| 245 | # Check for interactive bash and that we haven't already been sourced.
|
---|
| 246 | if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
|
---|
| 247 |
|
---|
| 248 | # Check for recent enough version of bash.
|
---|
| 249 | if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
|
---|
| 250 | [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
|
---|
| 251 | [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
|
---|
| 252 | . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
|
---|
| 253 | if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
|
---|
| 254 | # Source completion code.
|
---|
| 255 | . /usr/share/bash-completion/bash_completion
|
---|
| 256 | fi
|
---|
| 257 | fi
|
---|
| 258 | fi
|
---|
| 259 |
|
---|
| 260 | else
|
---|
| 261 |
|
---|
| 262 | # bash-completions are not installed, use only bash completion directory
|
---|
| 263 | if shopt -q progcomp; then
|
---|
| 264 | for script in /etc/bash_completion.d/* ; do
|
---|
| 265 | if [ -r $script ] ; then
|
---|
| 266 | . $script
|
---|
| 267 | fi
|
---|
| 268 | done
|
---|
| 269 | fi
|
---|
| 270 | fi
|
---|
| 271 |
|
---|
[931a597] | 272 | # End /etc/profile.d/bash_completion.sh</literal>
|
---|
| 273 | EOF</userinput></screen>
|
---|
[81a73ed8] | 274 | <para>
|
---|
| 275 | Make sure that the directory exists:
|
---|
| 276 | </para>
|
---|
[931a597] | 277 |
|
---|
| 278 | <screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/bash_completion.d</userinput></screen>
|
---|
| 279 |
|
---|
[81a73ed8] | 280 | <para>
|
---|
| 281 | For a more complete installation, see
|
---|
| 282 | <ulink url="&blfs-wiki;/bash-shell-startup-files#bash-completions"/>.
|
---|
| 283 | </para>
|
---|
[931a597] | 284 |
|
---|
[5c3f3856] | 285 | </sect3>
|
---|
[931a597] | 286 |
|
---|
[2753b70b] | 287 | <sect3 id="etc-profile.d-dircolors.sh">
|
---|
| 288 | <title>/etc/profile.d/dircolors.sh</title>
|
---|
| 289 |
|
---|
| 290 | <indexterm zone="postlfs-config-profile etc-profile.d-dircolors.sh">
|
---|
| 291 | <primary sortas="e-etc-profile.d-dircolors.sh">/etc/profile.d/dircolors.sh</primary>
|
---|
| 292 | </indexterm>
|
---|
| 293 |
|
---|
[81a73ed8] | 294 | <para>
|
---|
| 295 | This script uses the <filename>~/.dircolors</filename> and
|
---|
| 296 | <filename>/etc/dircolors</filename> files to control the colors of
|
---|
| 297 | file names in a directory listing. They control colorized output of
|
---|
| 298 | things like <command>ls --color</command>. The explanation of how to
|
---|
| 299 | initialize these files is at the end of this section.
|
---|
| 300 | </para>
|
---|
[2753b70b] | 301 |
|
---|
| 302 | <screen role="root"><userinput>cat > /etc/profile.d/dircolors.sh << "EOF"
|
---|
[b5905ae] | 303 | <literal># Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
|
---|
[1a396398] | 304 | if [ -f "/etc/dircolors" ] ; then
|
---|
| 305 | eval $(dircolors -b /etc/dircolors)
|
---|
[89ef45fc] | 306 | fi
|
---|
[384039a] | 307 |
|
---|
[89ef45fc] | 308 | if [ -f "$HOME/.dircolors" ] ; then
|
---|
| 309 | eval $(dircolors -b $HOME/.dircolors)
|
---|
[b554263] | 310 | fi
|
---|
[89ef45fc] | 311 |
|
---|
[b5905ae] | 312 | alias ls='ls --color=auto'
|
---|
| 313 | alias grep='grep --color=auto'</literal>
|
---|
[2753b70b] | 314 | EOF</userinput></screen>
|
---|
| 315 |
|
---|
| 316 | </sect3>
|
---|
| 317 |
|
---|
| 318 | <sect3 id="extrapaths.sh">
|
---|
| 319 | <title>/etc/profile.d/extrapaths.sh</title>
|
---|
| 320 |
|
---|
| 321 | <indexterm zone="postlfs-config-profile extrapaths.sh">
|
---|
| 322 | <primary sortas="e-etc-profile.d-extrapaths.sh">/etc/profile.d/extrapaths.sh</primary>
|
---|
| 323 | </indexterm>
|
---|
| 324 |
|
---|
[81a73ed8] | 325 | <para>
|
---|
| 326 | This script adds some useful paths to the <envar>PATH</envar> and
|
---|
| 327 | can be used to customize other PATH related environment variables
|
---|
| 328 | (e.g. LD_LIBRARY_PATH, etc) that may be needed for all users.
|
---|
| 329 | </para>
|
---|
[384039a] | 330 |
|
---|
[2753b70b] | 331 | <screen role="root"><userinput>cat > /etc/profile.d/extrapaths.sh << "EOF"
|
---|
| 332 | <literal>if [ -d /usr/local/lib/pkgconfig ] ; then
|
---|
[1a396398] | 333 | pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
|
---|
| 334 | fi
|
---|
| 335 | if [ -d /usr/local/bin ]; then
|
---|
| 336 | pathprepend /usr/local/bin
|
---|
[b554263] | 337 | fi
|
---|
[1a396398] | 338 | if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
|
---|
| 339 | pathprepend /usr/local/sbin
|
---|
[a4f641b] | 340 | fi
|
---|
[bfa21f3] | 341 |
|
---|
[bdd4ca4] | 342 | if [ -d /usr/local/share ]; then
|
---|
| 343 | pathprepend /usr/local/share XDG_DATA_DIRS
|
---|
| 344 | fi
|
---|
| 345 |
|
---|
[bfa21f3] | 346 | # Set some defaults before other applications add to these paths.
|
---|
[a4f641b] | 347 | pathappend /usr/share/info INFOPATH</literal>
|
---|
[2753b70b] | 348 | EOF</userinput></screen>
|
---|
| 349 |
|
---|
[755607e3] | 350 | <note>
|
---|
| 351 | <para>
|
---|
| 352 | The <command>man</command> program automatically deduce the search
|
---|
[efc10aa3] | 353 | path for man pages by examining the content of the
|
---|
[755607e3] | 354 | <envar>PATH</envar> variable, see
|
---|
| 355 | <ulink role='man' url='&man;manpath.5'>manpath(5)</ulink> for
|
---|
| 356 | details. Setting the <envar>MANPATH</envar> variable may override
|
---|
| 357 | the automatic deduction, so the BLFS editors do not recommend to
|
---|
| 358 | set it. If you must set it for any reason, it's better to start
|
---|
| 359 | its value with a colon (<literal>:</literal>), for example
|
---|
| 360 | <command>MANPATH=:/opt/somepkg/share/man:/opt/otherpkg/share/man</command>
|
---|
| 361 | so the paths listed in the <envar>MANPATH</envar> variable will
|
---|
| 362 | be appended to the automatically deduced value instead of
|
---|
| 363 | overriding it.
|
---|
| 364 | </para>
|
---|
| 365 | </note>
|
---|
| 366 |
|
---|
[2753b70b] | 367 | </sect3>
|
---|
| 368 |
|
---|
| 369 | <sect3 id="readline.sh">
|
---|
| 370 | <title>/etc/profile.d/readline.sh</title>
|
---|
| 371 |
|
---|
| 372 | <indexterm zone="postlfs-config-profile readline.sh">
|
---|
| 373 | <primary sortas="e-etc-profile.d-readline.sh">/etc/profile.d/readline.sh</primary>
|
---|
| 374 | </indexterm>
|
---|
| 375 |
|
---|
[81a73ed8] | 376 | <para>
|
---|
| 377 | This script sets up the default <filename>inputrc</filename>
|
---|
| 378 | configuration file. If the user does not have individual settings, it
|
---|
| 379 | uses the global file.
|
---|
| 380 | </para>
|
---|
[2753b70b] | 381 |
|
---|
| 382 | <screen role="root"><userinput>cat > /etc/profile.d/readline.sh << "EOF"
|
---|
[b59e5eb3] | 383 | <literal># Set up the INPUTRC environment variable.
|
---|
[b554263] | 384 | if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
|
---|
[1a396398] | 385 | INPUTRC=/etc/inputrc
|
---|
[b554263] | 386 | fi
|
---|
[2753b70b] | 387 | export INPUTRC</literal>
|
---|
| 388 | EOF</userinput></screen>
|
---|
| 389 |
|
---|
| 390 | </sect3>
|
---|
| 391 |
|
---|
| 392 | <sect3 id="umask.sh">
|
---|
| 393 | <title>/etc/profile.d/umask.sh</title>
|
---|
| 394 |
|
---|
| 395 | <indexterm zone="postlfs-config-profile umask.sh">
|
---|
| 396 | <primary sortas="e-etc-profile.d-umask.sh">/etc/profile.d/umask.sh</primary>
|
---|
| 397 | </indexterm>
|
---|
[384039a] | 398 |
|
---|
[81a73ed8] | 399 | <para>
|
---|
| 400 | Setting the <command>umask</command> value is important for security.
|
---|
| 401 | Here the default group write permissions are turned off for system
|
---|
| 402 | users and when the user name and group name are not the same.
|
---|
| 403 | </para>
|
---|
[b554263] | 404 |
|
---|
[2753b70b] | 405 | <screen role="root"><userinput>cat > /etc/profile.d/umask.sh << "EOF"
|
---|
[ec64d28] | 406 | <literal># By default, the umask should be set.
|
---|
[1a396398] | 407 | if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
|
---|
| 408 | umask 002
|
---|
| 409 | else
|
---|
| 410 | umask 022
|
---|
[2753b70b] | 411 | fi</literal>
|
---|
| 412 | EOF</userinput></screen>
|
---|
| 413 |
|
---|
| 414 | </sect3>
|
---|
| 415 |
|
---|
[be409f9a] | 416 | <!-- This is handled in the Xorg section of the book
|
---|
[2753b70b] | 417 | <sect3 id="X.sh">
|
---|
| 418 | <title>/etc/profile.d/X.sh</title>
|
---|
[1a396398] | 419 |
|
---|
[2753b70b] | 420 | <indexterm zone="postlfs-config-profile X.sh">
|
---|
| 421 | <primary sortas="e-etc-profile.d-X.sh">/etc/profile.d/X.sh</primary>
|
---|
| 422 | </indexterm>
|
---|
[1a396398] | 423 |
|
---|
[81a73ed8] | 424 | <para>
|
---|
| 425 | If <application>X</application> is installed, the <envar>PATH</envar>
|
---|
| 426 | and <envar>PKG_CONFIG_PATH</envar> variables are also updated.
|
---|
| 427 | </para>
|
---|
[1a396398] | 428 |
|
---|
[2753b70b] | 429 | <screen role="root"><userinput>cat > /etc/profile.d/X.sh << "EOF"
|
---|
| 430 | <literal>if [ -x /usr/X11R6/bin/X ]; then
|
---|
[1a396398] | 431 | pathappend /usr/X11R6/bin
|
---|
| 432 | fi
|
---|
| 433 | if [ -d /usr/X11R6/lib/pkgconfig ] ; then
|
---|
| 434 | pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
|
---|
[2753b70b] | 435 | fi</literal>
|
---|
| 436 | EOF</userinput></screen>
|
---|
| 437 |
|
---|
| 438 | </sect3>
|
---|
[be409f9a] | 439 | -->
|
---|
[d202a49f] | 440 | <sect3 id="i18n.sh">
|
---|
| 441 | <!-- This is handled system wide on systemd but LANG is not exported to
|
---|
| 442 | the environment, hence it's return...need to add additional text for
|
---|
| 443 | systemd only -->
|
---|
[0d7ec6f1] | 444 | <title>/etc/profile.d/i18n.sh</title>
|
---|
[2753b70b] | 445 |
|
---|
| 446 | <indexterm zone="postlfs-config-profile i18n.sh">
|
---|
| 447 | <primary sortas="e-etc-profile.d-i18n.sh">/etc/profile.d/i18n.sh</primary>
|
---|
| 448 | </indexterm>
|
---|
| 449 |
|
---|
[81a73ed8] | 450 | <para>
|
---|
| 451 | This script sets an environment variable necessary for
|
---|
| 452 | native language support. A full discussion on determining this
|
---|
| 453 | variable can be found on the <ulink
|
---|
[b416ee85] | 454 | url="&lfs-root;/chapter09/locale.html">Configuring the System
|
---|
| 455 | Locale</ulink> page.
|
---|
[81a73ed8] | 456 | </para>
|
---|
[2753b70b] | 457 |
|
---|
[1794983d] | 458 | <screen role="root" revision="sysv"><userinput>cat > /etc/profile.d/i18n.sh << "EOF"
|
---|
[2753b70b] | 459 | <literal># Set up i18n variables
|
---|
[8a8a7dc] | 460 | for i in $(locale); do
|
---|
| 461 | unset ${i%=*}
|
---|
| 462 | done
|
---|
| 463 |
|
---|
| 464 | if [[ "$TERM" = linux ]]; then
|
---|
[dde4d38] | 465 | export LANG=C.UTF-8
|
---|
[8a8a7dc] | 466 | else
|
---|
| 467 | export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
| 468 | fi</literal>
|
---|
[1794983d] | 469 | EOF</userinput></screen>
|
---|
| 470 |
|
---|
| 471 | <screen role="root" revision="systemd"><userinput>cat > /etc/profile.d/i18n.sh << "EOF"
|
---|
| 472 | <literal># Set up i18n variables
|
---|
[8a8a7dc] | 473 | for i in $(locale); do
|
---|
| 474 | unset ${i%=*}
|
---|
| 475 | done
|
---|
| 476 |
|
---|
| 477 | if [[ "$TERM" = linux ]]; then
|
---|
[dde4d38] | 478 | export LANG=C.UTF-8
|
---|
[8a8a7dc] | 479 | else
|
---|
| 480 | source /etc/locale.conf
|
---|
| 481 |
|
---|
| 482 | for i in $(locale); do
|
---|
| 483 | key=${i%=*}
|
---|
| 484 | if [[ -v $key ]]; then
|
---|
| 485 | export $key
|
---|
| 486 | fi
|
---|
| 487 | done
|
---|
| 488 | fi</literal>
|
---|
[2753b70b] | 489 | EOF</userinput></screen>
|
---|
| 490 |
|
---|
| 491 | </sect3>
|
---|
| 492 |
|
---|
| 493 | <sect3>
|
---|
| 494 | <title>Other Initialization Values</title>
|
---|
| 495 |
|
---|
[81a73ed8] | 496 | <para>
|
---|
| 497 | Other initialization can easily be added to the
|
---|
| 498 | <filename>profile</filename> by adding additional scripts to the
|
---|
| 499 | <filename class='directory'>/etc/profile.d</filename> directory.
|
---|
| 500 | </para>
|
---|
[2753b70b] | 501 |
|
---|
| 502 | </sect3>
|
---|
| 503 |
|
---|
| 504 | </sect2>
|
---|
| 505 |
|
---|
| 506 | <sect2 id="etc-bashrc-profile">
|
---|
| 507 | <title>/etc/bashrc</title>
|
---|
| 508 |
|
---|
| 509 | <indexterm zone="postlfs-config-profile etc-bashrc-profile">
|
---|
| 510 | <primary sortas="e-etc-bashrc">/etc/bashrc</primary>
|
---|
| 511 | </indexterm>
|
---|
| 512 |
|
---|
[81a73ed8] | 513 | <para>
|
---|
| 514 | Here is a base <filename>/etc/bashrc</filename>. Comments in the
|
---|
| 515 | file should explain everything you need.
|
---|
| 516 | </para>
|
---|
[2753b70b] | 517 |
|
---|
| 518 | <screen role="root"><userinput>cat > /etc/bashrc << "EOF"
|
---|
[384039a] | 519 | <literal># Begin /etc/bashrc
|
---|
| 520 | # Written for Beyond Linux From Scratch
|
---|
[b554263] | 521 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[4e88613] | 522 | # updated by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
[ad33bab6] | 523 |
|
---|
[b554263] | 524 | # System wide aliases and functions.
|
---|
| 525 |
|
---|
| 526 | # System wide environment variables and startup programs should go into
|
---|
| 527 | # /etc/profile. Personal environment variables and startup programs
|
---|
| 528 | # should go into ~/.bash_profile. Personal aliases and functions should
|
---|
| 529 | # go into ~/.bashrc
|
---|
| 530 |
|
---|
[b5905ae] | 531 | # Provides colored /bin/ls and /bin/grep commands. Used in conjunction
|
---|
| 532 | # with code in /etc/profile.
|
---|
[1a396398] | 533 |
|
---|
[b554263] | 534 | alias ls='ls --color=auto'
|
---|
[b5905ae] | 535 | alias grep='grep --color=auto'
|
---|
[b554263] | 536 |
|
---|
[1a396398] | 537 | # Provides prompt for non-login shells, specifically shells started
|
---|
[2753b70b] | 538 | # in the X environment. [Review the LFS archive thread titled
|
---|
[384039a] | 539 | # PS1 Environment Variable for a great case study behind this script
|
---|
[dd362e5] | 540 | # addendum.]
|
---|
[1a396398] | 541 |
|
---|
[0d7ec6f1] | 542 | NORMAL="\[\e[0m\]"
|
---|
| 543 | RED="\[\e[1;31m\]"
|
---|
| 544 | GREEN="\[\e[1;32m\]"
|
---|
| 545 | if [[ $EUID == 0 ]] ; then
|
---|
| 546 | PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
---|
| 547 | else
|
---|
| 548 | PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
---|
| 549 | fi
|
---|
[28a9992] | 550 |
|
---|
[dc53944] | 551 | unset RED GREEN NORMAL
|
---|
| 552 |
|
---|
[2753b70b] | 553 | # End /etc/bashrc</literal>
|
---|
| 554 | EOF</userinput></screen>
|
---|
| 555 |
|
---|
| 556 | </sect2>
|
---|
| 557 |
|
---|
| 558 | <sect2 id="bash_profile-profile">
|
---|
| 559 | <title>~/.bash_profile</title>
|
---|
| 560 |
|
---|
| 561 | <indexterm zone="postlfs-config-profile bash_profile-profile">
|
---|
| 562 | <primary sortas="e-AA.bash_profile">~/.bash_profile</primary>
|
---|
| 563 | </indexterm>
|
---|
| 564 |
|
---|
[81a73ed8] | 565 | <para>
|
---|
| 566 | Here is a base <filename>~/.bash_profile</filename>. If you want each
|
---|
| 567 | new user to have this file automatically, just change the output of
|
---|
| 568 | the command to <filename>/etc/skel/.bash_profile</filename> and check the
|
---|
| 569 | permissions after the command is run. You can then copy <filename>
|
---|
| 570 | /etc/skel/.bash_profile</filename> to the home directories of already
|
---|
| 571 | existing users, including <systemitem class="username">root</systemitem>,
|
---|
| 572 | and set the owner and group appropriately.
|
---|
| 573 | </para>
|
---|
[2753b70b] | 574 |
|
---|
| 575 | <screen><userinput>cat > ~/.bash_profile << "EOF"
|
---|
| 576 | <literal># Begin ~/.bash_profile
|
---|
[b554263] | 577 | # Written for Beyond Linux From Scratch
|
---|
| 578 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[4e88613] | 579 | # updated by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
[b554263] | 580 |
|
---|
[64d97b7c] | 581 | # Personal environment variables and startup programs.
|
---|
[b554263] | 582 |
|
---|
| 583 | # Personal aliases and functions should go in ~/.bashrc. System wide
|
---|
| 584 | # environment variables and startup programs are in /etc/profile.
|
---|
| 585 | # System wide aliases and functions are in /etc/bashrc.
|
---|
| 586 |
|
---|
| 587 | if [ -f "$HOME/.bashrc" ] ; then
|
---|
[76d61ba] | 588 | source $HOME/.bashrc
|
---|
[b554263] | 589 | fi
|
---|
| 590 |
|
---|
| 591 | if [ -d "$HOME/bin" ] ; then
|
---|
[dc53944] | 592 | pathprepend $HOME/bin
|
---|
[b554263] | 593 | fi
|
---|
| 594 |
|
---|
[dc53944] | 595 | # Having . in the PATH is dangerous
|
---|
| 596 | #if [ $EUID -gt 99 ]; then
|
---|
| 597 | # pathappend .
|
---|
| 598 | #fi
|
---|
[b554263] | 599 |
|
---|
[2753b70b] | 600 | # End ~/.bash_profile</literal>
|
---|
| 601 | EOF</userinput></screen>
|
---|
| 602 |
|
---|
| 603 | </sect2>
|
---|
[384039a] | 604 |
|
---|
[6f36554] | 605 | <sect2 id="dot_profile-profile">
|
---|
| 606 | <title>~/.profile</title>
|
---|
| 607 |
|
---|
| 608 | <indexterm zone="postlfs-config-profile dot_profile-profile">
|
---|
| 609 | <primary sortas="e-AA.dot_profile">~/.profile</primary>
|
---|
| 610 | </indexterm>
|
---|
| 611 |
|
---|
[81a73ed8] | 612 | <para>
|
---|
| 613 | Here is a base <filename>~/.profile</filename>. The comments and
|
---|
| 614 | instructions for using <filename class="directory">/etc/skel</filename>
|
---|
| 615 | for <filename>.bash_profile</filename> above also apply here. Only the
|
---|
| 616 | target file names are different.
|
---|
| 617 | </para>
|
---|
[6f36554] | 618 |
|
---|
| 619 | <screen><userinput>cat > ~/.profile << "EOF"
|
---|
| 620 | <literal># Begin ~/.profile
|
---|
| 621 | # Personal environment variables and startup programs.
|
---|
| 622 |
|
---|
| 623 | if [ -d "$HOME/bin" ] ; then
|
---|
| 624 | pathprepend $HOME/bin
|
---|
| 625 | fi
|
---|
| 626 |
|
---|
[d202a49f] | 627 | # Set up user specific i18n variables
|
---|
| 628 | #export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
| 629 |
|
---|
[6f36554] | 630 | # End ~/.profile</literal>
|
---|
| 631 | EOF</userinput></screen>
|
---|
| 632 |
|
---|
| 633 | </sect2>
|
---|
| 634 |
|
---|
[2753b70b] | 635 | <sect2 id="bashrc-profile">
|
---|
| 636 | <title>~/.bashrc</title>
|
---|
| 637 |
|
---|
| 638 | <indexterm zone="postlfs-config-profile bashrc-profile">
|
---|
| 639 | <primary sortas="e-AA.bashrc">~/.bashrc</primary>
|
---|
| 640 | </indexterm>
|
---|
| 641 |
|
---|
[81a73ed8] | 642 | <para>
|
---|
| 643 | Here is a base <filename>~/.bashrc</filename>.
|
---|
| 644 | </para>
|
---|
[2753b70b] | 645 |
|
---|
| 646 | <screen><userinput>cat > ~/.bashrc << "EOF"
|
---|
| 647 | <literal># Begin ~/.bashrc
|
---|
[b554263] | 648 | # Written for Beyond Linux From Scratch
|
---|
| 649 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 650 |
|
---|
| 651 | # Personal aliases and functions.
|
---|
| 652 |
|
---|
| 653 | # Personal environment variables and startup programs should go in
|
---|
[64d97b7c] | 654 | # ~/.bash_profile. System wide environment variables and startup
|
---|
[b554263] | 655 | # programs are in /etc/profile. System wide aliases and functions are
|
---|
[384039a] | 656 | # in /etc/bashrc.
|
---|
[b554263] | 657 |
|
---|
| 658 | if [ -f "/etc/bashrc" ] ; then
|
---|
[76d61ba] | 659 | source /etc/bashrc
|
---|
[b554263] | 660 | fi
|
---|
| 661 |
|
---|
[d202a49f] | 662 | # Set up user specific i18n variables
|
---|
| 663 | #export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
| 664 |
|
---|
[2753b70b] | 665 | # End ~/.bashrc</literal>
|
---|
| 666 | EOF</userinput></screen>
|
---|
| 667 |
|
---|
| 668 | </sect2>
|
---|
[384039a] | 669 |
|
---|
| 670 |
|
---|
[2753b70b] | 671 | <sect2 id="bash_logout-profile">
|
---|
| 672 | <title>~/.bash_logout</title>
|
---|
| 673 |
|
---|
| 674 | <indexterm zone="postlfs-config-profile bash_logout-profile">
|
---|
| 675 | <primary sortas="e-AA.bash_logout">~/.bash_logout</primary>
|
---|
| 676 | </indexterm>
|
---|
| 677 |
|
---|
[81a73ed8] | 678 | <para>
|
---|
| 679 | This is an empty <filename>~/.bash_logout</filename> that can be used as
|
---|
| 680 | a template. You will notice that the base <filename>~/.bash_logout
|
---|
| 681 | </filename> does not include a <userinput>clear</userinput> command.
|
---|
| 682 | This is because the clear is handled in the
|
---|
| 683 | <filename>/etc/issue</filename> file.
|
---|
| 684 | </para>
|
---|
[2753b70b] | 685 |
|
---|
| 686 | <screen><userinput>cat > ~/.bash_logout << "EOF"
|
---|
| 687 | <literal># Begin ~/.bash_logout
|
---|
[b554263] | 688 | # Written for Beyond Linux From Scratch
|
---|
| 689 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 690 |
|
---|
| 691 | # Personal items to perform on logout.
|
---|
| 692 |
|
---|
[2753b70b] | 693 | # End ~/.bash_logout</literal>
|
---|
| 694 | EOF</userinput></screen>
|
---|
| 695 |
|
---|
| 696 | </sect2>
|
---|
[384039a] | 697 |
|
---|
| 698 |
|
---|
[2753b70b] | 699 | <sect2 id="etc-dircolors-profile">
|
---|
| 700 | <title>/etc/dircolors</title>
|
---|
| 701 |
|
---|
| 702 | <indexterm zone="postlfs-config-profile etc-dircolors-profile">
|
---|
| 703 | <primary sortas="e-etc-dircolors">/etc/dircolors</primary>
|
---|
| 704 | </indexterm>
|
---|
| 705 |
|
---|
| 706 | <indexterm zone="postlfs-config-profile etc-dircolors-profile">
|
---|
| 707 | <primary sortas="e-AA.dircolors">~/.dircolors</primary>
|
---|
| 708 | </indexterm>
|
---|
| 709 |
|
---|
[81a73ed8] | 710 | <para>
|
---|
| 711 | If you want to use the <filename>dircolors</filename> capability, then
|
---|
| 712 | run the following command. The <filename class="directory">/etc/skel
|
---|
| 713 | </filename> setup steps shown above also can be used here to provide
|
---|
| 714 | a <filename>~/.dircolors</filename> file when a new user is set up.
|
---|
| 715 | As before, just change the output file name on the following command
|
---|
| 716 | and assure the permissions, owner, and group are correct on the files
|
---|
| 717 | created and/or copied.
|
---|
| 718 | </para>
|
---|
[2753b70b] | 719 |
|
---|
| 720 | <screen role="root"><userinput>dircolors -p > /etc/dircolors</userinput></screen>
|
---|
| 721 |
|
---|
[81a73ed8] | 722 | <para>
|
---|
| 723 | If you wish to customize the colors used for different file types, you
|
---|
| 724 | can edit the <filename>/etc/dircolors</filename> file. The instructions
|
---|
| 725 | for setting the colors are embedded in the file.
|
---|
| 726 | </para>
|
---|
[2753b70b] | 727 |
|
---|
| 728 |
|
---|
[81a73ed8] | 729 | <para>
|
---|
| 730 | Finally, Ian Macdonald has written an excellent collection of tips and
|
---|
| 731 | tricks to enhance your shell environment. You can read it online at
|
---|
[cd29bc9] | 732 | <ulink url="https://www.caliban.org/bash/index.shtml"/>.
|
---|
[81a73ed8] | 733 | </para>
|
---|
[2753b70b] | 734 |
|
---|
| 735 | </sect2>
|
---|
| 736 |
|
---|
[b554263] | 737 | </sect1>
|
---|