Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ 43ffd839

History | View | Annotate | Download (5.5 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
# The value of DATA_DIR is read as well from the environment.
9

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

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

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

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

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

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

    
79
#Stop on errors
80
set -e
81

    
82
#Cleanup
83
rm -rf $CHDIR
84
mkdir $CHDIR
85

    
86
#Install tools for building chroots
87
apt-get install -y schroot debootstrap
88

    
89
shopt -s expand_aliases
90
alias in_chroot='schroot -c $CHNAME -d / '
91
alias subst_variables='sed \
92
  -e "s/\${ARCH}/$ARCH/" \
93
  -e "s*\${CHDIR}*$CHDIR*" \
94
  -e "s/\${CHNAME}/$CHNAME/" \
95
  -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
96
  -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
97
  -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
98
  -e "s/\${DIST_RELEASE}/$DIST_RELEASE/"'
99

    
100
#Generate chroot configurations
101
cat $ACTUAL_DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
102
cat $ACTUAL_DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
103

    
104
#Install the base system
105
debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
106

    
107
APT_INSTALL="apt-get install -y --no-install-recommends"
108

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

    
113
#Install all the packages
114
in_chroot -- \
115
  apt-get update
116

    
117
#Install selected packages from backports
118
in_chroot -- \
119
  $APT_INSTALL -t squeeze-backports install \
120
    git \
121
    vim
122

    
123
in_chroot -- \
124
  $APT_INSTALL python-setuptools build-essential python-dev sudo automake \
125
               fakeroot rsync locales less
126

    
127
echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
128

    
129
in_chroot -- \
130
  locale-gen
131

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

    
139
in_chroot -- \
140
  $APT_INSTALL python-paramiko qemu-utils
141

    
142
in_chroot -- \
143
  easy_install affinity bitarray ipaddr
144

    
145
#Haskell packages
146
in_chroot -- \
147
  $APT_INSTALL ghc6 \
148
               libghc6-parallel-dev libghc6-deepseq-dev \
149
               libghc6-curl-dev
150

    
151
in_chroot -- \
152
  $APT_INSTALL cabal-install
153

    
154
in_chroot -- \
155
  cabal update
156

    
157
in_chroot -- \
158
  $APT_INSTALL libpcre3-dev
159

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

    
181
#Python development tools
182
in_chroot -- \
183
  $APT_INSTALL pandoc python-epydoc graphviz
184

    
185
in_chroot -- \
186
  easy_install sphinx==1.1.3 \
187
               logilab-common \
188
               logilab-astng==0.23.1 \
189
               pylint==0.25.1 \
190
               pep8==1.2 \
191
               coverage
192

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

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

    
208
#Tools for creating debian packages
209
in_chroot -- \
210
  $APT_INSTALL python-docutils debhelper quilt
211

    
212
#Set default editor
213
in_chroot -- \
214
  update-alternatives --set editor $ALTERNATIVE_EDITOR
215

    
216
rm -f $COMP_FILEPATH
217
echo "Creating compressed schroot image..."
218
cd $CHDIR
219
tar czf $COMP_FILEPATH ./*
220
cd $ROOT
221

    
222
rm -rf $CHDIR
223
rm -f $TEMP_CHROOT_CONF
224
rm -rf $TEMP_DATA_DIR
225

    
226
echo "Chroot created. In order to run it:"
227
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
228
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
229

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