Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ 72a7f6b3

History | View | Annotate | Download (5.7 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
echo "deb http://backports.debian.org/debian-backports" \
115
     "$DIST_RELEASE-backports main contrib non-free" \
116
     > $CHDIR/etc/apt/sources.list.d/backports.list
117

    
118
#Install all the packages
119
in_chroot -- \
120
  apt-get update
121

    
122
#Install selected packages from backports
123
in_chroot -- \
124
  $APT_INSTALL -t squeeze-backports \
125
    git \
126
    git-email \
127
    vim
128

    
129
in_chroot -- \
130
  $APT_INSTALL python-setuptools build-essential python-dev sudo automake \
131
               fakeroot rsync locales less
132

    
133
echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
134

    
135
in_chroot -- \
136
  locale-gen
137

    
138
in_chroot -- \
139
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
140
               ndisc6 python python-pyopenssl openssl \
141
               python-pyparsing python-simplejson \
142
               python-pyinotify python-pycurl python-yaml \
143
               socat fping
144

    
145
in_chroot -- \
146
  $APT_INSTALL python-paramiko qemu-utils
147

    
148
in_chroot -- \
149
  easy_install affinity bitarray ipaddr mock==1.0.1
150

    
151
#Haskell packages
152
in_chroot -- \
153
  $APT_INSTALL ghc6 \
154
               libghc6-parallel-dev libghc6-deepseq-dev \
155
               libghc6-curl-dev
156

    
157
in_chroot -- \
158
  $APT_INSTALL cabal-install
159

    
160
in_chroot -- \
161
  cabal update
162

    
163
in_chroot -- \
164
  $APT_INSTALL libpcre3-dev
165

    
166
in_chroot -- \
167
  cabal install --global \
168
    network==2.3 \
169
    regex-pcre==0.94.2 \
170
    hinotify==0.3.2 \
171
    hslogger==1.1.4 \
172
    attoparsec==0.10.1.1\
173
    quickcheck==2.5.1.1 \
174
    crypto==4.2.4 \
175
    monadcatchio-transformers==0.2.2.0 \
176
    mtl==2.0.1.0 \
177
    hashable==1.1.2.0 \
178
    case-insensitive==0.3 \
179
    parsec==3.0.1 \
180
    network==2.3 \
181
    snap-server==0.8.1 \
182
    text==0.11.3.0 \
183
    vector==0.9.1 \
184
    json==0.4.4 \
185
    process==1.0.1.2
186

    
187
#Python development tools
188
in_chroot -- \
189
  $APT_INSTALL pandoc python-epydoc graphviz
190

    
191
in_chroot -- \
192
  easy_install sphinx==1.1.3 \
193
               logilab-common \
194
               logilab-astng==0.23.1 \
195
               pylint==0.25.1 \
196
               pep8==1.2 \
197
               coverage
198

    
199
#Haskell development tools
200
in_chroot -- \
201
  cabal install --global \
202
    hunit==1.2.5.2 \
203
    happy==1.18.10 \
204
    hlint==1.8.34 \
205
    hscolour==1.20.3 \
206
    temporary==1.1.2.3 \
207
    test-framework==0.6.1 \
208
    test-framework-hunit==0.2.7 \
209
    test-framework-quickcheck2==0.2.12.3
210

    
211
in_chroot -- \
212
  cabal install --global shelltestrunner
213

    
214
#Tools for creating debian packages
215
in_chroot -- \
216
  $APT_INSTALL python-docutils debhelper quilt
217

    
218
# extra debian packages
219

    
220
for package in $CHROOT_EXTRA_DEBIAN_PACKAGES
221
do in_chroot -- \
222
  $APT_INSTALL $package
223
done
224

    
225
#Set default editor
226
in_chroot -- \
227
  update-alternatives --set editor $ALTERNATIVE_EDITOR
228

    
229
# Final user hook
230

    
231
in_chroot -- $CHROOT_FINAL_HOOK
232

    
233
rm -f $COMP_FILEPATH
234
echo "Creating compressed schroot image..."
235
cd $CHDIR
236
tar czf $COMP_FILEPATH ./*
237
cd $ROOT
238

    
239
rm -rf $CHDIR
240
rm -f $TEMP_CHROOT_CONF
241
rm -rf $TEMP_DATA_DIR
242

    
243
echo "Chroot created. In order to run it:"
244
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
245
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
246

    
247
echo "Then run \"schroot -c $CHROOTNAME\""