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 | |
30 | "") val=$i change=t; continue ;; | |
31 | $i) continue ;; | |
32 | *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;; | |
33 | $i:*) val=${val#$i:} ;; | |
34 | *:$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) eval $var=\$val ;; esac | |
43 | } | |
44 | ||
45 | ## __mdw_programp NAME | |
46 | ## | |
47 | ## Does NAME exist as an executable program? | |
48 | __mdw_programp () { type >/dev/null 2>&1 "$1"; } | |
49 | ||
50 | ## __mdw_setconf VAR CONF [DEFAULT] | |
51 | ## | |
52 | ## If CONF is defined in `~/.mdw.conf' then set VAR to its value; otherwise, | |
53 | ## set VAR to DEFAULT, if given; otherwise, do nothing at all. | |
54 | __mdw_setconf () { | |
55 | local var=$1 conf=$2 val; shift 2 | |
56 | if val=$(mdw-conf 2>/dev/null "$conf" "$@"); then | |
57 | eval "$var=\$val; export $var" | |
58 | fi | |
59 | } | |
60 | ||
61 | ###-------------------------------------------------------------------------- | |
62 | ### Other preliminaries. | |
63 | ||
64 | ## Work out my home directory, resolving symbolic links. | |
65 | HOME=$(cd "$HOME"; pwd -P) | |
66 | case ${SCHROOT_SESSION_ID+t} in t) ;; *) cd "$HOME" ;; esac | |
67 | ||
68 | ## CDE's session structure is demented and doesn't leave us with a proper | |
69 | ## logout hook, so synthesize one here. | |
70 | case ${DT+t} in t) trap "source $HOME/.shell-logout" EXIT; esac | |
71 | ||
72 | ###-------------------------------------------------------------------------- | |
73 | ### Set some basic paths. | |
74 | ||
75 | ## The main path. | |
76 | export PATH | |
77 | __mdw_addto PATH l \ | |
78 | "$HOME"/bin \ | |
79 | /usr/local/bin /usr/local/sbin /usr/local/games \ | |
80 | /usr/bin /usr/sbin /usr/games \ | |
81 | /usr/X11R6/bin /usr/local/X11R6/bin \ | |
82 | /bin /sbin \ | |
83 | /opt/nfast/bin /opt/nfast/sbin | |
84 | ||
85 | ## If we have Plan 9 from User Space, then add that in. | |
86 | if [ -d /usr/local/plan9 ]; then | |
87 | PLAN9=/usr/local/plan9; export PLAN9 | |
88 | __mdw_addto PATH r $PLAN9/bin | |
89 | fi | |
90 | ||
91 | ###-------------------------------------------------------------------------- | |
92 | ### Some other preliminaries. | |
93 | ||
94 | ## Establish a temporary directory. | |
95 | case ${TMPDIR+t} in | |
96 | t) ;; | |
97 | *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi | |
98 | esac | |
99 | TMP=$TMPDIR; export TMP | |
100 | ||
101 | ## Sensible umask if users have their own groups. | |
102 | umask 002 | |
103 | ||
104 | ###-------------------------------------------------------------------------- | |
105 | ### Text editor configuration. | |
106 | ||
107 | MDW_EDITOR=ed | |
108 | emacs_startup_args="--no-site-file --mdw-fast-startup -nw" | |
109 | for ed in \ | |
110 | "emacs24 $emacs_startup_args" \ | |
111 | "emacs23 $emacs_startup_args" \ | |
112 | "emacs22 $emacs_startup_args" \ | |
113 | "emacs21 $emacs_startup_args" \ | |
114 | zile mg \ | |
115 | "emacs -nw" \ | |
116 | vi pico nano ae | |
117 | do | |
118 | name=${ed%% *} | |
119 | if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi | |
120 | done | |
121 | EDITOR=mdw-editor VISUAL=mdw-editor | |
122 | export EDITOR VISUAL MDW_EDITOR | |
123 | unset ed emacs_startup_args | |
124 | ||
125 | ###-------------------------------------------------------------------------- | |
126 | ### Locale configuration. | |
127 | ||
128 | case ${DISPLAY+t} in | |
129 | t) | |
130 | __mdw_setconf LANG x-ctype POSIX | |
131 | ;; | |
132 | *) | |
133 | : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}} | |
134 | case "$TERM,$(tty)" in | |
135 | linux,/dev/tty*) | |
136 | if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then | |
137 | ctype=.utf8 | |
138 | else | |
139 | ctype= | |
140 | fi | |
141 | LANG=${LANG%.*}$ctype | |
142 | ;; | |
143 | esac | |
144 | ;; | |
145 | esac | |
146 | unset LC_ALL | |
147 | export LANG | |
148 | ||
149 | LC_COLLATE=POSIX; export LC_COLLATE | |
150 | ||
151 | ###-------------------------------------------------------------------------- | |
152 | ### Pagers. | |
153 | ||
154 | ## Choose a sensible pager. | |
155 | MDW_PAGER=more | |
156 | for pg in less more; do | |
157 | if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi | |
158 | done | |
159 | PAGER=mdw-pager METAMAIL_PAGER=mdw-pager | |
160 | export MDW_PAGER PAGER METAMAIL_PAGER | |
161 | unset pg | |
162 | ||
163 | ## Configure `less'. | |
164 | LESS="-iqgRh1j.3FSX"; export LESS | |
165 | LESSOPEN="|lesspipe.sh %s"; export LESSOPEN | |
166 | case ${LC_CTYPE-$LANG} in | |
167 | *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;; | |
168 | *) LESSCHARSET=latin1 ;; | |
169 | esac | |
170 | export LESSCHARSET | |
171 | if __mdw_programp global; then | |
172 | LESSGLOBALTAGS=global | |
173 | export LESSGLOBALTAGS | |
174 | fi | |
175 | ||
176 | ###-------------------------------------------------------------------------- | |
177 | ### Miscellaneous things. | |
178 | ||
179 | ## Mail and general identification. | |
180 | __mdw_setconf MAIL mailbox /var/mail/mdw | |
181 | __mdw_setconf EMAIL email mdw@distorted.org.uk | |
182 | NAME="Mark Wooding"; export NAME | |
183 | ||
184 | ## News server. | |
185 | __mdw_setconf NNTPSERVER nntp-server | |
186 | ||
187 | ## Some programs want to know the hostname. | |
188 | case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac | |
189 | ||
190 | ## HTTP and FTP proxies. | |
191 | http=$(mdw-conf http-proxy none) | |
192 | case "${http_proxy-none},$http" in | |
193 | *,none) ;; | |
194 | none,*) http_proxy=http://$http/; export http_proxy ;; | |
195 | esac | |
196 | ftp=$(mdw-conf ftp-proxy none) | |
197 | case "${ftp_proxy-none},$ftp,${http_proxy-none}" in | |
198 | *,none,none) ;; | |
199 | none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;; | |
200 | none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;; | |
201 | esac | |
202 | unset http ftp | |
203 | ||
204 | ## Ncurses programs should use the Unicode box-drawing characters because the | |
205 | ## alternative character set stuff isn't supported well. | |
206 | NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS | |
207 | ||
208 | ## Shut up Perl's readline machinery. | |
209 | PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN | |
210 | ||
211 | ## If we have `distcc' then tell `ccache' to use it. | |
212 | if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi | |
213 | ||
214 | ## Choose a sensible web browser. If we have a display, try to pick a | |
215 | ## graphical one. | |
216 | set -- elinks w3m lynx | |
217 | case ${DISPLAY+t} in | |
218 | t) set -- mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;; | |
219 | esac | |
220 | for b in "$@"; do | |
221 | if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi | |
222 | done | |
223 | unset b | |
224 | ||
225 | ## Acquiring root privileges. This is mainly the job of `bashrc', but we | |
226 | ## cache the mechanism here. | |
227 | __mdw_setconf __MDW_ROOTLY rootly | |
228 | BECOME="--preserve-environment"; export BECOME | |
229 | ||
230 | ## It's useful to see the little sigils in `ls'. | |
231 | case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac | |
232 | ||
233 | ## Settings for BBC BASIC listing. | |
234 | export BASCAT="-l +n" | |
235 | ||
236 | ## Version control hacking. | |
237 | CVS_RSH=ssh; export CVS_RSH | |
238 | __mdw_setconf CVSROOT cvs-root | |
239 | __mdw_setconf SVNROOT svn-root | |
240 | P4CONFIG=.p4; export P4CONFIG | |
241 | ||
242 | ## Help X programs find their resources. | |
243 | XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S" | |
244 | export XUSERFILESEARCHPATH | |
245 | ||
246 | ## Make OpenOffice.org do its thing properly. | |
247 | OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP | |
248 | ||
249 | ## Hack Qt-ish things to be unstoatly. | |
250 | QT_STYLE_OVERRIDE=gtk2; export QT_STYLE_OVERRIDE | |
251 | ||
252 | ## Configure `ps'. | |
253 | PS_PERSONALITY=gnu; export PS_PERSONALITY | |
254 | ||
255 | ## Disable core dumps. | |
256 | ulimit -S -c 0 | |
257 | ||
258 | ###-------------------------------------------------------------------------- | |
259 | ### Authentication and SSH hacking. | |
260 | ||
261 | ## Start an authentication agent. This is unnecessarily fiddly. If there's | |
262 | ## a Gnome keyring server then we should use that; unfortunately, it may not | |
263 | ## yet have had a chance to populate the environment with its settings, so we | |
264 | ## go off and fetch them. | |
265 | if { { [ "$GNOME_KEYRING_CONTROL" ] && | |
266 | [ -s "$GNOME_KEYRING_CONTROL" ]; } || | |
267 | { [ "$DBUS_SESSION_BUS_ADDRESS" ] && | |
268 | __mdw_programp gnome-keyring-daemon; }; } && | |
269 | stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null) | |
270 | then | |
271 | eval "$stuff" | |
272 | export SSH_AUTH_SOCK GPG_AGENT_INFO | |
273 | fi | |
274 | ||
275 | ## If we still don't have an agent then start one with a stable name. | |
276 | eval $(start-ssh-agent -b) | |
277 | ||
278 | ## Decide whether this session should be considered `secure'. A session is | |
279 | ## secure if it's on a secure TTY, but there are lots of ways of finding out | |
280 | ## which TTYs are secure. | |
281 | if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] || | |
282 | ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}" | |
283 | { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } || | |
284 | { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } && | |
285 | egrep "$devtty" $sectty >/dev/null; } || | |
286 | { [ -e /etc/default/login ] && | |
287 | egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } || | |
288 | case "${tty#/dev/}" in | |
289 | console|systty|tty[0-9]) true ;; | |
290 | *) false ;; | |
291 | esac ) | |
292 | then | |
293 | __mdw_sechost=$HOST; export __mdw_sechost | |
294 | fi | |
295 | ||
296 | ## Start a passphrase pixie if there is one and it's not already running. | |
297 | if pixie --version >/dev/null 2>&1; then | |
298 | mkdir -p "$HOME/.catacomb" | |
299 | pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie} | |
300 | if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then | |
301 | : | |
302 | else | |
303 | pixie -d 2>>"$HOME/.catacomb/pixie.log" | |
304 | __mdw_started_pixie=yes | |
305 | fi | |
306 | fi | |
307 | ||
308 | ###-------------------------------------------------------------------------- | |
309 | ### Finishing touches. | |
310 | ||
311 | ## For old-fashioned Bourne-ish shells, set up per-shell definitions. | |
312 | ENV=$HOME/.shrc; export ENV | |
313 | ||
314 | ## If there's a local hook then run it. | |
315 | if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi | |
316 | ||
317 | ###----- That's all, folks -------------------------------------------------- |