Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ ed2c3597

History | View | Annotate | Download (7.3 kB)

1 8b3f1f42 Michele Tartara
#!/bin/bash
2 8b3f1f42 Michele Tartara
#Configuration
3 d1068153 Michele Tartara
: ${ARCH:=amd64}
4 d1068153 Michele Tartara
: ${DIST_RELEASE:=squeeze}
5 8b3f1f42 Michele Tartara
: ${CONF_DIR:=/etc/schroot/chroot.d}
6 8b3f1f42 Michele Tartara
: ${CHROOT_DIR:=/srv/chroot}
7 35133aae Michele Tartara
: ${ALTERNATIVE_EDITOR:=/usr/bin/vim.basic}
8 6676f007 Klaus Aehlig
: ${CHROOT_FINAL_HOOK:=/bin/true}
9 6676f007 Klaus Aehlig
# Additional Variables taken from the environmen
10 6676f007 Klaus Aehlig
# DATA_DIR
11 e2bbdded Michele Tartara
# CHROOT_EXTRA_DEBIAN_PACKAGES
12 8b3f1f42 Michele Tartara
13 8b3f1f42 Michele Tartara
#Automatically generated variables
14 8b3f1f42 Michele Tartara
CHROOTNAME=$DIST_RELEASE-$ARCH
15 8b3f1f42 Michele Tartara
CHNAME=building_$CHROOTNAME
16 8b3f1f42 Michele Tartara
TEMP_CHROOT_CONF=$CONF_DIR/$CHNAME.conf
17 8b3f1f42 Michele Tartara
FINAL_CHROOT_CONF=$CHROOTNAME.conf
18 8b3f1f42 Michele Tartara
ROOT=`pwd`
19 8b3f1f42 Michele Tartara
CHDIR=$ROOT/$CHNAME
20 8b3f1f42 Michele Tartara
USER=`whoami`
21 8b3f1f42 Michele Tartara
COMP_FILENAME=$CHROOTNAME.tar.gz
22 8b3f1f42 Michele Tartara
COMP_FILEPATH=$ROOT/$COMP_FILENAME
23 d1068153 Michele Tartara
TEMP_DATA_DIR=`mktemp -d`
24 d1068153 Michele Tartara
ACTUAL_DATA_DIR=$DATA_DIR
25 d1068153 Michele Tartara
ACTUAL_DATA_DIR=${ACTUAL_DATA_DIR:-$TEMP_DATA_DIR}
26 8b3f1f42 Michele Tartara
27 8b3f1f42 Michele Tartara
#Runnability checks
28 8b3f1f42 Michele Tartara
if [ $USER != 'root' ]
29 8b3f1f42 Michele Tartara
then
30 8b3f1f42 Michele Tartara
  echo "This script requires root permissions to run"
31 8b3f1f42 Michele Tartara
  exit
32 8b3f1f42 Michele Tartara
fi
33 8b3f1f42 Michele Tartara
34 8b3f1f42 Michele Tartara
if [ -f $TEMP_CHROOT_CONF ]
35 8b3f1f42 Michele Tartara
then
36 8b3f1f42 Michele Tartara
  echo "The configuration file name for the temporary chroot"
37 8b3f1f42 Michele Tartara
  echo "  $TEMP_CHROOT_CONF"
38 8b3f1f42 Michele Tartara
  echo "already exists."
39 8b3f1f42 Michele Tartara
  echo "Remove it or change the CHNAME value in the script."
40 8b3f1f42 Michele Tartara
  exit
41 8b3f1f42 Michele Tartara
fi
42 8b3f1f42 Michele Tartara
43 d1068153 Michele Tartara
#Create configuration dir and files if they do not exist
44 d1068153 Michele Tartara
if [ ! -d $ACTUAL_DATA_DIR ]
45 85b66af5 Michele Tartara
then
46 d1068153 Michele Tartara
  mkdir $ACTUAL_DATA_DIR
47 85b66af5 Michele Tartara
  echo "The data directory"
48 d1068153 Michele Tartara
  echo "  $ACTUAL_DATA_DIR"
49 d1068153 Michele Tartara
  echo "has been created."
50 d1068153 Michele Tartara
fi
51 d1068153 Michele Tartara
52 d1068153 Michele Tartara
if [ ! -f $ACTUAL_DATA_DIR/final.schroot.conf.in ]
53 d1068153 Michele Tartara
then
54 d1068153 Michele Tartara
  cat <<END >$ACTUAL_DATA_DIR/final.schroot.conf.in
55 d1068153 Michele Tartara
[${CHROOTNAME}]
56 d1068153 Michele Tartara
description=Debian ${DIST_RELEASE} ${ARCH}
57 d1068153 Michele Tartara
groups=src
58 d1068153 Michele Tartara
source-root-groups=root
59 d1068153 Michele Tartara
type=file
60 d1068153 Michele Tartara
file=${CHROOT_DIR}/${COMP_FILENAME}
61 d1068153 Michele Tartara
END
62 d1068153 Michele Tartara
  echo "The file"
63 d1068153 Michele Tartara
  echo " $ACTUAL_DATA_DIR/final.schroot.conf.in"
64 d1068153 Michele Tartara
  echo "has been created with default configurations."
65 85b66af5 Michele Tartara
fi
66 85b66af5 Michele Tartara
67 d1068153 Michele Tartara
if [ ! -f $ACTUAL_DATA_DIR/temp.schroot.conf.in ]
68 d1068153 Michele Tartara
then
69 d1068153 Michele Tartara
  cat <<END >$ACTUAL_DATA_DIR/temp.schroot.conf.in
70 d1068153 Michele Tartara
[${CHNAME}]
71 d1068153 Michele Tartara
description=Debian ${DIST_RELEASE} ${ARCH}
72 d1068153 Michele Tartara
directory=${CHDIR}
73 d1068153 Michele Tartara
groups=src
74 d1068153 Michele Tartara
users=root
75 d1068153 Michele Tartara
type=directory
76 d1068153 Michele Tartara
END
77 d1068153 Michele Tartara
  echo "The file"
78 d1068153 Michele Tartara
  echo " $ACTUAL_DATA_DIR/temp.schroot.conf.in"
79 d1068153 Michele Tartara
  echo "has been created with default configurations."
80 85b66af5 Michele Tartara
fi
81 85b66af5 Michele Tartara
82 d1068153 Michele Tartara
#Stop on errors
83 8b3f1f42 Michele Tartara
set -e
84 8b3f1f42 Michele Tartara
85 8b3f1f42 Michele Tartara
#Cleanup
86 8b3f1f42 Michele Tartara
rm -rf $CHDIR
87 8b3f1f42 Michele Tartara
mkdir $CHDIR
88 8b3f1f42 Michele Tartara
89 8b3f1f42 Michele Tartara
#Install tools for building chroots
90 8b3f1f42 Michele Tartara
apt-get install -y schroot debootstrap
91 8b3f1f42 Michele Tartara
92 8b3f1f42 Michele Tartara
shopt -s expand_aliases
93 8b3f1f42 Michele Tartara
alias in_chroot='schroot -c $CHNAME -d / '
94 3b308f47 Michele Tartara
function subst_variables {
95 3b308f47 Michele Tartara
  sed \
96 3b308f47 Michele Tartara
    -e "s/\${ARCH}/$ARCH/" \
97 3b308f47 Michele Tartara
    -e "s*\${CHDIR}*$CHDIR*" \
98 3b308f47 Michele Tartara
    -e "s/\${CHNAME}/$CHNAME/" \
99 3b308f47 Michele Tartara
    -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
100 3b308f47 Michele Tartara
    -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
101 3b308f47 Michele Tartara
    -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
102 3b308f47 Michele Tartara
    -e "s/\${DIST_RELEASE}/$DIST_RELEASE/" $@
103 3b308f47 Michele Tartara
}
104 8b3f1f42 Michele Tartara
105 8b3f1f42 Michele Tartara
#Generate chroot configurations
106 d1068153 Michele Tartara
cat $ACTUAL_DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
107 d1068153 Michele Tartara
cat $ACTUAL_DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
108 8b3f1f42 Michele Tartara
109 8b3f1f42 Michele Tartara
#Install the base system
110 8b3f1f42 Michele Tartara
debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
111 8b3f1f42 Michele Tartara
112 8b3f1f42 Michele Tartara
APT_INSTALL="apt-get install -y --no-install-recommends"
113 8b3f1f42 Michele Tartara
114 ed2c3597 Santi Raffa
if [ DIST_RELEASE = squeeze ]
115 ed2c3597 Santi Raffa
then
116 ed2c3597 Santi Raffa
  echo "deb http://backports.debian.org/debian-backports" \
117 ed2c3597 Santi Raffa
       "$DIST_RELEASE-backports main contrib non-free" \
118 ed2c3597 Santi Raffa
       > $CHDIR/etc/apt/sources.list.d/backports.list
119 ed2c3597 Santi Raffa
fi
120 d8e3c5c9 Michele Tartara
121 8b3f1f42 Michele Tartara
#Install all the packages
122 8b3f1f42 Michele Tartara
in_chroot -- \
123 8b3f1f42 Michele Tartara
  apt-get update
124 8b3f1f42 Michele Tartara
125 ed2c3597 Santi Raffa
case $DIST_RELEASE in
126 ed2c3597 Santi Raffa
127 ed2c3597 Santi Raffa
  squeeze)
128 8b3f1f42 Michele Tartara
129 e2bbdded Michele Tartara
# do not install libghc6-network-dev, since it's too old, and just
130 e2bbdded Michele Tartara
# confuses the dependencies
131 8b3f1f42 Michele Tartara
in_chroot -- \
132 e2bbdded Michele Tartara
  $APT_INSTALL \
133 e2bbdded Michele Tartara
    autoconf automake \
134 e2bbdded Michele Tartara
    ghc cabal-install \
135 e2bbdded Michele Tartara
    libghc6-curl-dev \
136 e2bbdded Michele Tartara
    libghc6-parallel-dev \
137 e2bbdded Michele Tartara
    libghc6-text-dev \
138 e2bbdded Michele Tartara
    libghc6-vector-dev \
139 e2bbdded Michele Tartara
    libpcre3-dev \
140 e2bbdded Michele Tartara
    hlint hscolour pandoc \
141 ed2c3597 Santi Raffa
    graphviz qemu-utils \
142 e2bbdded Michele Tartara
    python-docutils \
143 e2bbdded Michele Tartara
    python-simplejson \
144 e2bbdded Michele Tartara
    python-pyparsing \
145 e2bbdded Michele Tartara
    python-pyinotify \
146 e2bbdded Michele Tartara
    python-pycurl \
147 e2bbdded Michele Tartara
    python-ipaddr \
148 e2bbdded Michele Tartara
    python-yaml \
149 e2bbdded Michele Tartara
    python-paramiko
150 8b3f1f42 Michele Tartara
151 8b3f1f42 Michele Tartara
in_chroot -- \
152 e2bbdded Michele Tartara
  $APT_INSTALL python-setuptools python-dev build-essential
153 8b3f1f42 Michele Tartara
154 8b3f1f42 Michele Tartara
in_chroot -- \
155 e2bbdded Michele Tartara
  easy_install \
156 ab6536ba Michele Tartara
    logilab-astng==0.24.1 \
157 ab6536ba Michele Tartara
    logilab-common==0.58.3 \
158 e2bbdded Michele Tartara
    mock==1.0.1 \
159 ab6536ba Michele Tartara
    pylint==0.26.0
160 8b3f1f42 Michele Tartara
161 8b3f1f42 Michele Tartara
in_chroot -- \
162 e2bbdded Michele Tartara
  easy_install \
163 e2bbdded Michele Tartara
    sphinx==1.1.3 \
164 ab6536ba Michele Tartara
    pep8==1.3.3 \
165 e2bbdded Michele Tartara
    coverage==3.4 \
166 e2bbdded Michele Tartara
    bitarray==0.8.0
167 8b3f1f42 Michele Tartara
168 8b3f1f42 Michele Tartara
in_chroot -- \
169 8b3f1f42 Michele Tartara
  cabal update
170 8b3f1f42 Michele Tartara
171 8b3f1f42 Michele Tartara
in_chroot -- \
172 8b3f1f42 Michele Tartara
  cabal install --global \
173 71e00202 Michele Tartara
    network==2.3 \
174 71a3ad07 Helga Velroyen
    regex-pcre==0.94.4 \
175 74685117 Michele Tartara
    hinotify==0.3.2 \
176 71e00202 Michele Tartara
    hslogger==1.1.4 \
177 71e00202 Michele Tartara
    quickcheck==2.5.1.1 \
178 e2bbdded Michele Tartara
    attoparsec==0.10.1.1 \
179 71e00202 Michele Tartara
    crypto==4.2.4 \
180 e2bbdded Michele Tartara
    MonadCatchIO-transformers==0.2.2.0 \
181 71e00202 Michele Tartara
    mtl==2.0.1.0 \
182 71e00202 Michele Tartara
    hashable==1.1.2.0 \
183 71e00202 Michele Tartara
    case-insensitive==0.3 \
184 71e00202 Michele Tartara
    parsec==3.0.1 \
185 71e00202 Michele Tartara
    snap-server==0.8.1 \
186 e2bbdded Michele Tartara
    json==0.4.4
187 74685117 Michele Tartara
188 8b3f1f42 Michele Tartara
in_chroot -- \
189 8b3f1f42 Michele Tartara
  cabal install --global \
190 71e00202 Michele Tartara
    hunit==1.2.5.2 \
191 71e00202 Michele Tartara
    happy==1.18.10 \
192 ab6536ba Michele Tartara
    hlint==1.8.43 \
193 8b3f1f42 Michele Tartara
    hscolour==1.20.3 \
194 71e00202 Michele Tartara
    temporary==1.1.2.3 \
195 8b3f1f42 Michele Tartara
    test-framework==0.6.1 \
196 8b3f1f42 Michele Tartara
    test-framework-hunit==0.2.7 \
197 8b3f1f42 Michele Tartara
    test-framework-quickcheck2==0.2.12.3
198 8b3f1f42 Michele Tartara
199 8b3f1f42 Michele Tartara
in_chroot -- \
200 e2bbdded Michele Tartara
  cabal install --global cabal-file-th
201 e2bbdded Michele Tartara
202 e2bbdded Michele Tartara
in_chroot -- \
203 8b3f1f42 Michele Tartara
  cabal install --global shelltestrunner
204 8b3f1f42 Michele Tartara
205 e2bbdded Michele Tartara
#Install selected packages from backports
206 e2bbdded Michele Tartara
in_chroot -- \
207 e2bbdded Michele Tartara
  $APT_INSTALL -t squeeze-backports \
208 e2bbdded Michele Tartara
    git \
209 e2bbdded Michele Tartara
    git-email \
210 e2bbdded Michele Tartara
    vim
211 e2bbdded Michele Tartara
212 ed2c3597 Santi Raffa
;;
213 ed2c3597 Santi Raffa
214 ed2c3597 Santi Raffa
  wheezy)
215 ed2c3597 Santi Raffa
216 e2bbdded Michele Tartara
in_chroot -- \
217 ed2c3597 Santi Raffa
  $APT_INSTALL \
218 ed2c3597 Santi Raffa
  autoconf automake ghc ghc-haddock libghc-network-dev \
219 ed2c3597 Santi Raffa
  libghc-test-framework{,-hunit,-quickcheck2}-dev \
220 ed2c3597 Santi Raffa
  libghc-json-dev libghc-curl-dev libghc-hinotify-dev \
221 ed2c3597 Santi Raffa
  libghc-parallel-dev libghc-utf8-string-dev \
222 ed2c3597 Santi Raffa
  libghc-hslogger-dev libghc-crypto-dev \
223 ed2c3597 Santi Raffa
  libghc-regex-pcre-dev libghc-attoparsec-dev \
224 ed2c3597 Santi Raffa
  libghc-vector-dev libghc-temporary-dev \
225 ed2c3597 Santi Raffa
  libghc-snap-server-dev libpcre3 libpcre3-dev hscolour hlint pandoc \
226 ed2c3597 Santi Raffa
  python-setuptools python-sphinx python-epydoc graphviz python-pyparsing \
227 ed2c3597 Santi Raffa
  python-simplejson python-pycurl python-paramiko \
228 ed2c3597 Santi Raffa
  python-bitarray python-ipaddr python-yaml qemu-utils python-coverage pep8 \
229 ed2c3597 Santi Raffa
  shelltestrunner python-dev pylint openssh-client vim git git-email
230 e2bbdded Michele Tartara
231 ed2c3597 Santi Raffa
  easy_install pyinotify==0.9.4
232 ed2c3597 Santi Raffa
233 ed2c3597 Santi Raffa
;;
234 ed2c3597 Santi Raffa
235 ed2c3597 Santi Raffa
  *)
236 e2bbdded Michele Tartara
237 e2bbdded Michele Tartara
in_chroot -- \
238 ed2c3597 Santi Raffa
  $APT_INSTALL \
239 ed2c3597 Santi Raffa
  autoconf automake ghc ghc-haddock libghc-network-dev \
240 ed2c3597 Santi Raffa
  libghc-test-framework{,-hunit,-quickcheck2}-dev \
241 ed2c3597 Santi Raffa
  libghc-json-dev libghc-curl-dev libghc-hinotify-dev \
242 ed2c3597 Santi Raffa
  libghc-parallel-dev libghc-utf8-string-dev \
243 ed2c3597 Santi Raffa
  libghc-hslogger-dev libghc-crypto-dev \
244 ed2c3597 Santi Raffa
  libghc-regex-pcre-dev libghc-attoparsec-dev \
245 ed2c3597 Santi Raffa
  libghc-vector-dev libghc-temporary-dev \
246 ed2c3597 Santi Raffa
  libghc-snap-server-dev libpcre3 libpcre3-dev hscolour hlint pandoc \
247 ed2c3597 Santi Raffa
  python-setuptools python-sphinx python-epydoc graphviz python-pyparsing \
248 ed2c3597 Santi Raffa
  python-simplejson python-pyinotify python-pycurl python-paramiko \
249 ed2c3597 Santi Raffa
  python-bitarray python-ipaddr python-yaml qemu-utils python-coverage pep8 \
250 ed2c3597 Santi Raffa
  shelltestrunner python-dev pylint openssh-client vim git git-email
251 ed2c3597 Santi Raffa
252 ed2c3597 Santi Raffa
;;
253 ed2c3597 Santi Raffa
esac
254 ed2c3597 Santi Raffa
255 ed2c3597 Santi Raffa
echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
256 e2bbdded Michele Tartara
257 e2bbdded Michele Tartara
in_chroot -- \
258 ed2c3597 Santi Raffa
  $APT_INSTALL sudo fakeroot rsync locales less socat
259 e2bbdded Michele Tartara
260 e2bbdded Michele Tartara
in_chroot -- \
261 ed2c3597 Santi Raffa
  locale-gen
262 e2bbdded Michele Tartara
263 e2bbdded Michele Tartara
in_chroot -- \
264 ed2c3597 Santi Raffa
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
265 ed2c3597 Santi Raffa
               ndisc6 python-openssl openssl \
266 ed2c3597 Santi Raffa
               python-mock fping qemu-utils
267 e2bbdded Michele Tartara
268 e2bbdded Michele Tartara
in_chroot -- \
269 ed2c3597 Santi Raffa
  easy_install affinity
270 e2bbdded Michele Tartara
271 9839902a Michele Tartara
in_chroot -- \
272 ed2c3597 Santi Raffa
  $APT_INSTALL \
273 ed2c3597 Santi Raffa
  python-epydoc debhelper quilt
274 9839902a Michele Tartara
275 6676f007 Klaus Aehlig
# extra debian packages
276 6676f007 Klaus Aehlig
277 6676f007 Klaus Aehlig
for package in $CHROOT_EXTRA_DEBIAN_PACKAGES
278 6676f007 Klaus Aehlig
do in_chroot -- \
279 6676f007 Klaus Aehlig
  $APT_INSTALL $package
280 6676f007 Klaus Aehlig
done
281 6676f007 Klaus Aehlig
282 35133aae Michele Tartara
#Set default editor
283 35133aae Michele Tartara
in_chroot -- \
284 35133aae Michele Tartara
  update-alternatives --set editor $ALTERNATIVE_EDITOR
285 35133aae Michele Tartara
286 6676f007 Klaus Aehlig
# Final user hook
287 6676f007 Klaus Aehlig
288 6676f007 Klaus Aehlig
in_chroot -- $CHROOT_FINAL_HOOK
289 6676f007 Klaus Aehlig
290 8b3f1f42 Michele Tartara
rm -f $COMP_FILEPATH
291 8b3f1f42 Michele Tartara
echo "Creating compressed schroot image..."
292 8b3f1f42 Michele Tartara
cd $CHDIR
293 8b3f1f42 Michele Tartara
tar czf $COMP_FILEPATH ./*
294 8b3f1f42 Michele Tartara
cd $ROOT
295 8b3f1f42 Michele Tartara
296 8b3f1f42 Michele Tartara
rm -rf $CHDIR
297 8b3f1f42 Michele Tartara
rm -f $TEMP_CHROOT_CONF
298 d1068153 Michele Tartara
rm -rf $TEMP_DATA_DIR
299 3be0f700 Michele Tartara
300 3be0f700 Michele Tartara
echo "Chroot created. In order to run it:"
301 3be0f700 Michele Tartara
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
302 3be0f700 Michele Tartara
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
303 3be0f700 Michele Tartara
echo "Then run \"schroot -c $CHROOTNAME\""