Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ 6676f007

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
alias subst_variables='sed \
95
  -e "s/\${ARCH}/$ARCH/" \
96
  -e "s*\${CHDIR}*$CHDIR*" \
97
  -e "s/\${CHNAME}/$CHNAME/" \
98
  -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
99
  -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
100
  -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
101
  -e "s/\${DIST_RELEASE}/$DIST_RELEASE/"'
102

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

    
107
#Install the base system
108
debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
109

    
110
APT_INSTALL="apt-get install -y --no-install-recommends"
111

    
112
echo "deb http://backports.debian.org/debian-backports" \
113
     "$DIST_RELEASE-backports main contrib non-free" \
114
     > $CHDIR/etc/apt/sources.list.d/backports.list
115

    
116
#Install all the packages
117
in_chroot -- \
118
  apt-get update
119

    
120
#Install selected packages from backports
121
in_chroot -- \
122
  $APT_INSTALL -t squeeze-backports \
123
    git \
124
    vim
125

    
126
in_chroot -- \
127
  $APT_INSTALL python-setuptools build-essential python-dev sudo automake \
128
               fakeroot rsync locales less
129

    
130
echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
131

    
132
in_chroot -- \
133
  locale-gen
134

    
135
in_chroot -- \
136
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
137
               ndisc6 python python-pyopenssl openssl \
138
               python-pyparsing python-simplejson \
139
               python-pyinotify python-pycurl python-yaml python-mock \
140
               socat fping
141

    
142
in_chroot -- \
143
  $APT_INSTALL python-paramiko qemu-utils
144

    
145
in_chroot -- \
146
  easy_install affinity bitarray ipaddr
147

    
148
#Haskell packages
149
in_chroot -- \
150
  $APT_INSTALL ghc6 \
151
               libghc6-parallel-dev libghc6-deepseq-dev \
152
               libghc6-curl-dev
153

    
154
in_chroot -- \
155
  $APT_INSTALL cabal-install
156

    
157
in_chroot -- \
158
  cabal update
159

    
160
in_chroot -- \
161
  $APT_INSTALL libpcre3-dev
162

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

    
184
#Python development tools
185
in_chroot -- \
186
  $APT_INSTALL pandoc python-epydoc graphviz
187

    
188
in_chroot -- \
189
  easy_install sphinx==1.1.3 \
190
               logilab-common \
191
               logilab-astng==0.23.1 \
192
               pylint==0.25.1 \
193
               pep8==1.2 \
194
               coverage
195

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

    
208
in_chroot -- \
209
  cabal install --global shelltestrunner
210

    
211
#Tools for creating debian packages
212
in_chroot -- \
213
  $APT_INSTALL python-docutils debhelper quilt
214

    
215
# extra debian packages
216

    
217
for package in $CHROOT_EXTRA_DEBIAN_PACKAGES
218
do in_chroot -- \
219
  $APT_INSTALL $package
220
done
221

    
222
#Set default editor
223
in_chroot -- \
224
  update-alternatives --set editor $ALTERNATIVE_EDITOR
225

    
226
# Final user hook
227

    
228
in_chroot -- $CHROOT_FINAL_HOOK
229

    
230
rm -f $COMP_FILEPATH
231
echo "Creating compressed schroot image..."
232
cd $CHDIR
233
tar czf $COMP_FILEPATH ./*
234
cd $ROOT
235

    
236
rm -rf $CHDIR
237
rm -f $TEMP_CHROOT_CONF
238
rm -rf $TEMP_DATA_DIR
239

    
240
echo "Chroot created. In order to run it:"
241
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
242
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
243

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