setup: Source local hacks if present.
[profile] / setup
CommitLineData
65ff0e8c 1#! /bin/bash
f617db13
MW
2
3set -e
4
5umask 002
6
4aa875e9 7sub=
f617db13
MW
8mkdir -p $HOME$sub
9
60fe6715 10[ -f setup-local ] && . setup-local
0633739b 11: ${REPO=http://guvnor.distorted.org.uk/ftp/pub/mdw/profile}
f617db13
MW
12
13export PATH=/usr/local/bin:$HOME$sub/bin:/usr/bin:/usr/ccs/bin:/bin
14
15### Sort out command line
16xstuff= false=
17while [ $# -gt 0 ]; do
18 case "$1" in
19 -x) xstuff=t;;
20 -n) false=false;;
21 --) shift; break;;
22 -*) echo >&2 "$0: bad option"; exit 1;;
23 *) break;;
24 esac
25 shift
26done
27
28### Find out where I am
29here=$(pwd)
f617db13
MW
30
31### Suss out how to print things
32out=$(echo -n "foo"; echo "bar")
33if [ "$out" = "foobar" ]; then
34 echon="echo -n"
35 echoc=""
36else
37 echon="echo"
38 echoc='\c'
39fi
40
41### Create the necessary directories
42echo "Creating directories..."
43for i in bin lib/emacs src; do
44 $echon " $i:$echoc"
45 if [ -d $HOME$sub/$i ]; then
46 echo " already exists."
47 else
48 mkdir -p $HOME$sub/$i
49 echo " done."
50 fi
51done
52echo " all done."
53
54### Find out how to fetch things over the net
55$echon "Finding URL fetcher:$echoc"
56if curl >/dev/null 2>&1 --version || [ $? -eq 2 ]; then
57 GETURL="curl -fs -o"
58 echo " curl."
59elif wget >/dev/null 2>&1 --version; then
60 GETURL="wget -q -O"
61 echo " wget."
62else
63 echo " failed!"
64 echo >&2 "$0: failed to find URL fetcher"
65 exit 1
66fi
67
68### Install necessary things
69echo "Installing useful scripts..."
70
af58d83c
MW
71scripts="
72 lesspipe.sh start-ssh-agent svnwrap"
73[ "$xstuff" ] && scripts="$scripts
74 xrun"
75for script in $scripts; do
f617db13
MW
76 $echon " $script:$echoc"
77 found=
78 for p in /bin /usr/bin /usr/local/bin $(echo $PATH | tr : ' '); do
79 if $false [ -x $p/$script ]; then
80 found=t
81 break
82 fi
83 done
84 if [ "$found" ]; then
85 echo " already installed."
86 else
87 $echon " downloading$echoc"
88 $GETURL $HOME$sub/bin/$script $REPO/$script
89 chmod +x $HOME$sub/bin/$script
90 echo " done."
91 fi
92done
93
94echo " all done."
95
96### Install some more complicated programs
97echo "Installing packages..."
98systems="
99 mLib:2.0.3:mLib-config
100 chkpath:1.1.0:tmpdir
101"
102[ "$xstuff" ] && systems="$systems
103 mgLib:1.1.0:mgLib-config
104 xtoys:1.3.0:xscsize
105"
106for system in $systems; do
107 set -- $(echo $system | tr : ' ')
108 sys=$1 ver=$2 prog=$3
109 $echon " $sys:$echoc"
110 if $false $prog >/dev/null 2>&1 --version; then
111 echo " already installed."
112 else
113 ( set -e
114 $echon " downloading$echoc"
115 cd $HOME$sub/src
116 rm -rf $sys-$ver.tar.gz $sys-$ver
117 $GETURL $sys-$ver.tar.gz $REPO/$sys-$ver.tar.gz
118 $echon " unpacking$echoc"
119 gzip -cd $sys-$ver.tar.gz | tar xf -
120 $echon " configuring$echoc"
121 cd $sys-$ver
122 mkdir build
123 cd build
124 ../configure --prefix=$HOME$sub >>buildlog 2>&1
125 $echon " building$echoc"
126 make >>buildlog 2>&1
127 $echon " installing$echoc"
128 make install >>buildlog 2>&1
129 echo " done."
130 )
131 fi
132done
133echo " all done."
134
f141fe0f
MW
135### Install global configuration
136echo -n "Installing dotfile configuration:"
137if [ -f $HOME$sub/.mdw.conf ]; then
138 echo " already installed."
139else
140 cp mdw.conf $HOME$sub/.mdw.conf
141 echo " done."
142fi
143
f617db13
MW
144### Symlink the various dotfiles into place
145dotfiles="
917b7a9a 146 bash_profile bash_logout bashrc inputrc
f617db13 147 emacs emacs-calc
a124320a 148 vm mailrc signature
ccaac00b
MW
149 lisp-init.lisp:.cmucl-init.lisp
150 lisp-init.lisp:.sbclrc
151 lisp-init.lisp:.clisprc.lisp
db27ee7d 152 dircolors screenrc cvsrc"
739bccbf 153[ "$xstuff" ] && dotfiles="$dotfiles
eae29a8c 154 xinitrc xsession Xdefaults vncrc vncsession
739bccbf
MW
155 eterm-theme.cfg:.Eterm/themes/Eterm/theme.cfg
156 e-keybindings.cfg:.enlightenment/keybindings.cfg
eae29a8c 157 evnc-keybindings.cfg:.enlightenment-vnc/keybindings.cfg
739bccbf 158 jue-peek.jpg:.enlightenment/backgrounds/jue-peek.jpg"
f617db13
MW
159mkdir -p $HOME/test
160echo "Installing dotfiles..."
161for d in $dotfiles; do
739bccbf
MW
162 target=.$d
163 case $d in
164 *:*) target=${d#*:} d=${d%%:*};;
165 esac
166 ft=$HOME$sub/$target
167 dir=${ft%/*}
168 mkdir -p $dir
169 ln -s $here/$d $ft.new
170 mv $ft.new $ft
171 echo " $target"
f617db13
MW
172done
173echo " all done."
174
175### Set up the Emacs config
65ff0e8c
MW
176$echon "Finding a suitable emacs:$echoc"
177emacs=no
178for i in emacs21 emacs; do
179 if type -p >/dev/null $i; then
180 emacs=$i
181 break
182 fi
183done
184if [ $emacs = no ]; then
185 echo " failed."
186 emacs=:
187else
188 echo " $emacs."
189fi
190
f617db13 191echo "Installing Emacs packages..."
400223a1
MW
192emacspkg="
193 make-regexp
194 git vc-git
195 quilt"
196for elib in $emacspkg; do
f617db13 197 $echon " $elib:$echoc"
65ff0e8c 198 if $false $emacs >/dev/null 2>&1 --no-site-file --batch --eval '
20eb0692
MW
199 (progn
200 (setq load-path (nconc load-path (list "~/lib/emacs")))
201 (kill-emacs (condition-case nil
202 (progn (load-library "'"$elib"'") 0)
203 (error 1))))'; then
f617db13
MW
204 echo " already installed."
205 else
206 $echon " downloading$echoc"
20eb0692 207 $GETURL $HOME$sub/lib/emacs/$elib.el $REPO/$elib.el
f617db13
MW
208 $echon " compiling$echoc"
209 (cd $HOME$sub/lib/emacs;
65ff0e8c 210 $emacs >/dev/null 2>&1 --no-site-file --batch \
20eb0692 211 --eval '(byte-compile-file "'"$elib.el"'")')
f617db13
MW
212 echo " done."
213 fi
214done
215echo " all done."
216
217$echon "Setting up Emacs configuration:$echoc"
218$echon " linking$echoc"
219for link in dot-emacs.el:dot-emacs.el emacs-Makefile:Makefile; do
220 set -- $(echo $link | tr : ' ')
221 from=$1 to=$2
739bccbf
MW
222 ln -s $here/$from $HOME$sub/lib/emacs/$to.new
223 mv $HOME$sub/lib/emacs/$to.new $HOME$sub/lib/emacs/$to
f617db13
MW
224done
225$echon " compiling$echoc"
65ff0e8c 226make >/dev/null 2>&1 -C $HOME$sub/lib/emacs EMACS=$emacs
f617db13 227echo " done."