chiark / gitweb /
Initial import of my profile.
[profile] / setup
1 #! /bin/sh
2
3 set -e
4
5 umask 002
6
7 sub= up=;
8 mkdir -p $HOME$sub
9
10 : ${REPO=http://guvnor.distorted.org.uk/ftp/pub/mdw}
11
12 export PATH=/usr/local/bin:$HOME$sub/bin:/usr/bin:/usr/ccs/bin:/bin
13
14 ### Sort out command line
15 xstuff= false=
16 while [ $# -gt 0 ]; do
17   case "$1" in
18     -x) xstuff=t;;
19     -n) false=false;;
20     --) shift; break;;
21     -*) echo >&2 "$0: bad option"; exit 1;;
22     *) break;;
23   esac
24   shift
25 done
26
27 ### Find out where I am
28 here=$(pwd)
29 case "$here" in
30   $HOME/*) ;;
31   *) echo >&2 "$0: must be below $HOME"; exit 1;;
32 esac
33 down=$(echo $here | sed "s#^$HOME/##")
34
35 ### Suss out how to print things
36 out=$(echo -n "foo"; echo "bar")
37 if [ "$out" = "foobar" ]; then
38   echon="echo -n"
39   echoc=""
40 else
41   echon="echo"
42   echoc='\c'
43 fi
44
45 ### Create the necessary directories
46 echo "Creating directories..."
47 for i in bin lib/emacs src; do
48   $echon "  $i:$echoc"
49   if [ -d $HOME$sub/$i ]; then
50     echo " already exists."
51   else
52     mkdir -p $HOME$sub/$i
53     echo " done."
54   fi
55 done
56 echo "  all done."
57
58 ### Find out how to fetch things over the net
59 $echon "Finding URL fetcher:$echoc"
60 if curl >/dev/null 2>&1 --version || [ $? -eq 2 ]; then
61   GETURL="curl -fs -o"
62   echo " curl."
63 elif wget >/dev/null 2>&1 --version; then
64   GETURL="wget -q -O"
65   echo " wget."
66 else
67   echo " failed!"
68   echo >&2 "$0: failed to find URL fetcher"
69   exit 1
70 fi
71
72 ### Install necessary things
73 echo "Installing useful scripts..."
74
75 for script in lesspipe.sh start-ssh-agent; do
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
92 done
93
94 echo "  all done."
95
96 ### Install some more complicated programs
97 echo "Installing packages..."
98 systems="
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 "
106 for 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
132 done
133 echo "  all done."
134
135 ### Symlink the various dotfiles into place
136 dotfiles=" 
137   bash_profile bash_logout bashrc
138   emacs emacs-calc 
139   vm mailrc
140   cmucl-init.lisp clisprc.lisp sbclrc
141   dircolors screenrc"
142 [ "$xstuff" ] && dotfiles="$dotfiles xinitrc xsession Xdefaults"
143 mkdir -p $HOME/test
144 echo "Installing dotfiles..."
145 for d in $dotfiles; do
146   [ -f $d ]
147   rm -f "$HOME$sub/.$d"
148   ln -s $up$down/$d $HOME$sub/.$d
149   echo "  .$d"
150 done
151 echo "  all done."
152
153 ### Set up the Emacs config
154 echo "Installing Emacs packages..."
155 for elib in make-regexp; do
156   $echon "  $elib:$echoc"
157   if $false emacs >/dev/null 2>&1 --batch --eval '
158        (kill-emacs (condition-case nil
159                        (progn (load-library "make-regexp") 0)
160                      (error 1)))'; then
161     echo " already installed."
162   else
163     $echon " downloading$echoc"
164     $GETURL $HOME$sub/lib/emacs/make-regexp.el $REPO/make-regexp.el
165     $echon " compiling$echoc"
166     (cd $HOME$sub/lib/emacs;
167       emacs >/dev/null 2>&1 --batch \
168         --eval '(byte-compile-file "make-regexp.el")')
169     echo " done."
170   fi
171 done
172 echo "  all done."
173
174 $echon "Setting up Emacs configuration:$echoc"
175 $echon " linking$echoc"
176 for link in dot-emacs.el:dot-emacs.el emacs-Makefile:Makefile; do
177   set -- $(echo $link | tr : ' ')
178   from=$1 to=$2
179   rm -f $HOME$sub/lib/emacs/$to
180   ln -s ../../$up$down/$from $HOME$sub/lib/emacs/$to
181 done
182 $echon " compiling$echoc"
183 make >/dev/null 2>&1 -C $HOME$sub/lib/emacs
184 echo " done."