Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ c4101ab5

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-get -y --no-install-recommends -t squeeze-backports install \
120
    git \
121
    git-email \
122
    vim
123

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

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

    
130
in_chroot -- \
131
  locale-gen
132

    
133
in_chroot -- \
134
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
135
               ndisc6 python python-pyopenssl openssl \
136
               python-pyparsing python-simplejson \
137
               python-pyinotify python-pycurl python-yaml 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

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

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

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

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

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

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

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

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

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

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