Monday, April 22, 2013

Shell initialization files

So, after a while I'm back writing a few posts on this blog.
This time I'm struggling to endure against the shadows of the evil.
They want to destroy everything that's fair, good and honest.
I'm thirsty for the Divine Justice to fix what's wrong.

Sorry, I needed to get that off my chest.
Now let's stick to our humble attempt to build what's good.



I'd say the chief way to administer Solaris is at the CLI (command line interface).
In Unix this is also traditionally known as the shell, which in Solaris 11 is bash by default.

Nowadays there's that beast called Ops Center which I dislike due to:
  • It's an extremely heavy-weight and resource-hungry software.
  • It's operations are mostly, if not completely, black-box style.
  • It's suited to a common-least-denominator, to lazy sysadmins.
  
I prefer to count on my own to carry out administration.
Hence the importance of being comfortable at the shell level.
As each person is unique, it's clear that so is customization.

My personal approach, as much as possible, is:
  • Stick to the defaults
  • Strive for simplicity
  • Always keep clarity
  
What I find absolutely essential in customizing the shell follows:

$ touch .hushlogin

$ cat .profile
# Solaris 10 and below.
# The /opt/sfw/bin is installed from the companion CD.
if [[ `uname -r |cut -d. -f2` -lt 11 ]]
then
  PATH="/opt/sfw/bin:/usr/bin:/usr/sbin:/sbin"; export PATH
  MANPATH=/usr/man; export MANPATH
  EDITOR=/opt/sfw/bin/vim; export EDITOR

fi

$ cat .bash_profile
source .bashrc

$ cat .bashrc
# On Solaris 11 Express, consider prepending /usr/gnu/bin.
PATH=/usr/bin:/usr/sbin
PATH=$PATH:<other paths>
export PATH

MANPATH=/usr/man
MANPATH=$MANPATH:<other paths>
export MANPATH

export PAGER="/usr/bin/less -ins"
export EDITOR=/usr/bin/vim

#
# Note the handy \n for spacing commands,
# the  ANSI escape sequences - colors (when supported)
# and the \n before the \$
#
  
if [[ "$TERM" == sun-color ]] || \
   [[ "$TERM" == xterm ]] || \
   [[ "$TERM" == screen ]]
then 
  O='\[\e[0m\]'        # all off
  B='\[\e[0;1m\]'      # bright / bold
  Y='\[\e[0;33m\]'     # (dark) yellow /orange 
  #
  PS1="$O\n"
  PS1="$PS1"$([[ "$LOGNAME" != root ]] && echo "$Y\u$B@")
  PS1="$PS1$Y\h$B:$O\w\n$B\\\$$O " 
else
  PS1="\n"
  PS1="$PS1"$([[ "$LOGNAME" != root ]] && echo "\u@")
  PS1="$PS1\h:\w\n\\$
fi
export PS1

#
# If latency is a problem, replace below -lh with -nh. 
#

alias l="ls -lh --color"
alias la='ls -a -lh --color'

alias L='ls -L -lh --color'
alias La='ls -a -L -lh --color'
   
 
alias md=mkdir

#
# This system uses special RLE configurations. 
# This is related to Staged Building of extra software.
#

export LD_CONFIG_32=~/.ldconfig-32
[[ -t 0 ]] && echo LD_CONFIG_32=$LD_CONFIG_32

crle -c $LD_CONFIG_32 -l /opt/gnu/lib:/opt/usr/lib -l /lib:/usr/lib
[[ -t 0 ]] && crle -c $LD_CONFIG_32

$ cat .inputrc
#
# See bash(1) Readline Command Names section or readline(3).
#
# For a sample contents check:
#   1) The .inputrc revisited
#   2) Keyboard - Layouts.
#
# Check the Some .inputrc detail post for historical issues.
# Check the Another .inputrc feature post for additional ideas.
#
...

In the output below, ^[ was entered in VIM as ^V + Esc:

# cat /etc/motd
b
  ^[[31mSolaris 11.3^[[0;2m (September 2015)^[[0m
b 

It may be good to check the Security & consent banner as well.
An depending on how the shell is launched: SSH login-time initializations.