chiark / gitweb /
dot/*: Major shake-up of shell configuration.
[profile] / setup
1 #! /bin/bash
2
3 set -e
4
5 ###--------------------------------------------------------------------------
6 ### Basic setup.
7
8 umask 002
9
10 sub=
11 mkdir -p $HOME$sub
12
13 : ${REPO=https://ftp.distorted.org.uk/pub/mdw/profile}
14
15 export PATH=/usr/local/bin:$HOME$sub/bin:/usr/bin:/usr/ccs/bin:/bin
16
17 ###--------------------------------------------------------------------------
18 ### Sort out command line.
19
20 xstuff= false=
21 while [ $# -gt 0 ]; do
22   case "$1" in
23     -x) xstuff=t;;
24     -n) false=false;;
25     --) shift; break;;
26     -*) echo >&2 "$0: bad option"; exit 1;;
27     *) break;;
28   esac
29   shift
30 done
31
32 ###--------------------------------------------------------------------------
33 ### Environment autoconfiguration.
34
35 ## Find out where I am
36 here=$(pwd)
37
38 ## Suss out how to print things
39 out=$(echo -n "foo"; echo "bar")
40 if [ "$out" = "foobar" ]; then
41   echon="echo -n"
42   echoc=""
43 else
44   echon="echo"
45   echoc='\c'
46 fi
47
48 ## Find out how to fetch things over the net
49 $echon "Finding URL fetcher:$echoc"
50 if curl >/dev/null 2>&1 --version || [ $? -eq 2 ]; then
51   GETURL="curl -fs -o"
52   echo " curl."
53 elif wget >/dev/null 2>&1 --version; then
54   GETURL="wget -q -O"
55   echo " wget."
56 else
57   echo " failed!"
58   echo >&2 "$0: failed to find URL fetcher"
59   exit 1
60 fi
61
62 ###--------------------------------------------------------------------------
63 ### Create the necessary directories.
64
65 echo "Creating directories..."
66 for i in bin lib/emacs src; do
67   $echon "  $i:$echoc"
68   if [ -d $HOME$sub/$i ]; then
69     echo " already exists."
70   else
71     mkdir -p $HOME$sub/$i
72     echo " done."
73   fi
74 done
75 echo "  all done."
76
77 ###--------------------------------------------------------------------------
78 ### Install some more complicated programs.
79
80 echo "Installing packages..."
81 systems="
82   mlib:crc-mktab
83   checkpath:tmpdir
84 "
85 [ "$xstuff" ] && systems="$systems
86   xtoys:xatom
87 "
88 for system in $systems; do
89   set -- $(echo $system | tr : ' ')
90   sys=$1 prog=$2
91   $echon "  $sys:$echoc"
92   if $false $prog >/dev/null 2>&1 --version; then
93     echo " already installed."
94   else
95     ( set -e
96       $echon " downloading$echoc"
97       cd $HOME$sub/src
98       rm -rf $sys.tar.gz $sys-$ver
99       $GETURL $sys.tar.gz $REPO/$sys.tar.gz
100       $echon " unpacking$echoc"
101       dir=$(gzip -cd $sys.tar.gz | tar tf - | head -1)
102       gzip -cd $sys.tar.gz | tar xf -
103       $echon " configuring$echoc"
104       cd $dir
105       mkdir build
106       cd build
107       ../configure \
108         --prefix=$HOME$sub \
109         PKG_CONFIG_PATH=$HOME$sub/lib/pkgconfig \
110         >>buildlog 2>&1
111       $echon " building$echoc"
112       make >>buildlog 2>&1
113       $echon " installing$echoc"
114       make install >>buildlog 2>&1
115       echo " done."
116     )
117   fi
118 done
119 echo "  all done."
120
121 ###--------------------------------------------------------------------------
122 ### Install global configuration.
123
124 echo -n "Installing dotfile configuration:"
125 if [ -f $HOME$sub/.mdw.conf ]; then
126   echo " already installed."
127 else
128   cp mdw.conf $HOME$sub/.mdw.conf
129   echo " done."
130 fi
131
132 ## Symlink the various dotfiles into place
133 dotfiles="
134   profile shell-rc shell-logout
135   bash-profile:.bash_profile
136   bash-completion:.bash_completion bashrc inputrc
137   shrc
138   emacs emacs-calc vm gnus.el ercrc.el
139   vimrc mg zile lesskey sqliterc
140   parallel-config:.parallel/config
141   ipython-config.py:.ipython/profile_default/ipython_config.py
142   ipython-key-bindings.py:.ipython/profile_default/startup/50-key-bindings.py
143   ditz-config
144   mailrc signature muttrc
145   cgrc tigrc
146   gdbinit
147   guile
148   rcrc
149   toprc
150   mc-ini:.mc/ini mc-panels.ini:.mc/panels.ini
151   pulse-daemon.conf:.pulse/daemon.conf
152   aspell.conf
153   tclshrc:.tclshrc tclshrc:.wishrc
154   lisp-init.lisp:.cmucl-init.lisp
155     lisp-init.lisp:.sbclrc
156     lisp-init.lisp:.clisprc.lisp
157     lisp-init.lisp:.eclrc
158   swank.lisp
159   mdw-build.conf:.config/mdw-build.conf
160   w3m-config:.w3m/config elinks.conf:.elinks/elinks.conf
161   dircolors colordiffrc screenrc tmux.conf cvsrc indent.pro"
162 [ "$xstuff" ] && dotfiles="$dotfiles
163   xinitrc xsession xmodmap vncrc vncsession
164   fonts.conf
165   stalonetrayrc
166   putty-defaults:.putty/sessions/Default%20Settings
167   mdw.session:.config/gnome-session/sessions/mdw.session
168   eterm-theme.cfg:.Eterm/themes/Eterm/theme.cfg
169   e-keybindings.cfg:.enlightenment/keybindings.cfg
170   evnc-keybindings.cfg:.enlightenment-vnc/keybindings.cfg
171   e16-bindings:.e16/bindings.cfg
172   gtkrc-2.0
173   gtk3.css:.config/gtk-3.0/gtk.css
174   gtk3-settings.ini:.config/gtk-3.0/settings.ini"
175 echo "Installing dotfiles..."
176 for d in $dotfiles; do
177   target=.$d
178   case $d in
179     *:*) target=${d#*:} d=${d%%:*};;
180   esac
181   ft=$HOME$sub/$target
182   dir=${ft%/*}
183   mkdir -p $dir
184   ln -s $here/dot/$d $ft.new
185   mv $ft.new $ft
186   echo "  $target"
187 done
188 echo "  all done."
189
190 ## CPP-hack files which need it.
191 cppfiles=""
192 [ "$xstuff" ] && cppfiles="$cppfiles
193   Xdefaults"
194 echo "Hacking files with C preprocessor..."
195 defs="-DHOME=$HOME -DPROFILE=$here"
196 defs="$defs -DEMACSWD=$(bin/mdw-conf emacs-width 77)"
197 for c in $cppfiles; do
198   target=.$c
199   case $c in
200     *:*) target=${c#*:} c=${c%%:*};;
201   esac
202   ft=$HOME$sub/$target
203   dir=${ft%/*}
204   mkdir -p $dir
205   cpp -P $defs dot/$c -o $ft.new
206   mv $ft.new $ft
207   echo "  $target"
208 done
209 echo "  all done."
210
211 ## Substitute things which need substituting.
212 dotfilessubst="
213   gitconfig
214   mykermrc
215   pulse-default.pa.in:.pulse/default.pa"
216 echo "Installing dotfiles with substitutions..."
217 for d in $dotfilessubst; do
218   case $d in
219     *:*) target=${d#*:} d=${d%%:*};;
220     *) target=.$d d=$d.in;;
221   esac
222   ft=$HOME$sub/$target
223   dir=${ft%/*}
224   mkdir -p $dir
225   sed "
226 1i\\
227 ### generated by $here/setup; do not edit!\\
228
229 /@home@/ s\a\a$HOME\ag
230 /@profile@/ s\a\a$here\ag
231 /@releasekey@/ s\a\a$(bin/mdw-conf releasekey 481334C2)\ag
232 " dot/$d >$ft.new
233   mv $ft.new $ft
234   echo "  $target"
235 done
236 echo "  all done."
237
238 ## Symlink backgrounds.
239 backgrounds=$(cd bg && echo *)
240 if [ "$xstuff" ]; then
241   echo "Installing backgrounds..."
242   for b in $backgrounds; do
243     for e in enlightenment e16; do
244       dir=$HOME$sub/.$e/backgrounds
245       t=$dir/$b
246       mkdir -p $dir
247       ln -s $here/bg/$b $t.new
248       mv $t.new $t
249     done
250     echo "  $b"
251   done
252   echo "        all done."
253 fi
254
255 ###--------------------------------------------------------------------------
256 ### Install useful scripts included in this package.
257
258 scripts="
259   mdw-editor
260   mdw-pager
261   mdw-conf
262   mdw-build mdw-sbuild mdw-sbuild-server
263   update-buildable-branch
264   emacsclient-hack
265   movemail-hack
266   sendmail-hack
267   aspell-hack
268   emerge-hack
269   lesspipe.sh
270   run-with-shell-env
271   start-ssh-agent
272   start-ssh-pageant
273   add-ssh-keys
274   svnwrap
275   guest-console
276   hyperspec"
277 [ "$xstuff" ] && scripts="$scripts
278   xinitcmd
279   un-backslashify-selection
280   lock-screen
281   xpra-start-xdummy
282   xshutdown"
283 echo "Installing scripts..."
284 mkdir -p $HOME$sub/bin
285 for s in $scripts; do
286   ft=$HOME$sub/bin/$s
287   ln -s $here/bin/$s $ft.new
288   mv $ft.new $ft
289   echo "  $s"
290 done
291 echo "  all done."
292
293 hacks="
294   ssh:ssh"
295 echo "Installing hacks..."
296 for h in $hacks; do
297   d=${h%%:*} h=${h#*:}
298   ft=$HOME$sub/bin/hacks/$d
299   mkdir -p $ft
300   ln -s $here/hacks/$h $ft/$h.new
301   mv $ft/$h.new $ft/$h
302   echo "  $d:$h"
303 done
304 echo "  all done."
305
306 ###--------------------------------------------------------------------------
307 ### Set up the Emacs config.
308
309 $echon "Finding a suitable emacs:$echoc"
310 emacs=no
311 for i in emacs24 emacs23 emacs22 emacs21 emacs; do
312   if type -p >/dev/null $i; then
313     emacs=$i
314     break
315   fi
316 done
317 if [ $emacs = no ]; then
318   echo " failed."
319   emacs=:
320 else
321   echo " $emacs."
322 fi
323
324 echo "Installing Emacs packages..."
325 emacspkg="
326   make-regexp
327   ew-hols
328   mdw-gnus-patch
329   git git-blame vc-git stgit
330   mdw-multiple-cursors
331   quilt"
332 for elib in $emacspkg; do
333   $echon "  $elib:$echoc"
334   if $false $emacs >/dev/null 2>&1 --no-site-file --batch --eval '
335        (progn
336          (setq load-path (nconc load-path (list "~/lib/emacs")))
337          (kill-emacs (condition-case nil
338                          (progn (load-library "'"$elib"'") 0)
339                        (error 1))))'; then
340     echo " already installed."
341   else
342     if [ -f el/$elib.el ]; then
343       cp el/$elib.el $HOME$sub/lib/emacs/$elib.el
344     else
345       $echon " downloading$echoc"
346       $GETURL $HOME$sub/lib/emacs/$elib.el $REPO/$elib.el
347     fi
348     $echon " compiling$echoc"
349     (cd $HOME$sub/lib/emacs;
350       $emacs >/dev/null 2>&1 --no-site-file --batch \
351         --eval '(byte-compile-file "'"$elib.el"'")')
352     echo " done."
353   fi
354 done
355 echo "  all done."
356
357 $echon "Setting up Emacs configuration:$echoc"
358 $echon " linking$echoc"
359 for f in dot-emacs.el Makefile; do
360   set -- $(echo $link | tr : ' ')
361   ln -s $here/el/$f $HOME$sub/lib/emacs/$f.new
362   mv $HOME$sub/lib/emacs/$f.new $HOME$sub/lib/emacs/$f
363 done
364 $echon " compiling$echoc"
365 { cd $HOME$sub/lib/emacs && make EMACS=$emacs; } >/dev/null 2>&1
366 echo " done."
367
368 ###----- That's all, folks --------------------------------------------------