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