Add script for building chroot
[ganeti-github.git] / devel / build_chroot
1 #!/bin/bash
2 #Configuration
3 : ${DATA_DIR=data}
4 : ${ARCH=amd64}
5 : ${DIST_RELEASE=squeeze}
6 : ${CONF_DIR:=/etc/schroot/chroot.d}
7 : ${CHROOT_DIR:=/srv/chroot}
8
9 #Automatically generated variables
10 CHROOTNAME=$DIST_RELEASE-$ARCH
11 CHNAME=building_$CHROOTNAME
12 TEMP_CHROOT_CONF=$CONF_DIR/$CHNAME.conf
13 FINAL_CHROOT_CONF=$CHROOTNAME.conf
14 ROOT=`pwd`
15 CHDIR=$ROOT/$CHNAME
16 USER=`whoami`
17 COMP_FILENAME=$CHROOTNAME.tar.gz
18 COMP_FILEPATH=$ROOT/$COMP_FILENAME
19
20 #Runnability checks
21 if [ $USER != 'root' ]
22 then
23   echo "This script requires root permissions to run"
24   exit
25 fi
26
27 if [ -f $TEMP_CHROOT_CONF ]
28 then
29   echo "The configuration file name for the temporary chroot"
30   echo "  $TEMP_CHROOT_CONF"
31   echo "already exists."
32   echo "Remove it or change the CHNAME value in the script."
33   exit
34 fi
35
36 set -e
37
38 #Cleanup
39 rm -rf $CHDIR
40 mkdir $CHDIR
41
42 #Install tools for building chroots
43 apt-get install -y schroot debootstrap
44
45 shopt -s expand_aliases
46 alias in_chroot='schroot -c $CHNAME -d / '
47 alias subst_variables='sed \
48   -e "s/\${ARCH}/$ARCH/" \
49   -e "s*\${CHDIR}*$CHDIR*" \
50   -e "s/\${CHNAME}/$CHNAME/" \
51   -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
52   -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
53   -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
54   -e "s/\${DIST_RELEASE}/$DIST_RELEASE/"'
55
56 #Generate chroot configurations
57 cat $DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
58 cat $DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
59
60 #Install the base system
61 debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
62
63 APT_INSTALL="apt-get install -y --no-install-recommends"
64
65 #Install all the packages
66 in_chroot -- \
67   apt-get update
68
69 in_chroot -- \
70   $APT_INSTALL python-setuptools build-essential python-dev sudo automake git \
71                fakeroot vim rsync locales
72
73 echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
74
75 in_chroot -- \
76   locale-gen
77
78 in_chroot -- \
79   $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
80                ndisc6 python python-pyopenssl openssl \
81                python-pyparsing python-simplejson \
82                python-pyinotify python-pycurl python-yaml socat fping
83
84 in_chroot -- \
85   $APT_INSTALL python-paramiko qemu-utils
86
87 in_chroot -- \
88   easy_install affinity bitarray ipaddr
89
90 #Haskell packages
91 in_chroot -- \
92   $APT_INSTALL ghc6 \
93                libghc6-parallel-dev libghc6-deepseq-dev \
94                libghc6-curl-dev
95
96 in_chroot -- \
97   $APT_INSTALL cabal-install
98
99 in_chroot -- \
100   cabal update
101
102 in_chroot -- \
103   $APT_INSTALL libpcre3-dev
104
105 in_chroot -- \
106   cabal install --global \
107     QuickCheck==2.5.1.1 \
108     network==2.3 hslogger Crypto text regex-pcre \
109     attoparsec vector \
110     json==0.4.4 \
111     MonadCatchIO-transformers==0.2.2.0 mtl==2.0.1.0 \
112     hashable==1.1.2.0 case-insensitive==0.3 parsec==3.0.1 \
113     network==2.3 snap-server==0.8.1 \
114     hinotify==0.3.2
115
116 #Python development tools
117 in_chroot -- \
118   $APT_INSTALL pandoc python-epydoc graphviz
119
120 in_chroot -- \
121   easy_install sphinx==1.1.3 \
122                logilab-common \
123                logilab-astng==0.23.1 \
124                pylint==0.25.1 \
125                pep8==1.2 \
126                coverage
127
128 #Haskell development tools
129 in_chroot -- \
130   cabal install --global \
131     HUnit \
132     happy \
133     hlint==1.8.34 \
134     hscolour==1.20.3 \
135     temporary \
136     test-framework==0.6.1 \
137     test-framework-hunit==0.2.7 \
138     test-framework-quickcheck2==0.2.12.3
139
140 in_chroot -- \
141   cabal install --global shelltestrunner
142
143 rm -f $COMP_FILEPATH
144 echo "Creating compressed schroot image..."
145 cd $CHDIR
146 tar czf $COMP_FILEPATH ./*
147 cd $ROOT
148 echo "Done"
149
150 rm -rf $CHDIR
151 rm -f $TEMP_CHROOT_CONF