Refactor reading live data in htools
[ganeti-local] / devel / build_chroot
1 #!/bin/bash
2 #Configuration
3 : ${DATA_DIR=`dirname $0`/data}
4 : ${ARCH=amd64}
5 : ${DIST_RELEASE=squeeze}
6 : ${CONF_DIR:=/etc/schroot/chroot.d}
7 : ${CHROOT_DIR:=/srv/chroot}
8 : ${ALTERNATIVE_EDITOR:=/usr/bin/vim.basic}
9
10 #Automatically generated variables
11 CHROOTNAME=$DIST_RELEASE-$ARCH
12 CHNAME=building_$CHROOTNAME
13 TEMP_CHROOT_CONF=$CONF_DIR/$CHNAME.conf
14 FINAL_CHROOT_CONF=$CHROOTNAME.conf
15 ROOT=`pwd`
16 CHDIR=$ROOT/$CHNAME
17 USER=`whoami`
18 COMP_FILENAME=$CHROOTNAME.tar.gz
19 COMP_FILEPATH=$ROOT/$COMP_FILENAME
20
21 #Runnability checks
22 if [ $USER != 'root' ]
23 then
24   echo "This script requires root permissions to run"
25   exit
26 fi
27
28 if [ -f $TEMP_CHROOT_CONF ]
29 then
30   echo "The configuration file name for the temporary chroot"
31   echo "  $TEMP_CHROOT_CONF"
32   echo "already exists."
33   echo "Remove it or change the CHNAME value in the script."
34   exit
35 fi
36
37 if [ ! -d $DATA_DIR ]
38 then
39   echo "The data directory"
40   echo "  $DATA_DIR"
41   echo "does not exist."
42   echo "Please, set the DATA_DIR environment variable so that it points to the"
43   echo "data directory."
44   exit
45 fi
46
47 set -e
48
49 #Cleanup
50 rm -rf $CHDIR
51 mkdir $CHDIR
52
53 #Install tools for building chroots
54 apt-get install -y schroot debootstrap
55
56 shopt -s expand_aliases
57 alias in_chroot='schroot -c $CHNAME -d / '
58 alias subst_variables='sed \
59   -e "s/\${ARCH}/$ARCH/" \
60   -e "s*\${CHDIR}*$CHDIR*" \
61   -e "s/\${CHNAME}/$CHNAME/" \
62   -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
63   -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
64   -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
65   -e "s/\${DIST_RELEASE}/$DIST_RELEASE/"'
66
67 #Generate chroot configurations
68 cat $DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
69 cat $DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
70
71 #Install the base system
72 debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
73
74 APT_INSTALL="apt-get install -y --no-install-recommends"
75
76 echo "deb http://backports.debian.org/debian-backports" \
77      "$DIST_RELEASE-backports main contrib non-free" \
78      > $CHDIR/etc/apt/sources.list.d/backports.list
79
80 #Install all the packages
81 in_chroot -- \
82   apt-get update
83
84 #Install selected packages from backports
85 in_chroot -- \
86   apt-get -y --no-install-recommends -t squeeze-backports install \
87     git \
88     vim
89
90 in_chroot -- \
91   $APT_INSTALL python-setuptools build-essential python-dev sudo automake \
92                fakeroot rsync locales less
93
94 echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
95
96 in_chroot -- \
97   locale-gen
98
99 in_chroot -- \
100   $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
101                ndisc6 python python-pyopenssl openssl \
102                python-pyparsing python-simplejson \
103                python-pyinotify python-pycurl python-yaml python-mock \
104                socat fping
105
106 in_chroot -- \
107   $APT_INSTALL python-paramiko qemu-utils
108
109 in_chroot -- \
110   easy_install affinity bitarray ipaddr
111
112 #Haskell packages
113 in_chroot -- \
114   $APT_INSTALL ghc6 \
115                libghc6-parallel-dev libghc6-deepseq-dev \
116                libghc6-curl-dev
117
118 in_chroot -- \
119   $APT_INSTALL cabal-install
120
121 in_chroot -- \
122   cabal update
123
124 in_chroot -- \
125   $APT_INSTALL libpcre3-dev
126
127 in_chroot -- \
128   cabal install --global \
129     network==2.3 \
130     regex-pcre==0.94.2 \
131     hinotify==0.3.2 \
132     hslogger==1.1.4 \
133     attoparsec==0.10.1.1\
134     quickcheck==2.5.1.1 \
135     crypto==4.2.4 \
136     monadcatchio-transformers==0.2.2.0 \
137     mtl==2.0.1.0 \
138     hashable==1.1.2.0 \
139     case-insensitive==0.3 \
140     parsec==3.0.1 \
141     network==2.3 \
142     snap-server==0.8.1 \
143     text==0.11.3.0 \
144     vector==0.9.1 \
145     json==0.4.4 \
146     process==1.0.1.2
147
148 #Python development tools
149 in_chroot -- \
150   $APT_INSTALL pandoc python-epydoc graphviz
151
152 in_chroot -- \
153   easy_install sphinx==1.1.3 \
154                logilab-common \
155                logilab-astng==0.23.1 \
156                pylint==0.25.1 \
157                pep8==1.2 \
158                coverage
159
160 #Haskell development tools
161 in_chroot -- \
162   cabal install --global \
163     hunit==1.2.5.2 \
164     happy==1.18.10 \
165     hlint==1.8.34 \
166     hscolour==1.20.3 \
167     temporary==1.1.2.3 \
168     test-framework==0.6.1 \
169     test-framework-hunit==0.2.7 \
170     test-framework-quickcheck2==0.2.12.3
171
172 in_chroot -- \
173   cabal install --global shelltestrunner
174
175 #Set default editor
176 in_chroot -- \
177   update-alternatives --set editor $ALTERNATIVE_EDITOR
178
179 rm -f $COMP_FILEPATH
180 echo "Creating compressed schroot image..."
181 cd $CHDIR
182 tar czf $COMP_FILEPATH ./*
183 cd $ROOT
184 echo "Done"
185
186 rm -rf $CHDIR
187 rm -f $TEMP_CHROOT_CONF