3 ### Bash startup things
5 ## The `.bashrc' hook will run us if it thinks we haven't been run before.
6 ## We should therefore let it know.
7 export __mdw_profile=done
9 ###--------------------------------------------------------------------------
10 ### Utility functions.
12 ## __mdw_addto VAR DIR PATH ...
14 ## VAR is the name of a PATH-like environment variable (i.e., one which
15 ## contains a sequence of pathnames separated by colons). DIR is either `l'
16 ## or `r'. The PATHs are pathnames. Those PATHs which correspond to
17 ## existing directories but which aren't currently named in the variable are
18 ## added to the left or right (depending on DIR) of VAR. The relative order
19 ## of PATHs added in the same invokation is the same as the order they
20 ## appeared in PATHs: the DIR argument only affects which end of the VAR they
23 local var=$1 val dir=$2 new="" change=nil
27 case "$new:" in *:$i:*) continue;; esac
30 X) val=$i change=t continue ;;
32 X*:$i:*) val=`echo $val | sed -e "s=:$i:=:="` ;;
33 X$i:*) val=${val#$i:} ;;
34 X*:$i) val=${val%:$i} ;;
39 l) val=${new#:}:$val ;;
42 case $change in t) export $var="$val" ;; esac
45 ## __mdw_programp NAME
47 ## Does NAME exist as an executable program?
48 __mdw_programp () { type -t >/dev/null "$1"; }
50 ###--------------------------------------------------------------------------
51 ### Other preliminaries.
53 ## Work out my home directory.
55 ## This horrible trick resolves symbolic links. It enables resolving links,
56 ## changes directory and displays the name of the directory in a subshell to
57 ## avoid changing the current state.
58 HOME=`(set -P; cd $HOME; pwd)`
59 [ -n "$SCHROOT_SESSION_ID" ] || cd $HOME
61 ## CDE's session structure is demented and doesn't leave us with a proper
62 ## logout hook, so synthesize one here.
63 [ -n "$DT" ] && trap "source $HOME/.bash_logout" EXIT
65 ###--------------------------------------------------------------------------
66 ### Set some basic paths.
71 {/usr{/local,}{,/X11R6},}{/bin,/sbin,/games} \
72 /opt/nfast{,/gcc}{/bin,/sbin} \
73 $HOME/src/ncipher/scripts
75 ## If we have Plan 9 from User Space, then add that in.
76 if [ -d /usr/local/plan9 ]; then
77 export PLAN9=/usr/local/plan9
82 ## Search for `info' documents.
83 __mdw_addto INFOPATH r \
85 /usr/info /usr/share/info \
86 /usr/local/info /usr/local/share/info \
87 /usr/local/share/info/its
90 __mdw_addto PERLLIB r $HOME/lib/perl
91 __mdw_addto PYTHONPATH r $HOME/lib/python
93 ###--------------------------------------------------------------------------
94 ### Various other kinds of configuration.
97 if val=$(mdw-conf 2>/dev/null "$2"); then
98 eval "export $1=\$val"
102 ## Establish a temporary directory.
103 [ "$TMPDIR" ] || eval `tmpdir -b`
106 ## Sensible umask if users have their own groups.
109 ## Mail and general identification.
110 __mdw_setconf MAIL mailbox
111 export NAME="Mark Wooding"
112 __mdw_setconf EMAIL email
115 ## Some programs want to know the hostname.
116 [ -z "$HOST" ] && export HOST=`hostname`
118 ## Text editor configuration.
120 emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
122 "emacs23 $emacs_startup_args" \
123 "emacs24 $emacs_startup_args" \
124 "emacs22 $emacs_startup_args" \
125 "emacs21 $emacs_startup_args" \
129 name=`echo $ed | sed 's/ .*$//'`
130 if __mdw_programp "$name"; then
135 export EDITOR=mdw-editor VISUAL=mdw-editor
137 ## Determine the locale settings. Really don't set LC_COLLATE because it
138 ## messes with the order of files in `ls' listings and similar.
139 if [ "$DISPLAY" != "" ]; then
140 LANG=`mdw-conf x-ctype POSIX`
142 : ${LANG=${LC_CTYPE-${LC_ALL-`mdw-conf console-ctype POSIX`}}}
143 case "$TERM,`tty`" in
146 kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
151 LANG=${LANG%.*}$ctype
156 export LC_COLLATE=POSIX LANG
158 ## Pager configuration.
159 export MDW_PAGER=`type -p less` PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
160 export LESS="-iqgRh1j.3FSX"
161 export LESSOPEN="|lesspipe.sh %s"
162 case "${LC_CTYPE-$LANG}" in
163 *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
164 *) LESSCHARSET=latin1 ;;
167 __mdw_programp global && export LESSGLOBALTAGS=global
169 ## HTTP and FTP proxies.
170 http=`mdw-conf http-proxy none`
171 case "${http_proxy-none},$http" in
173 none,*) export http_proxy=http://$http/ ;;
175 ftp=`mdw-conf ftp-proxy none`
176 case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
178 none,none,*) export ftp_proxy=$http_proxy ;;
179 none,*,*) export ftp_proxy=http://$ftp/ ;;
182 ## Ncurses programs should use the Unicode box-drawing characters because the
183 ## alternative character set stuff isn't supported well.
184 export NCURSES_NO_UTF8_ACS=1
186 ## Shut up Perl's readline machinery.
187 export PERL_READLINE_NOWARN=yes
189 ## If we have `distcc' then tell `ccache' to use it.
190 __mdw_programp distcc && export CCACHE_PREFIX=distcc
192 ## Choose a sensible web browser. If we have a display, try to pick a
194 browsers="elinks w3m lynx"
195 case "${DISPLAY+t}" in
196 t) browsers="mdw-iceweasel mdw-chrome iceweasel firefox $browsers" ;;
198 for i in $browsers; do
199 if __mdw_programp $i; then
206 ## Acquiring root privileges. This is mainly the job of `bashrc', but we
207 ## cache the mechanism here.
208 __mdw_setconf __MDW_ROOTLY rootly
209 export BECOME="--preserve-environment"
211 ## It's useful to see the little sigils in `ls'.
212 [ -z "$LS_OPTIONS" ] && export LS_OPTIONS="-F"
214 ## Settings for BBC BASIC listing.
215 export BASCAT="-l +n"
217 ## Version control hacking.
219 __mdw_setconf CVSROOT cvs-root
220 __mdw_setconf SVNROOT svn-root
224 __mdw_setconf NNTPSERVER nntp-server
226 ## Help X programs find their resources.
227 export XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
229 ## Make OpenOffice.org do its thing properly.
230 export OOO_FORCE_DESKTOP=gnome
233 export PS_PERSONALITY=gnu
235 ## Disable core dumps.
238 ###--------------------------------------------------------------------------
239 ### Authentication and SSH hacking.
241 ## Start an authentication agent. This is unnecessarily fiddly. If there's
242 ## a Gnome keyring server then we should use that; unfortunately, it may not
243 ## yet have had a chance to populate the environment with its settings, so we
244 ## go off and fetch them.
245 if { { [ "$GNOME_KEYRING_CONTROL" ] &&
246 [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
247 { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
248 __mdw_programp gnome-keyring-daemon; }; } &&
249 stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null)
252 export SSH_AUTH_SOCK GPG_AGENT_INFO
255 ## If we still don't have an agent then start one with a stable name.
256 eval `start-ssh-agent -b`
258 ## Decide whether this session should be considered `secure'. A session is
259 ## secure if it's on a secure TTY, but there are lots of ways of finding out
260 ## which TTYs are secure.
261 if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
262 ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
263 { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
264 { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
265 egrep "$devtty" $sectty >/dev/null; } ||
266 { [ -e /etc/default/login ] &&
267 egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
268 case "${tty#/dev/}" in
269 console|systty|tty[0-9]) true ;;
273 export __mdw_sechost="`hostname`"
276 ## Start a passphrase pixie if there is one and it's not already running.
277 if pixie --version >/dev/null 2>&1; then
278 mkdir -p $HOME/.catacomb
279 pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
280 if [ -S "$pixie" ] && pixie -C help >/dev/null 2>/dev/null; then
283 pixie -d 2>>$HOME/.catacomb/pixie.log
284 __mdw_started_pixie=yes
288 ###--------------------------------------------------------------------------
289 ### Finishing touches.
291 ## If there's a local hook then run it.
292 [ -f "$HOME/.profile-local" ] && . "$HOME/.profile-local"
294 ## If we haven't run the `.bashrc' yet, and this shell is interactive, then
296 [ -z "$__mdw_bashrc" ] && [ -t 0 ] && \
297 [ -r $HOME/.bashrc ] && . $HOME/.bashrc
299 ###----- That's all, folks --------------------------------------------------