Commit | Line | Data |
---|---|---|
74a53e28 MW |
1 | ### -*-sh-*- |
2 | ### | |
3 | ### Session startup things. | |
4 | ||
5 | ## The shell-specific hook will run us if it thinks we haven't been run | |
6 | ## before. We should therefore let it know. | |
7 | __mdw_profile=t; export __mdw_profile | |
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 | if ! [ -d $i ]; then continue; fi | |
29 | case "$val" in | |
74a53e28 MW |
30 | $i) continue ;; |
31 | *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;; | |
32 | $i:*) val=${val#$i:} ;; | |
33 | *:$i) val=${val%:$i} ;; | |
34 | esac | |
35 | new=$new:$i change=t | |
36 | done | |
37 | case $dir in | |
4c085f9e MW |
38 | l) val=${new#:}${val:+:$val} ;; |
39 | r) val=${val:+$val:}${new#:} ;; | |
74a53e28 MW |
40 | esac |
41 | case $change in t) eval $var=\$val ;; esac | |
42 | } | |
43 | ||
44 | ## __mdw_programp NAME | |
45 | ## | |
46 | ## Does NAME exist as an executable program? | |
47 | __mdw_programp () { type >/dev/null 2>&1 "$1"; } | |
48 | ||
49 | ## __mdw_setconf VAR CONF [DEFAULT] | |
50 | ## | |
51 | ## If CONF is defined in `~/.mdw.conf' then set VAR to its value; otherwise, | |
52 | ## set VAR to DEFAULT, if given; otherwise, do nothing at all. | |
53 | __mdw_setconf () { | |
54 | local var=$1 conf=$2 val; shift 2 | |
55 | if val=$(mdw-conf 2>/dev/null "$conf" "$@"); then | |
56 | eval "$var=\$val; export $var" | |
57 | fi | |
58 | } | |
59 | ||
dbf14608 MW |
60 | ## __mdw_export_if_defined VAR ... |
61 | ## | |
62 | ## If VARs are defined, then export them. | |
63 | __mdw_export_if_defined () { | |
64 | local var t | |
65 | for var in "$@"; do | |
66 | eval t=\${$var+t} | |
67 | case $t in t) export $var ;; esac | |
68 | done | |
69 | } | |
70 | ||
74a53e28 MW |
71 | ###-------------------------------------------------------------------------- |
72 | ### Other preliminaries. | |
73 | ||
74 | ## Work out my home directory, resolving symbolic links. | |
75 | HOME=$(cd "$HOME"; pwd -P) | |
76 | case ${SCHROOT_SESSION_ID+t} in t) ;; *) cd "$HOME" ;; esac | |
77 | ||
78 | ## CDE's session structure is demented and doesn't leave us with a proper | |
79 | ## logout hook, so synthesize one here. | |
80 | case ${DT+t} in t) trap "source $HOME/.shell-logout" EXIT; esac | |
81 | ||
82 | ###-------------------------------------------------------------------------- | |
83 | ### Set some basic paths. | |
84 | ||
85 | ## The main path. | |
86 | export PATH | |
87 | __mdw_addto PATH l \ | |
88 | "$HOME"/bin \ | |
89 | /usr/local/bin /usr/local/sbin /usr/local/games \ | |
90 | /usr/bin /usr/sbin /usr/games \ | |
91 | /usr/X11R6/bin /usr/local/X11R6/bin \ | |
92 | /bin /sbin \ | |
93 | /opt/nfast/bin /opt/nfast/sbin | |
94 | ||
95 | ## If we have Plan 9 from User Space, then add that in. | |
8fd6f7da MW |
96 | for i in /opt/plan9 /usr/local/plan9; do |
97 | if [ -d $i ]; then | |
98 | PLAN9=$i; export PLAN9 | |
99 | __mdw_addto PATH r $i/bin | |
100 | break | |
101 | fi | |
102 | done | |
74a53e28 | 103 | |
b97b3f8e MW |
104 | ## Check for some standard path hacks. |
105 | for i in ccache; do | |
106 | __mdw_addto PATH l "$HOME"/bin/hacks/$i | |
107 | done | |
108 | ||
74a53e28 MW |
109 | ###-------------------------------------------------------------------------- |
110 | ### Some other preliminaries. | |
111 | ||
3f180a8a MW |
112 | ## Set a per-process memory limit. It's much less common for a process to |
113 | ## need a lot of memory for a legitimate reason than for it to be a memory | |
114 | ## leak or some other bug that's going to cause swap death for no good | |
115 | ## reason. | |
1951337c | 116 | ulimit -Sv $(mdw-conf memory-limit 4194303) |
3f180a8a | 117 | |
74a53e28 MW |
118 | ## Establish a temporary directory. |
119 | case ${TMPDIR+t} in | |
120 | t) ;; | |
121 | *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi | |
122 | esac | |
123 | TMP=$TMPDIR; export TMP | |
124 | ||
125 | ## Sensible umask if users have their own groups. | |
126 | umask 002 | |
127 | ||
128 | ###-------------------------------------------------------------------------- | |
129 | ### Text editor configuration. | |
130 | ||
131 | MDW_EDITOR=ed | |
132 | emacs_startup_args="--no-site-file --mdw-fast-startup -nw" | |
133 | for ed in \ | |
134 | "emacs24 $emacs_startup_args" \ | |
135 | "emacs23 $emacs_startup_args" \ | |
136 | "emacs22 $emacs_startup_args" \ | |
137 | "emacs21 $emacs_startup_args" \ | |
138 | zile mg \ | |
139 | "emacs -nw" \ | |
140 | vi pico nano ae | |
141 | do | |
142 | name=${ed%% *} | |
143 | if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi | |
144 | done | |
145 | EDITOR=mdw-editor VISUAL=mdw-editor | |
146 | export EDITOR VISUAL MDW_EDITOR | |
147 | unset ed emacs_startup_args | |
148 | ||
149 | ###-------------------------------------------------------------------------- | |
150 | ### Locale configuration. | |
151 | ||
2c44f386 MW |
152 | case ${LC_MDWSSHLANG+t},${DISPLAY+t} in |
153 | t,*) | |
154 | LANG=$LC_MDWSSHLANG | |
155 | ;; | |
156 | ,t) | |
74a53e28 MW |
157 | __mdw_setconf LANG x-ctype POSIX |
158 | ;; | |
159 | *) | |
160 | : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}} | |
161 | case "$TERM,$(tty)" in | |
162 | linux,/dev/tty*) | |
163 | if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then | |
2f27026a | 164 | ctype=.UTF-8 |
74a53e28 MW |
165 | else |
166 | ctype= | |
167 | fi | |
168 | LANG=${LANG%.*}$ctype | |
169 | ;; | |
170 | esac | |
171 | ;; | |
172 | esac | |
173 | unset LC_ALL | |
174 | export LANG | |
175 | ||
176 | LC_COLLATE=POSIX; export LC_COLLATE | |
177 | ||
2c44f386 MW |
178 | case ${LANG+t} in |
179 | t) LC_MDWSSHLANG=$LANG; export LC_MDWSSHLANG ;; | |
180 | esac | |
181 | ||
74a53e28 MW |
182 | ###-------------------------------------------------------------------------- |
183 | ### Pagers. | |
184 | ||
185 | ## Choose a sensible pager. | |
186 | MDW_PAGER=more | |
187 | for pg in less more; do | |
188 | if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi | |
189 | done | |
190 | PAGER=mdw-pager METAMAIL_PAGER=mdw-pager | |
191 | export MDW_PAGER PAGER METAMAIL_PAGER | |
192 | unset pg | |
193 | ||
194 | ## Configure `less'. | |
74a53e28 MW |
195 | case ${LC_CTYPE-$LANG} in |
196 | *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;; | |
197 | *) LESSCHARSET=latin1 ;; | |
198 | esac | |
199 | export LESSCHARSET | |
200 | if __mdw_programp global; then | |
201 | LESSGLOBALTAGS=global | |
202 | export LESSGLOBALTAGS | |
203 | fi | |
204 | ||
f3b4cd96 MW |
205 | ## Get Debian `groff' to produce control sequences rather than overstriking. |
206 | GROFF_SGR=t; export GROFF_SGR | |
207 | ||
74a53e28 MW |
208 | ###-------------------------------------------------------------------------- |
209 | ### Miscellaneous things. | |
210 | ||
211 | ## Mail and general identification. | |
212 | __mdw_setconf MAIL mailbox /var/mail/mdw | |
213 | __mdw_setconf EMAIL email mdw@distorted.org.uk | |
214 | NAME="Mark Wooding"; export NAME | |
215 | ||
216 | ## News server. | |
217 | __mdw_setconf NNTPSERVER nntp-server | |
218 | ||
219 | ## Some programs want to know the hostname. | |
220 | case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac | |
221 | ||
222 | ## HTTP and FTP proxies. | |
223 | http=$(mdw-conf http-proxy none) | |
224 | case "${http_proxy-none},$http" in | |
225 | *,none) ;; | |
226 | none,*) http_proxy=http://$http/; export http_proxy ;; | |
227 | esac | |
442bc88b MW |
228 | https=$(mdw-conf https-proxy none) |
229 | case "${https_proxy-none},$https,${http_proxy-none}" in | |
230 | *,none,none) ;; | |
231 | none,none,*) https_proxy=$http_proxy; export https_proxy ;; | |
232 | none,*,*) https_proxy=http://$https/; export ftp_proxy ;; | |
233 | esac | |
74a53e28 MW |
234 | ftp=$(mdw-conf ftp-proxy none) |
235 | case "${ftp_proxy-none},$ftp,${http_proxy-none}" in | |
236 | *,none,none) ;; | |
237 | none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;; | |
238 | none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;; | |
239 | esac | |
442bc88b | 240 | unset http https ftp |
74a53e28 MW |
241 | |
242 | ## Ncurses programs should use the Unicode box-drawing characters because the | |
243 | ## alternative character set stuff isn't supported well. | |
244 | NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS | |
245 | ||
246 | ## Shut up Perl's readline machinery. | |
247 | PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN | |
248 | ||
249 | ## If we have `distcc' then tell `ccache' to use it. | |
250 | if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi | |
251 | ||
252 | ## Choose a sensible web browser. If we have a display, try to pick a | |
253 | ## graphical one. | |
254 | set -- elinks w3m lynx | |
255 | case ${DISPLAY+t} in | |
94526c3f | 256 | t) set -- mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;; |
74a53e28 MW |
257 | esac |
258 | for b in "$@"; do | |
259 | if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi | |
260 | done | |
261 | unset b | |
262 | ||
263 | ## Acquiring root privileges. This is mainly the job of `bashrc', but we | |
264 | ## cache the mechanism here. | |
265 | __mdw_setconf __MDW_ROOTLY rootly | |
266 | BECOME="--preserve-environment"; export BECOME | |
267 | ||
268 | ## It's useful to see the little sigils in `ls'. | |
269 | case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac | |
270 | ||
271 | ## Settings for BBC BASIC listing. | |
272 | export BASCAT="-l +n" | |
273 | ||
274 | ## Version control hacking. | |
275 | CVS_RSH=ssh; export CVS_RSH | |
276 | __mdw_setconf CVSROOT cvs-root | |
277 | __mdw_setconf SVNROOT svn-root | |
278 | P4CONFIG=.p4; export P4CONFIG | |
279 | ||
280 | ## Help X programs find their resources. | |
281 | XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S" | |
282 | export XUSERFILESEARCHPATH | |
283 | ||
284 | ## Make OpenOffice.org do its thing properly. | |
285 | OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP | |
286 | ||
287 | ## Hack Qt-ish things to be unstoatly. | |
f1e393ff | 288 | QT_QPA_PLATFORMTHEME=gtk2; export QT_QPA_PLATFORMTHEME |
e3a7c1c2 | 289 | QT_AUTO_SCREEN_SCALE_FACTOR=0; export QT_AUTO_SCREEN_SCALE_FACTOR |
74a53e28 | 290 | |
eb174df8 MW |
291 | ## Use X11 input method (including compose key sequences) everywhere. |
292 | GTK_IM_MODULE=xim; export GTK_IM_MODULE | |
293 | QT_IM_MODULE=xim; export QT_IM_MODULE | |
294 | ||
8308648a MW |
295 | ## Don't hide scrollbars. |
296 | GTK_OVERLAY_SCROLLING=0; export GTK_OVERLAY_SCROLLING | |
297 | ||
ab94ba6e MW |
298 | ## Rust Cargo things. |
299 | CARGO_HOME=$HOME/.cache/cargo; export CARGO_HOME | |
300 | ||
74a53e28 MW |
301 | ## Configure `ps'. |
302 | PS_PERSONALITY=gnu; export PS_PERSONALITY | |
303 | ||
f9ef6491 | 304 | ## Configure Debian building. |
b0b75b94 | 305 | DEB_BUILD_OPTIONS="parallel=$(mdw-conf make-parallel 4)" |
f9ef6491 MW |
306 | export DEB_BUILD_OPTIONS |
307 | ||
18045f11 MW |
308 | ## Turn off angry fruit salad error messages from things. |
309 | DPKG_COLORS=never; export DPKG_COLORS | |
310 | GCC_COLORS=; export GCC_COLORS | |
311 | CCC_OVERRIDE_OPTIONS="#^-fno-color-diagnostics"; export CCC_OVERRIDE_OPTIONS | |
312 | ||
85bd3826 MW |
313 | ## Local library directories. |
314 | __mdw_addto PERLLIB l $HOME/lib/perl; __mdw_export_if_defined PERLLIB | |
315 | __mdw_addto PYTHONPATH l $HOME/lib/python; __mdw_export_if_defined PYTHONPATH | |
316 | ||
74a53e28 MW |
317 | ## Disable core dumps. |
318 | ulimit -S -c 0 | |
319 | ||
320 | ###-------------------------------------------------------------------------- | |
321 | ### Authentication and SSH hacking. | |
322 | ||
323 | ## Start an authentication agent. This is unnecessarily fiddly. If there's | |
324 | ## a Gnome keyring server then we should use that; unfortunately, it may not | |
325 | ## yet have had a chance to populate the environment with its settings, so we | |
326 | ## go off and fetch them. | |
327 | if { { [ "$GNOME_KEYRING_CONTROL" ] && | |
328 | [ -s "$GNOME_KEYRING_CONTROL" ]; } || | |
329 | { [ "$DBUS_SESSION_BUS_ADDRESS" ] && | |
330 | __mdw_programp gnome-keyring-daemon; }; } && | |
331 | stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null) | |
332 | then | |
333 | eval "$stuff" | |
334 | export SSH_AUTH_SOCK GPG_AGENT_INFO | |
335 | fi | |
336 | ||
337 | ## If we still don't have an agent then start one with a stable name. | |
338 | eval $(start-ssh-agent -b) | |
339 | ||
340 | ## Decide whether this session should be considered `secure'. A session is | |
341 | ## secure if it's on a secure TTY, but there are lots of ways of finding out | |
342 | ## which TTYs are secure. | |
343 | if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] || | |
344 | ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}" | |
345 | { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } || | |
346 | { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } && | |
347 | egrep "$devtty" $sectty >/dev/null; } || | |
348 | { [ -e /etc/default/login ] && | |
349 | egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } || | |
350 | case "${tty#/dev/}" in | |
351 | console|systty|tty[0-9]) true ;; | |
352 | *) false ;; | |
353 | esac ) | |
354 | then | |
355 | __mdw_sechost=$HOST; export __mdw_sechost | |
356 | fi | |
357 | ||
358 | ## Start a passphrase pixie if there is one and it's not already running. | |
359 | if pixie --version >/dev/null 2>&1; then | |
360 | mkdir -p "$HOME/.catacomb" | |
361 | pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie} | |
362 | if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then | |
363 | : | |
364 | else | |
365 | pixie -d 2>>"$HOME/.catacomb/pixie.log" | |
366 | __mdw_started_pixie=yes | |
367 | fi | |
368 | fi | |
369 | ||
370 | ###-------------------------------------------------------------------------- | |
371 | ### Finishing touches. | |
372 | ||
373 | ## For old-fashioned Bourne-ish shells, set up per-shell definitions. | |
374 | ENV=$HOME/.shrc; export ENV | |
375 | ||
376 | ## If there's a local hook then run it. | |
377 | if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi | |
378 | ||
379 | ###----- That's all, folks -------------------------------------------------- |