chiark / gitweb /
Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/profile
[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=http://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   bash_profile bash_logout bashrc inputrc bash_completion
135   emacs emacs-calc vm gnus.el ercrc.el
136   vimrc mg zile lesskey
137   parallel-config:.parallel/config
138   ditz-config
139   mailrc signature muttrc
140   cgrc tigrc
141   gdbinit
142   guile
143   rcrc
144   toprc
145   mc-ini:.mc/ini mc-panels.ini:.mc/panels.ini
146   pulse-daemon.conf:.pulse/daemon.conf
147   aspell.conf
148   tclshrc:.tclshrc tclshrc:.wishrc
149   lisp-init.lisp:.cmucl-init.lisp
150     lisp-init.lisp:.sbclrc
151     lisp-init.lisp:.clisprc.lisp
152     lisp-init.lisp:.eclrc
153   swank.lisp
154   mdw-build.conf:.config/mdw-build.conf
155   w3m-config:.w3m/config elinks.conf:.elinks/elinks.conf
156   dircolors colordiffrc screenrc tmux.conf cvsrc indent.pro"
157 [ "$xstuff" ] && dotfiles="$dotfiles
158   xinitrc xsession xmodmap vncrc vncsession
159   fonts.conf
160   stalonetrayrc
161   putty-defaults:.putty/sessions/Default%20Settings
162   mdw.session:.config/gnome-session/sessions/mdw.session
163   eterm-theme.cfg:.Eterm/themes/Eterm/theme.cfg
164   e-keybindings.cfg:.enlightenment/keybindings.cfg
165   evnc-keybindings.cfg:.enlightenment-vnc/keybindings.cfg
166   e16-bindings:.e16/bindings.cfg"
167 echo "Installing dotfiles..."
168 for d in $dotfiles; do
169   target=.$d
170   case $d in
171     *:*) target=${d#*:} d=${d%%:*};;
172   esac
173   ft=$HOME$sub/$target
174   dir=${ft%/*}
175   mkdir -p $dir
176   ln -s $here/dot/$d $ft.new
177   mv $ft.new $ft
178   echo "  $target"
179 done
180 echo "  all done."
181
182 ## CPP-hack files which need it.
183 cppfiles=""
184 [ "$xstuff" ] && cppfiles="$cppfiles
185   Xdefaults"
186 echo "Hacking files with C preprocessor..."
187 for c in $cppfiles; do
188   target=.$c
189   case $c in
190     *:*) target=${c#*:} c=${c%%:*};;
191   esac
192   ft=$HOME$sub/$target
193   dir=${ft%/*}
194   mkdir -p $dir
195   cpp -P dot/$c -o $ft.new
196   mv $ft.new $ft
197   echo "  $target"
198 done
199 echo "  all done."
200
201 ## Substitute things which need substituting.
202 dotfilessubst="
203   gitconfig
204   mykermrc
205   pulse-default.pa.in:.pulse/default.pa"
206 echo "Installing dotfiles with substitutions..."
207 for d in $dotfilessubst; do
208   case $d in
209     *:*) target=${d#*:} d=${d%%:*};;
210     *) target=.$d d=$d.in;;
211   esac
212   ft=$HOME$sub/$target
213   dir=${ft%/*}
214   mkdir -p $dir
215   sed "
216 1i\\
217 ### generated by $here/setup; do not edit!\\
218
219 /@home@/ s\a\a$HOME\ag
220 /@profile@/ s\a\a$here\ag
221 /@releasekey@/ s\a\a$(bin/mdw-conf releasekey 481334C2)\ag
222 " dot/$d >$ft.new
223   mv $ft.new $ft
224   echo "  $target"
225 done
226 echo "  all done."
227
228 ## Symlink backgrounds.
229 backgrounds="
230   bsg-supper.jpg
231   harley-quinn.jpg
232   hypatia.jpg
233   jue-peek.jpg
234   lilith.jpg
235   lovelace.jpg
236   medusa.jpg
237   noodly.jpg
238   rayne.jpg
239 "
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   svnwrap
274   guest-console
275   hyperspec"
276 [ "$xstuff" ] && scripts="$scripts
277   xinitcmd
278   un-backslashify-selection
279   lock-screen
280   xpra-start-xdummy
281   xshutdown"
282 echo "Installing scripts..."
283 mkdir -p $HOME$sub/bin
284 for s in $scripts; do
285   ft=$HOME$sub/bin/$s
286   ln -s $here/bin/$s $ft.new
287   mv $ft.new $ft
288   echo "  $s"
289 done
290 echo "  all done."
291
292 hacks="
293   ssh:ssh"
294 echo "Installing hacks..."
295 for h in $hacks; do
296   d=${h%%:*} h=${h#*:}
297   ft=$HOME$sub/bin/hacks/$d
298   mkdir -p $ft
299   ln -s $here/hacks/$h $ft/$h.new
300   mv $ft/$h.new $ft/$h
301   echo "  $d:$h"
302 done
303 echo "  all done."
304
305 ###--------------------------------------------------------------------------
306 ### Set up the Emacs config.
307
308 $echon "Finding a suitable emacs:$echoc"
309 emacs=no
310 for i in emacs23 emacs24 emacs22 emacs21 emacs; do
311   if type -p >/dev/null $i; then
312     emacs=$i
313     break
314   fi
315 done
316 if [ $emacs = no ]; then
317   echo " failed."
318   emacs=:
319 else
320   echo " $emacs."
321 fi
322
323 echo "Installing Emacs packages..."
324 emacspkg="
325   make-regexp
326   ew-hols
327   mdw-gnus-patch
328   git git-blame vc-git stgit
329   mdw-multiple-cursors
330   quilt"
331 for elib in $emacspkg; do
332   $echon "  $elib:$echoc"
333   if $false $emacs >/dev/null 2>&1 --no-site-file --batch --eval '
334        (progn
335          (setq load-path (nconc load-path (list "~/lib/emacs")))
336          (kill-emacs (condition-case nil
337                          (progn (load-library "'"$elib"'") 0)
338                        (error 1))))'; then
339     echo " already installed."
340   else
341     if [ -f el/$elib.el ]; then
342       cp el/$elib.el $HOME$sub/lib/emacs/$elib.el
343     else
344       $echon " downloading$echoc"
345       $GETURL $HOME$sub/lib/emacs/$elib.el $REPO/$elib.el
346     fi
347     $echon " compiling$echoc"
348     (cd $HOME$sub/lib/emacs;
349       $emacs >/dev/null 2>&1 --no-site-file --batch \
350         --eval '(byte-compile-file "'"$elib.el"'")')
351     echo " done."
352   fi
353 done
354 echo "  all done."
355
356 $echon "Setting up Emacs configuration:$echoc"
357 $echon " linking$echoc"
358 for f in dot-emacs.el Makefile; do
359   set -- $(echo $link | tr : ' ')
360   ln -s $here/el/$f $HOME$sub/lib/emacs/$f.new
361   mv $HOME$sub/lib/emacs/$f.new $HOME$sub/lib/emacs/$f
362 done
363 $echon " compiling$echoc"
364 { cd $HOME$sub/lib/emacs && make EMACS=$emacs; } >/dev/null 2>&1
365 echo " done."
366
367 ###----- That's all, folks --------------------------------------------------