Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ 5349519d

History | View | Annotate | Download (10.3 kB)

1
#!/bin/bash
2
#Configuration
3
: ${ARCH:=amd64}
4
: ${DIST_RELEASE:=squeeze}
5
: ${CONF_DIR:=/etc/schroot/chroot.d}
6
: ${CHROOT_DIR:=/srv/chroot}
7
: ${ALTERNATIVE_EDITOR:=/usr/bin/vim.basic}
8
: ${CHROOT_FINAL_HOOK:=/bin/true}
9
# Additional Variables taken from the environmen
10
# DATA_DIR
11
# CHROOT_EXTRA_DEBIAN_PACKAGES
12

    
13
#Automatically generated variables
14
CHROOTNAME=$DIST_RELEASE-$ARCH
15
CHNAME=building_$CHROOTNAME
16
TEMP_CHROOT_CONF=$CONF_DIR/$CHNAME.conf
17
FINAL_CHROOT_CONF=$CHROOTNAME.conf
18
ROOT=`pwd`
19
CHDIR=$ROOT/$CHNAME
20
USER=`whoami`
21
COMP_FILENAME=$CHROOTNAME.tar.gz
22
COMP_FILEPATH=$ROOT/$COMP_FILENAME
23
TEMP_DATA_DIR=`mktemp -d`
24
ACTUAL_DATA_DIR=$DATA_DIR
25
ACTUAL_DATA_DIR=${ACTUAL_DATA_DIR:-$TEMP_DATA_DIR}
26

    
27
#Runnability checks
28
if [ $USER != 'root' ]
29
then
30
  echo "This script requires root permissions to run"
31
  exit
32
fi
33

    
34
if [ -f $TEMP_CHROOT_CONF ]
35
then
36
  echo "The configuration file name for the temporary chroot"
37
  echo "  $TEMP_CHROOT_CONF"
38
  echo "already exists."
39
  echo "Remove it or change the CHNAME value in the script."
40
  exit
41
fi
42

    
43
#Create configuration dir and files if they do not exist
44
if [ ! -d $ACTUAL_DATA_DIR ]
45
then
46
  mkdir $ACTUAL_DATA_DIR
47
  echo "The data directory"
48
  echo "  $ACTUAL_DATA_DIR"
49
  echo "has been created."
50
fi
51

    
52
if [ ! -f $ACTUAL_DATA_DIR/final.schroot.conf.in ]
53
then
54
  cat <<END >$ACTUAL_DATA_DIR/final.schroot.conf.in
55
[${CHROOTNAME}]
56
description=Debian ${DIST_RELEASE} ${ARCH}
57
groups=src
58
source-root-groups=root
59
type=file
60
file=${CHROOT_DIR}/${COMP_FILENAME}
61
END
62
  echo "The file"
63
  echo " $ACTUAL_DATA_DIR/final.schroot.conf.in"
64
  echo "has been created with default configurations."
65
fi
66

    
67
if [ ! -f $ACTUAL_DATA_DIR/temp.schroot.conf.in ]
68
then
69
  cat <<END >$ACTUAL_DATA_DIR/temp.schroot.conf.in
70
[${CHNAME}]
71
description=Debian ${DIST_RELEASE} ${ARCH}
72
directory=${CHDIR}
73
groups=src
74
users=root
75
type=directory
76
END
77
  echo "The file"
78
  echo " $ACTUAL_DATA_DIR/temp.schroot.conf.in"
79
  echo "has been created with default configurations."
80
fi
81

    
82
#Stop on errors
83
set -e
84

    
85
#Cleanup
86
rm -rf $CHDIR
87
mkdir $CHDIR
88

    
89
#Install tools for building chroots
90
apt-get install -y schroot debootstrap
91

    
92
shopt -s expand_aliases
93
alias in_chroot='schroot -c $CHNAME -d / '
94
function subst_variables {
95
  sed \
96
    -e "s/\${ARCH}/$ARCH/" \
97
    -e "s*\${CHDIR}*$CHDIR*" \
98
    -e "s/\${CHNAME}/$CHNAME/" \
99
    -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
100
    -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
101
    -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
102
    -e "s/\${DIST_RELEASE}/$DIST_RELEASE/" $@
103
}
104

    
105
#Generate chroot configurations
106
cat $ACTUAL_DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
107
cat $ACTUAL_DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
108

    
109
#Install the base system
110
debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
111

    
112
APT_INSTALL="apt-get install -y --no-install-recommends"
113

    
114
if [ DIST_RELEASE = squeeze ]
115
then
116
  echo "deb http://backports.debian.org/debian-backports" \
117
       "$DIST_RELEASE-backports main contrib non-free" \
118
       > $CHDIR/etc/apt/sources.list.d/backports.list
119
fi
120

    
121
#Install all the packages
122
in_chroot -- \
123
  apt-get update
124

    
125
case $DIST_RELEASE in
126

    
127
  squeeze)
128

    
129
    # do not install libghc6-network-dev, since it's too old, and just
130
    # confuses the dependencies
131
    in_chroot -- \
132
      $APT_INSTALL \
133
        autoconf automake \
134
        ghc cabal-install \
135
        libghc6-curl-dev \
136
        libghc6-parallel-dev \
137
        libghc6-text-dev \
138
        libghc6-vector-dev \
139
        libpcre3-dev \
140
        libghc6-zlib-dev \
141
        hlint hscolour pandoc \
142
        graphviz qemu-utils \
143
        python-docutils \
144
        python-simplejson \
145
        python-pyparsing \
146
        python-pyinotify \
147
        python-pycurl \
148
        python-ipaddr \
149
        python-yaml \
150
        python-paramiko
151

    
152
    in_chroot -- \
153
      $APT_INSTALL python-setuptools python-dev build-essential
154

    
155
    in_chroot -- \
156
      easy_install \
157
        logilab-astng==0.24.1 \
158
        logilab-common==0.58.3 \
159
        mock==1.0.1 \
160
        pylint==0.26.0
161

    
162
    in_chroot -- \
163
      easy_install \
164
        sphinx==1.1.3 \
165
        pep8==1.3.3 \
166
        coverage==3.4 \
167
        bitarray==0.8.0
168

    
169
    in_chroot -- \
170
      cabal update
171

    
172
    in_chroot -- \
173
      cabal install --global \
174
        blaze-builder==0.3.1.1 \
175
        network==2.3 \
176
        regex-pcre==0.94.4 \
177
        hinotify==0.3.2 \
178
        hslogger==1.1.4 \
179
        quickcheck==2.5.1.1 \
180
        attoparsec==0.10.1.1 \
181
        crypto==4.2.4 \
182
        MonadCatchIO-transformers==0.2.2.0 \
183
        mtl==2.0.1.0 \
184
        hashable==1.1.2.0 \
185
        case-insensitive==0.3 \
186
        parsec==3.0.1 \
187
        snap-server==0.8.1 \
188
        json==0.4.4 \
189
        lifted-base==0.2.1.1
190

    
191
    in_chroot -- \
192
      cabal install --global \
193
        hunit==1.2.5.2 \
194
        happy==1.18.10 \
195
        hlint==1.8.43 \
196
        hscolour==1.20.3 \
197
        temporary==1.1.2.3 \
198
        test-framework==0.6.1 \
199
        test-framework-hunit==0.2.7 \
200
        test-framework-quickcheck2==0.2.12.3
201

    
202
    in_chroot -- \
203
      cabal install --global cabal-file-th
204

    
205
    in_chroot -- \
206
      cabal install --global shelltestrunner
207

    
208
    in_chroot -- \
209
      cabal install --global base64-bytestring
210

    
211
    #Install selected packages from backports
212
    in_chroot -- \
213
      $APT_INSTALL -t squeeze-backports \
214
        git \
215
        git-email \
216
        vim
217

    
218
;;
219

    
220
  wheezy)
221

    
222
    in_chroot -- \
223
      $APT_INSTALL \
224
      autoconf automake ghc ghc-haddock libghc-network-dev \
225
      libghc-test-framework{,-hunit,-quickcheck2}-dev \
226
      libghc-json-dev libghc-curl-dev libghc-hinotify-dev \
227
      libghc-parallel-dev libghc-utf8-string-dev \
228
      libghc-hslogger-dev libghc-crypto-dev \
229
      libghc-regex-pcre-dev libghc-attoparsec-dev \
230
      libghc-vector-dev libghc-temporary-dev \
231
      libghc-snap-server-dev libpcre3 libpcre3-dev hscolour hlint pandoc \
232
      libghc6-zlib-dev \
233
      cabal-install\
234
      python-setuptools python-sphinx python-epydoc graphviz python-pyparsing \
235
      python-simplejson python-pycurl python-paramiko \
236
      python-bitarray python-ipaddr python-yaml qemu-utils python-coverage pep8 \
237
      shelltestrunner python-dev pylint openssh-client vim git git-email
238

    
239
    # We need version 0.9.4 of pyinotify because the packaged version, 0.9.3, is
240
    # incompatibile with the packaged version of python-epydoc 3.0.1.
241
    # Reason: a logger class in pyinotify calculates its superclasses at
242
    # runtime, which clashes with python-epydoc's static analysis phase.
243
    #
244
    # Problem introduced in:
245
    #   https://github.com/seb-m/pyinotify/commit/2c7e8f8959d2f8528e0d90847df360
246
    # and "fixed" in:
247
    #   https://github.com/seb-m/pyinotify/commit/98c5f41a6e2e90827a63ff1b878596
248

    
249
    in_chroot -- \
250
      easy_install pyinotify==0.9.4
251

    
252
     in_chroot -- \
253
       cabal update
254

    
255
     in_chroot -- \
256
       cabal install --global \
257
        base64-bytestring \
258
        'lifted-base>=0.1.2'
259
;;
260
  precise)
261
    # ghc, git-email and other dependencies are hosted in the universe
262
    # repository, which is not enabled by default.
263
    echo "Adding universe repository..."
264
    cat > $CHDIR/etc/apt/sources.list.d/universe.list <<EOF
265
deb http://archive.ubuntu.com/ubuntu precise universe
266
EOF
267
    in_chroot -- \
268
      apt-get update
269

    
270
    echo "Installing packages"
271
    in_chroot -- \
272
      $APT_INSTALL \
273
      autoconf automake ghc ghc-haddock libghc-network-dev \
274
      libghc-test-framework{,-hunit,-quickcheck2}-dev \
275
      libghc-json-dev libghc-curl-dev libghc-hinotify-dev \
276
      libghc-parallel-dev libghc-utf8-string-dev \
277
      libghc-hslogger-dev libghc-crypto-dev \
278
      libghc-regex-pcre-dev libghc-attoparsec-dev \
279
      libghc-vector-dev libghc-temporary-dev \
280
      libghc-snap-server-dev libpcre3 libpcre3-dev hscolour hlint pandoc \
281
      python-setuptools python-sphinx python-epydoc graphviz python-pyparsing \
282
      python-simplejson python-pyinotify python-pycurl python-paramiko \
283
      python-bitarray python-ipaddr python-yaml qemu-utils python-coverage pep8 \
284
      python-dev pylint openssh-client vim git git-email \
285
      build-essential
286

    
287
    echo "Installing cabal packages"
288
    in_chroot -- \
289
      $APT_INSTALL cabal-install
290

    
291
    in_chroot -- \
292
      cabal update
293

    
294
     in_chroot -- \
295
       cabal install --global \
296
        base64-bytestring \
297
        'lifted-base>=0.1.2'
298

    
299
    in_chroot -- \
300
      cabal install --global shelltestrunner
301
    ;;
302

    
303
  *)
304
    in_chroot -- \
305
      $APT_INSTALL \
306
      autoconf automake ghc ghc-haddock libghc-network-dev \
307
      libghc-test-framework{,-hunit,-quickcheck2}-dev \
308
      libghc-json-dev libghc-curl-dev libghc-hinotify-dev \
309
      libghc-parallel-dev libghc-utf8-string-dev \
310
      libghc-hslogger-dev libghc-crypto-dev \
311
      libghc-regex-pcre-dev libghc-attoparsec-dev \
312
      libghc-vector-dev libghc-temporary-dev \
313
      libghc-snap-server-dev libpcre3 libpcre3-dev hscolour hlint pandoc \
314
      libghc-lifted-base-dev \
315
      libghc-base64-bytestring-dev \
316
      python-setuptools python-sphinx python-epydoc graphviz python-pyparsing \
317
      python-simplejson python-pyinotify python-pycurl python-paramiko \
318
      python-bitarray python-ipaddr python-yaml qemu-utils python-coverage pep8 \
319
      shelltestrunner python-dev pylint openssh-client vim git git-email \
320
      build-essential
321

    
322
;;
323
esac
324

    
325
in_chroot -- \
326
  $APT_INSTALL sudo fakeroot rsync locales less socat
327

    
328
# Configure the locale
329
case $DIST_RELEASE in
330
  precise)
331
    in_chroot -- \
332
      $APT_INSTALL language-pack-en
333
    ;;
334
  *)
335
    echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
336

    
337
    in_chroot -- \
338
      locale-gen
339
    ;;
340
esac
341

    
342
in_chroot -- \
343
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
344
               ndisc6 python-openssl openssl \
345
               python-mock fping qemu-utils
346

    
347
in_chroot -- \
348
  easy_install affinity
349

    
350
in_chroot -- \
351
  easy_install jsonpointer \
352
    jsonpointer \
353
    jsonpatch
354

    
355
in_chroot -- \
356
  $APT_INSTALL \
357
  python-epydoc debhelper quilt
358

    
359
# extra debian packages
360

    
361
for package in $CHROOT_EXTRA_DEBIAN_PACKAGES
362
do in_chroot -- \
363
  $APT_INSTALL $package
364
done
365

    
366
#Set default editor
367
in_chroot -- \
368
  update-alternatives --set editor $ALTERNATIVE_EDITOR
369

    
370
# Final user hook
371

    
372
in_chroot -- $CHROOT_FINAL_HOOK
373

    
374
rm -f $COMP_FILEPATH
375
echo "Creating compressed schroot image..."
376
cd $CHDIR
377
tar czf $COMP_FILEPATH ./*
378
cd $ROOT
379

    
380
rm -rf $CHDIR
381
rm -f $TEMP_CHROOT_CONF
382
rm -rf $TEMP_DATA_DIR
383

    
384
echo "Chroot created. In order to run it:"
385
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
386
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
387
echo "Then run \"schroot -c $CHROOTNAME\""