Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ dabaa0b0

History | View | Annotate | Download (7.8 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
        hlint hscolour pandoc \
141
        graphviz qemu-utils \
142
        python-docutils \
143
        python-simplejson \
144
        python-pyparsing \
145
        python-pyinotify \
146
        python-pycurl \
147
        python-ipaddr \
148
        python-yaml \
149
        python-paramiko
150

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

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

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

    
168
    in_chroot -- \
169
      cabal update
170

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

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

    
200
    in_chroot -- \
201
      cabal install --global cabal-file-th
202

    
203
    in_chroot -- \
204
      cabal install --global shelltestrunner
205

    
206
    #Install selected packages from backports
207
    in_chroot -- \
208
      $APT_INSTALL -t squeeze-backports \
209
        git \
210
        git-email \
211
        vim
212

    
213
;;
214

    
215
  wheezy)
216

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

    
232
      easy_install pyinotify==0.9.4
233

    
234
;;
235

    
236
  *)
237

    
238
    in_chroot -- \
239
      $APT_INSTALL \
240
      autoconf automake ghc ghc-haddock libghc-network-dev \
241
      libghc-test-framework{,-hunit,-quickcheck2}-dev \
242
      libghc-json-dev libghc-curl-dev libghc-hinotify-dev \
243
      libghc-parallel-dev libghc-utf8-string-dev \
244
      libghc-hslogger-dev libghc-crypto-dev \
245
      libghc-regex-pcre-dev libghc-attoparsec-dev \
246
      libghc-vector-dev libghc-temporary-dev \
247
      libghc-snap-server-dev libpcre3 libpcre3-dev hscolour hlint pandoc \
248
      python-setuptools python-sphinx python-epydoc graphviz python-pyparsing \
249
      python-simplejson python-pyinotify python-pycurl python-paramiko \
250
      python-bitarray python-ipaddr python-yaml qemu-utils python-coverage pep8 \
251
      shelltestrunner python-dev pylint openssh-client vim git git-email
252

    
253
;;
254
esac
255

    
256
echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
257

    
258
in_chroot -- \
259
  $APT_INSTALL sudo fakeroot rsync locales less socat
260

    
261
in_chroot -- \
262
  locale-gen
263

    
264
in_chroot -- \
265
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
266
               ndisc6 python-openssl openssl \
267
               python-mock fping qemu-utils
268

    
269
in_chroot -- \
270
  easy_install affinity
271

    
272
in_chroot -- \
273
  easy_install jsonpointer \
274
    jsonpointer \
275
    jsonpatch
276

    
277
in_chroot -- \
278
  $APT_INSTALL \
279
  python-epydoc debhelper quilt
280

    
281
# extra debian packages
282

    
283
for package in $CHROOT_EXTRA_DEBIAN_PACKAGES
284
do in_chroot -- \
285
  $APT_INSTALL $package
286
done
287

    
288
#Set default editor
289
in_chroot -- \
290
  update-alternatives --set editor $ALTERNATIVE_EDITOR
291

    
292
# Final user hook
293

    
294
in_chroot -- $CHROOT_FINAL_HOOK
295

    
296
rm -f $COMP_FILEPATH
297
echo "Creating compressed schroot image..."
298
cd $CHDIR
299
tar czf $COMP_FILEPATH ./*
300
cd $ROOT
301

    
302
rm -rf $CHDIR
303
rm -f $TEMP_CHROOT_CONF
304
rm -rf $TEMP_DATA_DIR
305

    
306
echo "Chroot created. In order to run it:"
307
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
308
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
309
echo "Then run \"schroot -c $CHROOTNAME\""