| 1 | ### -*-bash-*- |
| 2 | ### |
| 3 | ### Bash startup things |
| 4 | |
| 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 |
| 8 | |
| 9 | ###-------------------------------------------------------------------------- |
| 10 | ### Utility functions. |
| 11 | |
| 12 | ## __mdw_addto VAR DIR PATH ... |
| 13 | ## |
| 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 |
| 21 | ## get added to. |
| 22 | __mdw_addto () { |
| 23 | local var=$1 val dir=$2 new="" change=nil |
| 24 | eval "val=\$$var" |
| 25 | shift 2 |
| 26 | for i in "$@"; do |
| 27 | case "$new:" in *:$i:*) continue;; esac |
| 28 | [ -d $i ] || continue |
| 29 | case "X$val" in |
| 30 | X) val=$i change=t continue ;; |
| 31 | X$i) continue ;; |
| 32 | X*:$i:*) val=`echo $val | sed -e "s=:$i:=:="` ;; |
| 33 | X$i:*) val=${val#$i:} ;; |
| 34 | X*:$i) val=${val%:$i} ;; |
| 35 | esac |
| 36 | new=$new:$i change=t |
| 37 | done |
| 38 | case $dir in |
| 39 | l) val=${new#:}:$val ;; |
| 40 | r) val=$val$new ;; |
| 41 | esac |
| 42 | case $change in t) export $var="$val" ;; esac |
| 43 | } |
| 44 | |
| 45 | ## __mdw_programp NAME |
| 46 | ## |
| 47 | ## Does NAME exist as an executable program? |
| 48 | __mdw_programp () { type -t >/dev/null "$1"; } |
| 49 | |
| 50 | ###-------------------------------------------------------------------------- |
| 51 | ### Other preliminaries. |
| 52 | |
| 53 | ## Work out my home directory. |
| 54 | ## |
| 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 | cd $HOME |
| 60 | |
| 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 |
| 64 | |
| 65 | ###-------------------------------------------------------------------------- |
| 66 | ### Set some basic paths. |
| 67 | |
| 68 | ## The main path. |
| 69 | __mdw_addto PATH l \ |
| 70 | $HOME/bin \ |
| 71 | {/usr{/local,}{,/X11R6},}{/bin,/sbin,/games} \ |
| 72 | /opt/nfast{,/gcc}{/bin,/sbin} \ |
| 73 | $HOME/src/ncipher/scripts |
| 74 | |
| 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 |
| 78 | __mdw_addto PATH r \ |
| 79 | $PLAN9/bin |
| 80 | fi |
| 81 | |
| 82 | ## Search for `info' documents. |
| 83 | __mdw_addto INFOPATH r \ |
| 84 | $HOME/info \ |
| 85 | /usr/info /usr/share/info \ |
| 86 | /usr/local/info /usr/local/share/info \ |
| 87 | /usr/local/share/info/its |
| 88 | |
| 89 | ## Script libraries. |
| 90 | __mdw_addto PERLLIB r $HOME/lib/perl |
| 91 | __mdw_addto PYTHONPATH r $HOME/lib/python |
| 92 | |
| 93 | ###-------------------------------------------------------------------------- |
| 94 | ### Various other kinds of configuration. |
| 95 | |
| 96 | ## Establish a temporary directory. |
| 97 | [ "$TMPDIR" ] || eval `tmpdir -b` |
| 98 | export TMP=$TMPDIR |
| 99 | |
| 100 | ## Sensible umask if users have their own groups. |
| 101 | umask 002 |
| 102 | |
| 103 | ## Mail and general identification. |
| 104 | export MAIL=`mdw-conf mailbox` |
| 105 | export NAME="Mark Wooding" |
| 106 | export EMAIL=`mdw-conf email` |
| 107 | export QMAILINJECT=c |
| 108 | |
| 109 | ## Some programs want to know the hostname. |
| 110 | [ -z "$HOST" ] && export HOST=`hostname` |
| 111 | |
| 112 | ## Text editor configuration. |
| 113 | export MDW_EDITOR=ed |
| 114 | emacs_startup_args="--no-site-file --mdw-fast-startup -nw" |
| 115 | for ed in \ |
| 116 | "emacs22 $emacs_startup_args" \ |
| 117 | "emacs21 $emacs_startup_args" \ |
| 118 | zile mg \ |
| 119 | "emacs -nw" \ |
| 120 | vi pico nano ae; do |
| 121 | name=`echo $ed | sed 's/ .*$//'` |
| 122 | if __mdw_programp "$name"; then |
| 123 | MDW_EDITOR=$ed |
| 124 | break |
| 125 | fi |
| 126 | done |
| 127 | export EDITOR=mdw-editor VISUAL=mdw-editor |
| 128 | |
| 129 | ## Determine the locale settings. Really don't set LC_COLLATE because it |
| 130 | ## messes with the order of files in `ls' listings and similar. |
| 131 | if [ "$DISPLAY" != "" ]; then |
| 132 | LANG=`mdw-conf x-ctype` |
| 133 | else |
| 134 | : ${LANG=${LC_CTYPE-${LC_ALL-`mdw-conf console-ctype`}}} |
| 135 | case "$TERM,`tty`" in |
| 136 | linux,/dev/tty*) |
| 137 | if { vt-is-UTF8 || |
| 138 | kbd_mode | grep UTF-8; } >/dev/null 2>&1; then |
| 139 | ctype=.utf8 |
| 140 | else |
| 141 | ctype= |
| 142 | fi |
| 143 | LANG=${LANG%.*}$ctype |
| 144 | ;; |
| 145 | esac |
| 146 | fi |
| 147 | unset LC_ALL |
| 148 | export LC_COLLATE=POSIX LANG |
| 149 | |
| 150 | ## Pager configuration. |
| 151 | export MDW_PAGER=`type -p less` PAGER=mdw-pager METAMAIL_PAGER=mdw-pager |
| 152 | export LESS="-iqgRh1FSX" |
| 153 | export LESSOPEN="|lesspipe.sh %s" |
| 154 | case "${LC_CTYPE-$LANG}" in |
| 155 | *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;; |
| 156 | *) LESSCHARSET=latin1 ;; |
| 157 | esac |
| 158 | export LESSCHARSET |
| 159 | __mdw_programp global && export LESSGLOBALTAGS=global |
| 160 | |
| 161 | ## HTTP and FTP proxies. |
| 162 | http=`mdw-conf http-proxy none` |
| 163 | case "${http_proxy-none},$http" in |
| 164 | *,none) ;; |
| 165 | none,*) export http_proxy=http://$http/ ;; |
| 166 | esac |
| 167 | ftp=`mdw-conf ftp-proxy none` |
| 168 | case "${ftp_proxy-none},$ftp,${http_proxy-none}" in |
| 169 | *,none,none) ;; |
| 170 | none,none,*) export ftp_proxy=$http_proxy ;; |
| 171 | none,*,*) export ftp_proxy=http://$ftp/ ;; |
| 172 | esac |
| 173 | |
| 174 | ## Ncurses programs should use the Unicode box-drawing characters because the |
| 175 | ## alternative character set stuff isn't supported well. |
| 176 | export NCURSES_NO_UTF8_ACS=1 |
| 177 | |
| 178 | ## Shut up Perl's readline machinery. |
| 179 | export PERL_READLINE_NOWARN=yes |
| 180 | |
| 181 | ## If we have `distcc' then tell `ccache' to use it. |
| 182 | __mdw_programp distcc && export CCACHE_PREFIX=distcc |
| 183 | |
| 184 | ## Choose a sensible web browser. If we have a display, try to pick a |
| 185 | ## graphical one. |
| 186 | browsers="elinks w3m lynx" |
| 187 | case "${DISPLAY+t}" in |
| 188 | t) browsers="mdw-chrome iceweasel firefox $browsers" ;; |
| 189 | esac |
| 190 | for i in $browsers; do |
| 191 | if __mdw_programp $i; then |
| 192 | export BROWSER=$i |
| 193 | break |
| 194 | fi |
| 195 | done |
| 196 | unset browsers |
| 197 | |
| 198 | ## Acquiring root privileges. This is mainly the job of `bashrc', but we |
| 199 | ## cache the mechanism here. |
| 200 | export __MDW_ROOTLY=`mdw-conf rootly` |
| 201 | export BECOME="--preserve-environment" |
| 202 | |
| 203 | ## It's useful to see the little sigils in `ls'. |
| 204 | [ -z "$LS_OPTIONS" ] && export LS_OPTIONS="-F" |
| 205 | |
| 206 | ## Settings for BBC BASIC listing. |
| 207 | export BASCAT="-l +n" |
| 208 | |
| 209 | ## Version control hacking. |
| 210 | export CVS_RSH=ssh |
| 211 | export CVSROOT=`mdw-conf cvs-root` |
| 212 | export SVNROOT=`mdw-conf svn-root` |
| 213 | export P4CONFIG=.p4 |
| 214 | |
| 215 | ## News server. |
| 216 | [ -z "$NNTPSERVER" ] && export NNTPSERVER=`mdw-conf nntp-server` |
| 217 | |
| 218 | ## Help X programs find their resources. |
| 219 | export XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S" |
| 220 | |
| 221 | ## Make OpenOffice.org do its thing properly. |
| 222 | export OOO_FORCE_DESKTOP=gnome |
| 223 | |
| 224 | ## Configure `ps'. |
| 225 | export PS_PERSONALITY=gnu |
| 226 | |
| 227 | ## Disable core dumps. |
| 228 | ulimit -S -c 0 |
| 229 | |
| 230 | ###-------------------------------------------------------------------------- |
| 231 | ### Authentication and SSH hacking. |
| 232 | |
| 233 | ## Start an authentication agent. This is unnecessarily fiddly. If there's |
| 234 | ## a Gnome keyring server then we should use that; unfortunately, it may not |
| 235 | ## yet have had a chance to populate the environment with its settings, so we |
| 236 | ## go off and fetch them. |
| 237 | if { { [ "$GNOME_KEYRING_CONTROL" ] && |
| 238 | [ -s "$GNOME_KEYRING_CONTROL" ]; } || |
| 239 | { [ "$DBUS_SESSION_BUS_ADDRESS" ] && |
| 240 | dbus-send --session --print-reply --dest=org.freedesktop.DBus \ |
| 241 | / org.freedesktop.DBus.GetNameOwner string:org.gnome.keyring \ |
| 242 | >/dev/null 2>/dev/null; }; } && |
| 243 | stuff=$(gnome-keyring-daemon -s -c ssh 2>/dev/null) |
| 244 | then |
| 245 | eval "$stuff" |
| 246 | export SSH_AUTH_SOCK |
| 247 | fi |
| 248 | |
| 249 | ## If we still don't have an agent then start one with a stable name. |
| 250 | eval `start-ssh-agent -b` |
| 251 | |
| 252 | ## Decide whether this session should be considered `secure'. A session is |
| 253 | ## secure if it's on a secure TTY, but there are lots of ways of finding out |
| 254 | ## which TTYs are secure. |
| 255 | if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] || |
| 256 | ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}" |
| 257 | { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } || |
| 258 | { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } && |
| 259 | egrep "$devtty" $sectty >/dev/null; } || |
| 260 | { [ -e /etc/default/login ] && |
| 261 | egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } || |
| 262 | case "${tty#/dev/}" in |
| 263 | console|systty|tty[0-9]) true ;; |
| 264 | *) false ;; |
| 265 | esac ) |
| 266 | then |
| 267 | export __mdw_sechost="`hostname`" |
| 268 | fi |
| 269 | |
| 270 | ## Start a passphrase pixie if there is one and it's not already running. |
| 271 | if pixie --version >/dev/null 2>&1; then |
| 272 | mkdir -p $HOME/.catacomb |
| 273 | pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie} |
| 274 | if [ -S "$pixie" ] && pixie -C help >/dev/null 2>/dev/null; then |
| 275 | : |
| 276 | else |
| 277 | pixie -d 2>>$HOME/.catacomb/pixie.log |
| 278 | __mdw_started_pixie=yes |
| 279 | fi |
| 280 | fi |
| 281 | |
| 282 | ###-------------------------------------------------------------------------- |
| 283 | ### Finishing touches. |
| 284 | |
| 285 | ## If there's a local hook then run it. |
| 286 | [ -f "$HOME/.profile-local" ] && . "$HOME/.profile-local" |
| 287 | |
| 288 | ## If we haven't run the `.bashrc' yet, and this shell is interactive, then |
| 289 | ## run it now. |
| 290 | [ -z "$__mdw_bashrc" ] && [ -t 0 ] && \ |
| 291 | [ -r $HOME/.bashrc ] && . $HOME/.bashrc |
| 292 | |
| 293 | ###----- That's all, folks -------------------------------------------------- |