chiark / gitweb /
Fix pstree output.
[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/ftp/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 necessary things.
79
80 echo "Installing useful scripts..."
81
82 scripts="
83   lesspipe.sh start-ssh-agent svnwrap"
84 for script in $scripts; do
85   $echon "  $script:$echoc"
86   found=
87   for p in /bin /usr/bin /usr/local/bin $(echo $PATH | tr : ' '); do
88     if $false [ -x $p/$script ]; then
89       found=t
90       break
91     fi
92   done
93   if [ "$found" ]; then
94     echo " already installed."
95   else
96     $echon " downloading$echoc"
97     $GETURL $HOME$sub/bin/$script $REPO/$script
98     chmod +x $HOME$sub/bin/$script
99     echo " done."
100   fi
101 done
102
103 echo "  all done."
104
105 ###--------------------------------------------------------------------------
106 ### Install some more complicated programs.
107
108 echo "Installing packages..."
109 systems="
110   mlib:2.0.4:crc-mktab
111   chkpath:1.1.0:tmpdir
112 "
113 [ "$xstuff" ] && systems="$systems
114   xtoys:1.4.0:xatom
115 "
116 for system in $systems; do
117   set -- $(echo $system | tr : ' ')
118   sys=$1 ver=$2 prog=$3
119   $echon "  $sys:$echoc"
120   if $false $prog >/dev/null 2>&1 --version; then
121     echo " already installed."
122   else
123     ( set -e
124       $echon " downloading$echoc"
125       cd $HOME$sub/src
126       rm -rf $sys-$ver.tar.gz $sys-$ver
127       $GETURL $sys-$ver.tar.gz $REPO/$sys-$ver.tar.gz
128       $echon " unpacking$echoc"
129       gzip -cd $sys-$ver.tar.gz | tar xf -
130       $echon " configuring$echoc"
131       cd $sys-$ver
132       mkdir build
133       cd build
134       ../configure --prefix=$HOME$sub >>buildlog 2>&1
135       $echon " building$echoc"
136       make >>buildlog 2>&1
137       $echon " installing$echoc"
138       make install >>buildlog 2>&1
139       echo " done."
140     )
141   fi
142 done
143 echo "  all done."
144
145 ###--------------------------------------------------------------------------
146 ### Install global configuration.
147
148 echo -n "Installing dotfile configuration:"
149 if [ -f $HOME$sub/.mdw.conf ]; then
150   echo " already installed."
151 else
152   cp mdw.conf $HOME$sub/.mdw.conf
153   echo " done."
154 fi
155
156 ## Symlink the various dotfiles into place
157 dotfiles="
158   bash_profile bash_logout bashrc inputrc bash_completion
159   emacs emacs-calc vm
160   vimrc mg
161   mailrc signature
162   cgrc tigrc
163   gdbinit
164   guile
165   lisp-init.lisp:.cmucl-init.lisp
166     lisp-init.lisp:.sbclrc
167     lisp-init.lisp:.clisprc.lisp
168     lisp-init.lisp:.eclrc
169   dircolors colordiffrc screenrc cvsrc indent.pro"
170 [ "$xstuff" ] && dotfiles="$dotfiles
171   xinitrc xsession Xdefaults vncrc vncsession
172   putty-defaults:.putty/sessions/Default%20Settings
173   eterm-theme.cfg:.Eterm/themes/Eterm/theme.cfg
174   e-keybindings.cfg:.enlightenment/keybindings.cfg
175   evnc-keybindings.cfg:.enlightenment-vnc/keybindings.cfg
176   e16-bindings:.e16/bindings.cfg
177   e16-config:.e16/e_config--1.0.cfg
178   jue-peek.jpg:.enlightenment/backgrounds/jue-peek.jpg
179   jue-peek.jpg:.e16/backgrounds/jue-peek.jpg"
180 echo "Installing dotfiles..."
181 for d in $dotfiles; do
182   target=.$d
183   case $d in
184     *:*) target=${d#*:} d=${d%%:*};;
185   esac
186   ft=$HOME$sub/$target
187   dir=${ft%/*}
188   mkdir -p $dir
189   ln -s $here/$d $ft.new
190   mv $ft.new $ft
191   echo "  $target"
192 done
193 echo "  all done."
194
195 ###--------------------------------------------------------------------------
196 ### Process the Git configuration.
197
198 echo -n "Installing Git configuration:"
199 sed "
200 1i\
201 ### generated by $here/setup; do not edit!\
202
203 /@releasekey@/ s::$(./mdw-conf release-key 481334C2):g
204 /@gitignore@/ s::$(./mdw-conf gitignore $here/gitignore):g
205 " gitconfig >$HOME/.gitconfig.new
206 mv $HOME/.gitconfig.new $HOME/.gitconfig
207 echo " done."
208
209 ###--------------------------------------------------------------------------
210 ### Install useful scripts included in this package.
211
212 scripts="
213   mdw-editor
214   mdw-conf
215   movemail-hack
216   emerge-hack"
217 [ "$xstuff" ] && scripts="$scripts
218   xrun
219   xshutdown"
220 echo "Installing scripts..."
221 mkdir -p $HOME$sub/bin
222 for s in $scripts; do
223   ft=$HOME$sub/bin/$s
224   ln -s $here/$s $ft.new
225   mv $ft.new $ft
226   echo "  $s"
227 done
228 echo "  all done."
229
230 ###--------------------------------------------------------------------------
231 ### Set up the Emacs config.
232
233 $echon "Finding a suitable emacs:$echoc"
234 emacs=no
235 for i in emacs22 emacs21 emacs; do
236   if type -p >/dev/null $i; then
237     emacs=$i
238     break
239   fi
240 done
241 if [ $emacs = no ]; then
242   echo " failed."
243   emacs=:
244 else
245   echo " $emacs."
246 fi
247
248 echo "Installing Emacs packages..."
249 emacspkg="
250   make-regexp
251   git git-blame vc-git stgit
252   quilt"
253 for elib in $emacspkg; do
254   $echon "  $elib:$echoc"
255   if $false $emacs >/dev/null 2>&1 --no-site-file --batch --eval '
256        (progn
257          (setq load-path (nconc load-path (list "~/lib/emacs")))
258          (kill-emacs (condition-case nil
259                          (progn (load-library "'"$elib"'") 0)
260                        (error 1))))'; then
261     echo " already installed."
262   else
263     $echon " downloading$echoc"
264     $GETURL $HOME$sub/lib/emacs/$elib.el $REPO/$elib.el
265     $echon " compiling$echoc"
266     (cd $HOME$sub/lib/emacs;
267       $emacs >/dev/null 2>&1 --no-site-file --batch \
268         --eval '(byte-compile-file "'"$elib.el"'")')
269     echo " done."
270   fi
271 done
272 echo "  all done."
273
274 $echon "Setting up Emacs configuration:$echoc"
275 $echon " linking$echoc"
276 for link in dot-emacs.el:dot-emacs.el emacs-Makefile:Makefile; do
277   set -- $(echo $link | tr : ' ')
278   from=$1 to=$2
279   ln -s $here/$from $HOME$sub/lib/emacs/$to.new
280   mv $HOME$sub/lib/emacs/$to.new $HOME$sub/lib/emacs/$to
281 done
282 $echon " compiling$echoc"
283 make >/dev/null 2>&1 -C $HOME$sub/lib/emacs EMACS=$emacs
284 echo " done."
285
286 ###----- That's all, folks --------------------------------------------------