Next Previous Contents

4. Software Configuration

These are the the configuration files we are going to custimise: /etc/profile /etc/bashrc .bashrc .bashrc .bash_profile .bash_logout .inputrc .less .lessrc .xinitrc .fvwmrc .fvwm2rc95 .Xmodmap .Xmodmap.num .Xdefaults .jedrc .abbrevs.sl .joerc .emacs . Don't add users until you have completed your system configuration; you'll put the dot files in /etc/skel.

4.1 bash(1)

Arguably, the most important piece of software after the kernel. To tailor the behaviour of bash, these are the main files to edit:

Examples of these files are shown below. First, the most important: /etc/profile. It's used to configure a lot of features in your Linux box, as you will see in the following sections. Please look out for reverse quotes!


# /etc/profile

# System wide environment and startup programs
# Functions and aliases go in /etc/bashrc

# This file sets up the following features and programs:
# path, prompts, a few environment variables, colour ls, less,
# rxvt, Backspace key behaviour, xterm title.
#
# Users can override these settings and/or add others in their
# $HOME/.bash_profile

# first: root or normal user? Set PATH and umask accordingly. Note that the
# PATH is normally set by login(1), but what if you access the machine
# via ssh?

if [ $(id -gn) = $(id -un) -a $(id -u) -gt 14 ]; then
  umask 002  # normal user
  PATH="/usr/local/bin:/bin:/usr/bin:."
else
  umask 022  # root
  PATH="/sbin:/bin:/usr/sbin:/usr/bin"
fi

# Now extend the PATH.
PATH="$PATH:/usr/X11R6/bin:$HOME/bin:." # !!! Beware of ./ !!!

# notify the user: login or non-login shell. If login, the prompt is
# blue; otherwise, magenta. Root's prompt is red.
# See the Colour-ls mini HOWTO for an explanation of the escape codes.
USER=$(whoami)
if [ $LOGNAME = $USER ] ; then
  COLOUR=44  # blue
else
  COLOUR=45  # magenta
fi

if [ $USER = 'root' ] ; then
  COLOUR=41  # red
  PATH="$PATH:/usr/local/bin" # my choice
fi

ESC="\033"
PROMPT='\h'    # hostname
STYLE='m'      # plain
# PROMPT='\u'  # username
# STYLE=';1m'  # bold
PS1="\[$ESC[$COLOUR;37$STYLE\]$PROMPT:\[$ESC[37;40$STYLE\]\w\\$ "
PS2="> "

# Ulimits: no core dumps, max file size 200 Mb.
ulimit -c 0 -f 200000

# a few variables
USER=$(id -un)
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"  # sendmail, postfix, smail
# MAIL="$HOME/Mailbox"        # qmail
NNTPSERVER=news.myisp.it      # put your own here
VISUAL=jed
EDITOR=jed
HOSTNAME=$(/bin/hostname)
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 PS2 USER LOGNAME MAIL NNTPSERVER
export VISUAL EDITOR HOSTNAME HISTSIZE HISTFILESIZE

# enable colour ls
eval $(dircolors /etc/DIR_COLORS -b)
export LS_OPTIONS='-s -F -T 0 --color=yes'

# customize less
LESS='-M-Q'
LESSEDIT="%E ?lt+%lt. %f"
LESSOPEN="| lesspipe.sh %s"
LESSCHARDEF=8bcccbcc13b.4b95.33b. # show colours in ls -l | less
# LESSCHARSET=latin1
PAGER=less
export LESS LESSEDIT LESSOPEN VISUAL LESSCHARDEF PAGER

# you might need this to fix the backspace key in rxvt/xterm
stty erase ^H  # alternative: ^?

# set xterm title: full path
case $TERM in
  xterm*|rxvt)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    ;;
esac      

for i in /etc/profile.d/*.sh ; do
  if [ -x $i ]; then
    . $i # beware - variables and aliases might get overridden!
  fi
done

# call fortune, if available 
if [ -x /usr/games/fortune ] ; then
echo ; /usr/games/fortune ; echo 
fi

This is a sample /etc/bashrc:


# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile
# Insert PS1 definitions here if you experience problems.

export CDPATH="$CDPATH:~"

# common aliases
alias cp='cp -i'
alias l=less
alias ls="ls $LS_OPTIONS"
alias mv='mv -i'
alias rm='rm -i'
alias rmbk='/bin/rm -f .*~ *~ *aux *bak *log *tmp 2> /dev/null'
alias u='cd ..'
alias which="type -path"
alias x=startx

# A few useful functions
c ()    # cd to the new directory and list its contents
{
  cd $1 ; ls
}

inst()  # Install a .tar.gz archive in current directory
{
  if [ $# != 0 ]; then tar zxvf $1; fi
}

cz()    # List the contents of a .zip archive
{
  if [ $# != 0 ]; then unzip -l $*; fi
}

ctgz()  # List the contents of a .tar.gz archive
{
  for file in $* ; do
    tar ztf ${file}
  done
}

tgz()   # Create a .tgz archive a la zip.
{
  if [ $# != 0 ]; then
    name=$1.tar; shift; tar -rvf ${name} $* ; gzip -9 ${name}
  fi
}

crpm()  # list information on an .rpm file
{
  if [ $# != 0 ]; then rpm -qil $1 | less; fi
}

This is a sample .bashrc:


# $HOME/.bashrc
# Source global definitions

if [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi

# this is needed to notify the user that they are in non-login shell
if [ "$GET_PS1" = "" ] ; then
  COLOUR=45; ESC="\033"; STYLE=';1m';  # STYLE='m'
  USER=$(whoami)
  export PS1="\[$ESC[$COLOUR;37$STYLE\]$USER:\[$ESC[37;40$STYLE\]\w\\$ "
fi

# personal aliases
alias backup='tar -Mcvf /dev/fd0'
alias dial='eznet up myisp'
alias f='cd ~/fortran'
alias hangup='eznet down'
alias lyx='lyx -width 580 -height 450'
alias restore='tar -M -xpvf /dev/fd0'

# personal functions
xj()    # Launch xjed and a file in background
{
  xjed $1 &
}

This is a sample .bash_profile:


# $HOME/.bash_profile

# User specific environment and startup programs
# This file contains user-defined settings that override
# those in /etc/profile

# Get user aliases and functions
if [ -f ~/.bashrc ]; then
  GET_PS1="NO"  # don't change the prompt colour
  . ~/.bashrc
fi
    
# set a few `default' directories
export CDPATH="$CDPATH:$HOME:$HOME/text:$HOME/text/geology"

This is a sample .inputrc:


# $HOME/.inputrc

# key bindings
"\e[1~": beginning-of-line
"\e[3~": delete-char
"\e[4~": end-of-line
# (F1 .. F5) are "\e[[A" ... "\e[[E"
"\e[[A": "info \C-m"

set bell-style visible          # please don't beep
set meta-flag On                # allow 8-bit input (i.e, accented letters)
set convert-meta Off            # don't strip 8-bit characters
set output-meta On              # display 8-bit characters correctly
set horizontal-scroll-mode On   # scroll long command lines
set show-all-if-ambiguous On    # after TAB is pressed

To make the backspace and delete keys work correctly in xterm and other X11 applications, the following is also needed:

rxvt is a wee bit more complicated, as some compile--time options influence its behaviour. See the above /etc/profile.

More info in bash(1) and readline(3) man pages.

Don't expect every application to work correctly! If you run joe in xterm, for instance, some keys won't work; the same holds for some versions of rxvt.

4.2 I18n

(This section doesn't apply to native English speakers.)

A.k.a. ``internationalisation''. Gasp. This long word means ``to adapt Linux to your local conventions: language, format of date, currency etc.''.

Although Red Hat has its own method for setting up i18n (/etc/sysconfig/i18n), you may want to enable your language only in some cases. I, for one, enabled i18n in kdm (via kdmconfig) and xfce, but want to read English messages when I work in console or xterm.

Consider these lines:

LANG=it # choose your language: fr, de, es, ...
LANGUAGE=it
LC_ALL=it
export LANG LANGUAGE LC_ALL

If you insert them in your .xinitrc or .xsession just before the line that starts the window manager, you'll get internationalised messages - including those in xterms started from within the window manager. But if you'd rather get English messages, set the language to ``en'' and put the same lines in .bash_profile.

4.3 ls(1)

ls can display directory listings using colours to highlight different file types. To enable this feature, you just need a couple of lines in /etc/profile as seen above. However, this won't work with old versions of rxvt; use some flavour of xterm instead. It looks like some old rxvts have a bug that prevents them from inheriting the environment correctly in some circumstances.

4.4 less(1)

With this excellent pager you can browse not only plain text files, but also gzip compressed, tar and zip archives, man pages, and what have you. Its configuration involves a few steps:

4.5 Editor

Only the most popular will be covered here.

emacs(1)

I rarely use emacs, so I have only a couple of tips for you. Some emacs distributions don't come preconfigured for colours and syntax highlighting. Put this in your .emacs:

(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

This only works in X11. Moreover, to enable accented characters you'll add this line:

(standard-display-european 1)

I'll leave it to you to peruse all of emacs' documentation to find out how to tailor it to your needs---potentially, it can take months of hacking. The Dotfile generator (Section Configuration Software) is a good helping hand.

joe(1)

Some versions of joe don't work with colours in console, and some special keys don't work either. A quick and dirty (and inelegant) solution to the former problem is this:

~$ export TERM=vt100
~$ joe myfile
   (edit your file)
~$ export TERM=linux

To make the special keys work, all you have to do is edit .joerc, .jstarrc or your favourite emulation; you can start from the system-wide config files in /usr/lib/joe. Look for the fourth section (key bindings). This enables Home and End:

bol ^[ [ 1 ~    Go to beginning of line
eol ^[ [ 4 ~    Go to end of line

Find out the desired ESC sequences typing cat followed by the special keys.

jed(1)

This is my favourite editor: it does what I need, it's lighter and easier to configure than emacs, and emulates other editors quite well. Many users at my university use jed to emulate EDT, VMS' system editor.

jed's configuration files are .jedrc and /usr/lib/jed/lib/*; the former can be adapted from jed.rc in the latter directory.

4.6 pine(1)

Edit the global configuration in /usr/lib/pine.conf, taking care at least of the following fields: user-domain, smtp-server, and nntp-server. Note that inbox-path depends on your MTA: if you use sendmail or postfix, that'll be var/spool/mail/$USER; with Qmail, /home/$USER/Mailbox (but root will use /var/qmail/alias/Mailbox.

4.7 minicom(1)

Users can't use minicom unless a global configuration has been made by root. Remember to make it.

4.8 efax(1)

This package is probably the most convenient for simple sending/receiving of faxes. You'll have to tailor the script /usr/bin/fax or (mandrake) /etc/fax.config; easy job, but a couple of quirks caused me quite a headache:

That done, there are a few permissions to fix to enable non-root users to send and receive faxes. The directories /var/lock and /var/spool/fax must be writable. To do so, create the group faxusers, add users to it, then type:

~# chown root.faxusers /var/lock
~# mkdir /var/spool/fax # if it doesn't exist yet
~# chown root.faxusers /var/spool/fax; chmod g+w /var/spool/fax

As a normal user, you'll issue newgrp faxusers before sendig a fax.

4.9 Ghostscript

This essential tool suffers from a small snag. Owing to to the well-known export regulations in the USA, the utility pdf2ps doesn't work with encrypted .pdf files. Never mind: point your browser to http://www.ozemail.com.au/~geoffk/pdfencrypt, download the file pdf_sec.ps and replace the file with the same name that comes with the Ghostscript distribution.

4.10 TeX and Friends

The ``root'' of a TeX system is the directory $TEXMF, which is /usr/share/texmf in teTeX; other distributions may differ (search for ``texmf'' on your system). You normally add stuff or fiddle with files therein.

Expanding $TEXINPUTS

To include PostScript figures or TeX files that reside in subdirectories, it is convenient to expand TeX's search path to include subdirectories. Put this command in your .bash_profile:

export TEXINPUTS="$HOME/mylib::./figures"

which makes TeX search in $HOME/mylib before the default directories, and the directory ./figures afterwards.

Hyphen Patterns

To configure the hyphenation pattern for your language, edit the file $TEXMF/tex/generic/config/language.dat, then do:

~# texconfig init ; texconfig hyphen

Even if you don't write in English, don't remove the entry ``english''; TeX pukes without it.

Dvips

To tailor dvips, the file to edit is $TEXMF/dvips/config/config.ps. Be aware that the fields regarding the default resolution also affect xdvi's behaviour; if you experience annoying attempts to create fonts each time you run it, put the line

XDvi*mfmode:

in your .Xdefault. This should help.

Adding LaTeX Packages

Additional LaTeX packages are available from your nearest CTAN (Comprehensive TeX Archive Network) mirror site, e.g. ftp://ftp.dante.de/pub/tex. Unpack the package under $TEXMF/tex/latex.

If no .sty file exist, run the command latex newstyle.ins or latex newstyle.dtx to create it, then run the command texhash so that teTeX recognises the new package.

4.11 Avoid PPProblems!

I'll take it for granted that your kernel has PPP + TCP/IP support compiled in, that loopback is enabled, and that you already have the pppd package correctly installed and, if you will, set uid root. Obviously, your ISP must support PPP.

There are now two ways to get PPP to work: a) manual configuration, and b) a configuration program that automagically sees to it. Whichever option you choose, have the following information on hand:

Manual configuration is a drudgery. It's about editing files and writing scripts; not too much work, but it's easy to make mistakes and newcomers are often intimidated. The PPP HOWTO is there for you. Alternatively, there are tools that ask for the information above and do all the work.

Gnome and KDE include, respectively, gnome-ppp and kppp which are easy enough to set up. Alternatively, I suggest that you have a look at a couple of tty--based tools, wvdial and eznet. You feed them your ISP's phone number, your username, your password, and you're in business. Their home pages are at http://www.worldvisions.ca/wvdial and http://www.hwaci.com/sw/eznet. Both are great, but I prefer the latter.

A Quick Start with eznet

First of all, create an /etc/resolv.conf like this:

nameserver w.x.y.z

where you'll insert the address of your ISP's nameserver. To create an account with eznet, issue the following command:

#~ eznet add service=YOUR_ISP user=NAME password=PASSWORD phone=PHONE

which creates the file /var/eznet/eznet.conf, owned by root.root with permissions 600; chmod it to 666 if you want it to be world readable. Now dial your ISP with eznet up YOUR_ISP. If the modem keeps waiting for the dial tone and won't connect, then try this command:

#~ eznet change YOUR_ISP init0=atx3

To hang up, the command is eznet down. That's all!

A Quick Start with wvdial

wvdial's setup is even shorter. Type wvdialconf /etc/wvdial.conf, then edit the resulting file to include your username, password, and phone number. Try it out with wvdial, and keep your fingers crossed. To hang up, stop it with Ctrl-C.

4.12 POP Client

To retrieve your mail from a POP3 server, you need a POP client. Most such clients require that you run an MTA like sendmail, qmail or postfix; a bit of an overkill on low-spec machines. However, there are clients that work without an MTA. The first kind is well represented by fetchmail; the second by fetchpop or frenchie. Sites: ftp://metalab.unc.edu/pub/Linux/system/mail/pop, http://www.lowcountry.com/~jscottb/tcltk.shtml.

To configure these clients:

4.13 Basic Mail Filtering

You will want to protect yourself from spam or huge mail messages. There are two cases: 1) permanent connection to the net, 2) a POP link. In the first case, you can write a .procmailrc file, while in the second there are tools for checking the mail prior to fetching it.

A very simple .procmailrc that defines a few rules:

# $HOME/.procmailrc

MAILDIR=$HOME/mail # make sure it exists

# Store messages directed to the "foo" mailing list to $HOME/mail/foo
:0
* ^To:.*foo
foo

# Discard messages that are not explicitly sent to me or to one of the
# mailling lists I subscribed to.
:0
* !^TO(guido|jed|lugvr|ldp|nobody)
/dev/null

# ditto, for messages larger than 50k.
:0
* > 50000
/dev/null

man procmailex for further examples.

POP users will want to use poppy, a useful Perl script for checking the mail before fetching it. Get it from ftp://metalab.unc.edu/system/mail/pop.

4.14 X Window System (XFree86)

Setting Up the X Server

Come on, it's no longer as difficult as it used to be... All major distributions include a tool for setting up X11 (e.g. XConfigurator, sax, XF86Setup, or at least xf86config). X configuration is virtually automatic these days, but a few video cards may cause a headache.

First of all, check out at the XFree86 site ( http://www.xfree86.org) whether your video card is supported. If so, then try this procedure:

This has always worked for me, but your mileage may vary. Please note that most times X11 won't start because you chose wrong specs for your monitor! Start with conservative settings, i.e. 800x600 and 256 colours, then pump it up. Warning: these operations are dangerous and your monitor might be damaged!

If your card isn't supported, you can either: 1) wait for the next version of XFree86; 2) buy a commercial X server; 3) buy a supported video card. Quartum non datur.

Keypad

We have seen above how to make a few special keys work. The sample file .Xmodmap works well if you want to use Xjed, but it makes the keypad unusable. You'll then need another config file, which we'll call .Xmodmap.num:

! Definitions can be found in <X11/keysymdef.h>

keycode 77  = Num_Lock
keycode 112 = KP_Divide
keycode 63  = KP_Multiply
keycode 82  = KP_Subtract
keycode 86  = KP_Add
keycode 79  = KP_7
keycode 80  = KP_8
keycode 81  = KP_9
keycode 83  = KP_4
keycode 84  = KP_5
keycode 85  = KP_6
keycode 87  = KP_1
keycode 88  = KP_2
keycode 89  = KP_3
keycode 90  = KP_0
keycode 91  = KP_Decimal

Make sure that your /etc/X11/XF86Config does not contain these three lines:

  ServerNumLock
  Xleds
  XkbDisable

and in case, comment them out. To re-enable the keypad, you'll issue the command xmodmap .Xmodmap.num.

Graphical Login with xdm

To be greeted by a graphical login, edit the file /etc/inittab, which should include a line like this:

x:5:respawn:/usr/bin/X11/xdm -nodaemon # also kdm or gdm

where 5 is the runlevel corresponding to X11. Modify the line that defines the default runlevel (usually 2 or 3), changing it as above:

id:5:initdefault:

The number of colours is specified in /etc/X11/xdm/Xserver:

:0 local /usr/X11R6/bin/X :0 -bpp 16 vt07  # first X server, 65k colours
:1 local /usr/X11R6/bin/X :1 -bpp 32 vt08  # second X server, true colour

If you already have .xinitrc, copy it to .xsession and make the latter executable with chmod +x .xsession. Now issue the command telinit 5 and you're in business.

Window Manager

Once X works, there are endless possibilities of configuration; it depends on the window manager you use, there are tens to choose from. Mostly, it's all down to editing one or more ASCII files in your home directory; in other cases you don't have to edit a thing, and use an applet or even a menu.

Some examples:

In short: if you don't mind editing config file, choose something like icewm, fvwm*, blackbox etc; if you do mind, the choice is currently restricted to KDE, Gnome, WindowMaker, and Xfce. Email me if I'm wrong.

It's important to have a good .xinitrc. An example:

#!/bin/sh
# $HOME/.xinitrc

usermodmap=$HOME/.Xmodmap
xmodmap $usermodmap

xset s noblank  # turn off the screen saver
xset s 300 2    # screen saver start after 5 min
xset m 10 5     # set mouse acceleration

rxvt -cr green -ls -bg black -fg white -fn 7x14 \
  -geometry 80x30+57+0 &

if [ "$1" = "" ] ; then  # default
  WINMGR=wmaker
else
  WINMGR=$1
fi

$WINMGR

Although it doesn't appear to be strictly required, make it executable with chmod +x .xinitrc.

The .xinitrc above lets you choose the window manager: try

$ startx startkde # or other w.m.

Defaults for X11 Apps

Find out where the app-defaults directory is (it should be /usr/X11R6/lib/X11/app-defaults). Several apps keep a configuration file there.

Adding Fonts

Recent versions of XFree86 (say, > 3.3.4) use an X Font Server that supports PostScript Type 1 and True Type fonts natively, so you can use the wealth of fonts available on the net. There's a simple procedure to follow.

Suppose that you download a Type 1 font collection, e.g. Freefont ( ftp://ftp.gimp.org/pub/gimp/fonts/freefonts-0.10.tar.gz). To make it visible to the font server, unpack the archive from /usr/X11R6/lib/X11/fonts/. Then edit /etc/X11/fs/config, add an entry for the new directory, and restart the font server.

If you're rolling your own font collection, you'll need to supply the files fonts.dir and fonts.scale; the tool to make them is type1inst, available from http://http://goblet.anu.edu.au/~m9305357/type1inst.html.

As for the True Type fonts, group them in a directory of your choice and create fonts.dir using ttmkfdir > fonts.dir, included in the Freetype archive; http://www.freetype.org. Then proceed as above. For example, if you want to use the Windows fonts you have in, say, /mnt/win/windows/fonts, go to that directory, run ttmkfdir, edit /etc/X11/fs/config and restart the font server.

It all started from the original True Type X font server: http://http://www.dcs.ed.ac.uk/home/jec/programs/xfsft/.

4.15 Users' Configurations

When you're done editing the dot files, copy them to /etc/skel as seen in Section Software Configuration.

4.16 Making .rpms

rpm is such a wonderful method of keeping packages under control that I'm reluctant to install .tar.gz archives but in very few special cases (e.g., security). Whenever you install a tarball, consider turning it into an .rpm archive, then reinstall it; consult the RPM HOWTO. Also, if you use recent gcc versions, it may be advisable to put this in your /etc/rpmrc:

optflags: i386 -O2 -mpentiumpro

4.17 Upgrading

If you upgrade your machine, do your backup as usual and remember to save a few additional files. Some could be /etc/X11/XF86Config, /usr/bin/fax, all the stuff in /usr/local, the kernel configuration, the whole /etc, and all the mail in /var/spool/mail.

Then it's time to upgrade (in rare cases, downgrade!) applications that your distribution ship with, and to add additional packages. Keep a list of these ones.


Next Previous Contents