Statistics
| Branch: | Tag: | Revision:

root / devel / build_chroot @ e2bbdded

History | View | Annotate | Download (5.9 kB)

1 8b3f1f42 Michele Tartara
#!/bin/bash
2 8b3f1f42 Michele Tartara
#Configuration
3 d1068153 Michele Tartara
: ${ARCH:=amd64}
4 d1068153 Michele Tartara
: ${DIST_RELEASE:=squeeze}
5 8b3f1f42 Michele Tartara
: ${CONF_DIR:=/etc/schroot/chroot.d}
6 8b3f1f42 Michele Tartara
: ${CHROOT_DIR:=/srv/chroot}
7 35133aae Michele Tartara
: ${ALTERNATIVE_EDITOR:=/usr/bin/vim.basic}
8 6676f007 Klaus Aehlig
: ${CHROOT_FINAL_HOOK:=/bin/true}
9 6676f007 Klaus Aehlig
# Additional Variables taken from the environmen
10 6676f007 Klaus Aehlig
# DATA_DIR
11 e2bbdded Michele Tartara
# CHROOT_EXTRA_DEBIAN_PACKAGES
12 8b3f1f42 Michele Tartara
13 8b3f1f42 Michele Tartara
#Automatically generated variables
14 8b3f1f42 Michele Tartara
CHROOTNAME=$DIST_RELEASE-$ARCH
15 8b3f1f42 Michele Tartara
CHNAME=building_$CHROOTNAME
16 8b3f1f42 Michele Tartara
TEMP_CHROOT_CONF=$CONF_DIR/$CHNAME.conf
17 8b3f1f42 Michele Tartara
FINAL_CHROOT_CONF=$CHROOTNAME.conf
18 8b3f1f42 Michele Tartara
ROOT=`pwd`
19 8b3f1f42 Michele Tartara
CHDIR=$ROOT/$CHNAME
20 8b3f1f42 Michele Tartara
USER=`whoami`
21 8b3f1f42 Michele Tartara
COMP_FILENAME=$CHROOTNAME.tar.gz
22 8b3f1f42 Michele Tartara
COMP_FILEPATH=$ROOT/$COMP_FILENAME
23 d1068153 Michele Tartara
TEMP_DATA_DIR=`mktemp -d`
24 d1068153 Michele Tartara
ACTUAL_DATA_DIR=$DATA_DIR
25 d1068153 Michele Tartara
ACTUAL_DATA_DIR=${ACTUAL_DATA_DIR:-$TEMP_DATA_DIR}
26 8b3f1f42 Michele Tartara
27 8b3f1f42 Michele Tartara
#Runnability checks
28 8b3f1f42 Michele Tartara
if [ $USER != 'root' ]
29 8b3f1f42 Michele Tartara
then
30 8b3f1f42 Michele Tartara
  echo "This script requires root permissions to run"
31 8b3f1f42 Michele Tartara
  exit
32 8b3f1f42 Michele Tartara
fi
33 8b3f1f42 Michele Tartara
34 8b3f1f42 Michele Tartara
if [ -f $TEMP_CHROOT_CONF ]
35 8b3f1f42 Michele Tartara
then
36 8b3f1f42 Michele Tartara
  echo "The configuration file name for the temporary chroot"
37 8b3f1f42 Michele Tartara
  echo "  $TEMP_CHROOT_CONF"
38 8b3f1f42 Michele Tartara
  echo "already exists."
39 8b3f1f42 Michele Tartara
  echo "Remove it or change the CHNAME value in the script."
40 8b3f1f42 Michele Tartara
  exit
41 8b3f1f42 Michele Tartara
fi
42 8b3f1f42 Michele Tartara
43 d1068153 Michele Tartara
#Create configuration dir and files if they do not exist
44 d1068153 Michele Tartara
if [ ! -d $ACTUAL_DATA_DIR ]
45 85b66af5 Michele Tartara
then
46 d1068153 Michele Tartara
  mkdir $ACTUAL_DATA_DIR
47 85b66af5 Michele Tartara
  echo "The data directory"
48 d1068153 Michele Tartara
  echo "  $ACTUAL_DATA_DIR"
49 d1068153 Michele Tartara
  echo "has been created."
50 d1068153 Michele Tartara
fi
51 d1068153 Michele Tartara
52 d1068153 Michele Tartara
if [ ! -f $ACTUAL_DATA_DIR/final.schroot.conf.in ]
53 d1068153 Michele Tartara
then
54 d1068153 Michele Tartara
  cat <<END >$ACTUAL_DATA_DIR/final.schroot.conf.in
55 d1068153 Michele Tartara
[${CHROOTNAME}]
56 d1068153 Michele Tartara
description=Debian ${DIST_RELEASE} ${ARCH}
57 d1068153 Michele Tartara
groups=src
58 d1068153 Michele Tartara
source-root-groups=root
59 d1068153 Michele Tartara
type=file
60 d1068153 Michele Tartara
file=${CHROOT_DIR}/${COMP_FILENAME}
61 d1068153 Michele Tartara
END
62 d1068153 Michele Tartara
  echo "The file"
63 d1068153 Michele Tartara
  echo " $ACTUAL_DATA_DIR/final.schroot.conf.in"
64 d1068153 Michele Tartara
  echo "has been created with default configurations."
65 85b66af5 Michele Tartara
fi
66 85b66af5 Michele Tartara
67 d1068153 Michele Tartara
if [ ! -f $ACTUAL_DATA_DIR/temp.schroot.conf.in ]
68 d1068153 Michele Tartara
then
69 d1068153 Michele Tartara
  cat <<END >$ACTUAL_DATA_DIR/temp.schroot.conf.in
70 d1068153 Michele Tartara
[${CHNAME}]
71 d1068153 Michele Tartara
description=Debian ${DIST_RELEASE} ${ARCH}
72 d1068153 Michele Tartara
directory=${CHDIR}
73 d1068153 Michele Tartara
groups=src
74 d1068153 Michele Tartara
users=root
75 d1068153 Michele Tartara
type=directory
76 d1068153 Michele Tartara
END
77 d1068153 Michele Tartara
  echo "The file"
78 d1068153 Michele Tartara
  echo " $ACTUAL_DATA_DIR/temp.schroot.conf.in"
79 d1068153 Michele Tartara
  echo "has been created with default configurations."
80 85b66af5 Michele Tartara
fi
81 85b66af5 Michele Tartara
82 d1068153 Michele Tartara
#Stop on errors
83 8b3f1f42 Michele Tartara
set -e
84 8b3f1f42 Michele Tartara
85 8b3f1f42 Michele Tartara
#Cleanup
86 8b3f1f42 Michele Tartara
rm -rf $CHDIR
87 8b3f1f42 Michele Tartara
mkdir $CHDIR
88 8b3f1f42 Michele Tartara
89 8b3f1f42 Michele Tartara
#Install tools for building chroots
90 8b3f1f42 Michele Tartara
apt-get install -y schroot debootstrap
91 8b3f1f42 Michele Tartara
92 8b3f1f42 Michele Tartara
shopt -s expand_aliases
93 8b3f1f42 Michele Tartara
alias in_chroot='schroot -c $CHNAME -d / '
94 3b308f47 Michele Tartara
function subst_variables {
95 3b308f47 Michele Tartara
  sed \
96 3b308f47 Michele Tartara
    -e "s/\${ARCH}/$ARCH/" \
97 3b308f47 Michele Tartara
    -e "s*\${CHDIR}*$CHDIR*" \
98 3b308f47 Michele Tartara
    -e "s/\${CHNAME}/$CHNAME/" \
99 3b308f47 Michele Tartara
    -e "s/\${CHROOTNAME}/$CHROOTNAME/" \
100 3b308f47 Michele Tartara
    -e "s*\${CHROOT_DIR}*$CHROOT_DIR*" \
101 3b308f47 Michele Tartara
    -e "s/\${COMP_FILENAME}/$COMP_FILENAME/" \
102 3b308f47 Michele Tartara
    -e "s/\${DIST_RELEASE}/$DIST_RELEASE/" $@
103 3b308f47 Michele Tartara
}
104 8b3f1f42 Michele Tartara
105 8b3f1f42 Michele Tartara
#Generate chroot configurations
106 d1068153 Michele Tartara
cat $ACTUAL_DATA_DIR/temp.schroot.conf.in | subst_variables > $TEMP_CHROOT_CONF
107 d1068153 Michele Tartara
cat $ACTUAL_DATA_DIR/final.schroot.conf.in | subst_variables > $FINAL_CHROOT_CONF
108 8b3f1f42 Michele Tartara
109 8b3f1f42 Michele Tartara
#Install the base system
110 8b3f1f42 Michele Tartara
debootstrap --arch $ARCH $DIST_RELEASE $CHDIR
111 8b3f1f42 Michele Tartara
112 8b3f1f42 Michele Tartara
APT_INSTALL="apt-get install -y --no-install-recommends"
113 8b3f1f42 Michele Tartara
114 d8e3c5c9 Michele Tartara
echo "deb http://backports.debian.org/debian-backports" \
115 d8e3c5c9 Michele Tartara
     "$DIST_RELEASE-backports main contrib non-free" \
116 d8e3c5c9 Michele Tartara
     > $CHDIR/etc/apt/sources.list.d/backports.list
117 d8e3c5c9 Michele Tartara
118 8b3f1f42 Michele Tartara
#Install all the packages
119 8b3f1f42 Michele Tartara
in_chroot -- \
120 8b3f1f42 Michele Tartara
  apt-get update
121 8b3f1f42 Michele Tartara
122 8b3f1f42 Michele Tartara
123 e2bbdded Michele Tartara
# do not install libghc6-network-dev, since it's too old, and just
124 e2bbdded Michele Tartara
# confuses the dependencies
125 8b3f1f42 Michele Tartara
in_chroot -- \
126 e2bbdded Michele Tartara
  $APT_INSTALL \
127 e2bbdded Michele Tartara
    autoconf automake \
128 e2bbdded Michele Tartara
    ghc cabal-install \
129 e2bbdded Michele Tartara
    libghc6-curl-dev \
130 e2bbdded Michele Tartara
    libghc6-parallel-dev \
131 e2bbdded Michele Tartara
    libghc6-text-dev \
132 e2bbdded Michele Tartara
    libghc6-vector-dev \
133 e2bbdded Michele Tartara
    libpcre3-dev \
134 e2bbdded Michele Tartara
    hlint hscolour pandoc \
135 e2bbdded Michele Tartara
    graphviz socat qemu-utils \
136 e2bbdded Michele Tartara
    python-docutils \
137 e2bbdded Michele Tartara
    python-simplejson \
138 e2bbdded Michele Tartara
    python-pyparsing \
139 e2bbdded Michele Tartara
    python-pyinotify \
140 e2bbdded Michele Tartara
    python-pycurl \
141 e2bbdded Michele Tartara
    python-ipaddr \
142 e2bbdded Michele Tartara
    python-yaml \
143 e2bbdded Michele Tartara
    python-paramiko
144 8b3f1f42 Michele Tartara
145 8b3f1f42 Michele Tartara
in_chroot -- \
146 e2bbdded Michele Tartara
  $APT_INSTALL python-setuptools python-dev build-essential
147 8b3f1f42 Michele Tartara
148 8b3f1f42 Michele Tartara
in_chroot -- \
149 e2bbdded Michele Tartara
  easy_install \
150 e2bbdded Michele Tartara
    logilab-astng==0.20.1 \
151 e2bbdded Michele Tartara
    logilab-common==0.50.3 \
152 e2bbdded Michele Tartara
    mock==1.0.1 \
153 e2bbdded Michele Tartara
    pylint==0.25.1
154 8b3f1f42 Michele Tartara
155 8b3f1f42 Michele Tartara
in_chroot -- \
156 e2bbdded Michele Tartara
  easy_install \
157 e2bbdded Michele Tartara
    sphinx==1.1.3 \
158 e2bbdded Michele Tartara
    pep8==1.2 \
159 e2bbdded Michele Tartara
    coverage==3.4 \
160 e2bbdded Michele Tartara
    bitarray==0.8.0
161 8b3f1f42 Michele Tartara
162 8b3f1f42 Michele Tartara
in_chroot -- \
163 8b3f1f42 Michele Tartara
  cabal update
164 8b3f1f42 Michele Tartara
165 8b3f1f42 Michele Tartara
in_chroot -- \
166 8b3f1f42 Michele Tartara
  cabal install --global \
167 71e00202 Michele Tartara
    network==2.3 \
168 71e00202 Michele Tartara
    regex-pcre==0.94.2 \
169 74685117 Michele Tartara
    hinotify==0.3.2 \
170 71e00202 Michele Tartara
    hslogger==1.1.4 \
171 71e00202 Michele Tartara
    quickcheck==2.5.1.1 \
172 e2bbdded Michele Tartara
    attoparsec==0.10.1.1 \
173 71e00202 Michele Tartara
    crypto==4.2.4 \
174 e2bbdded Michele Tartara
    MonadCatchIO-transformers==0.2.2.0 \
175 71e00202 Michele Tartara
    mtl==2.0.1.0 \
176 71e00202 Michele Tartara
    hashable==1.1.2.0 \
177 71e00202 Michele Tartara
    case-insensitive==0.3 \
178 71e00202 Michele Tartara
    parsec==3.0.1 \
179 71e00202 Michele Tartara
    network==2.3 \
180 71e00202 Michele Tartara
    snap-server==0.8.1 \
181 e2bbdded Michele Tartara
    json==0.4.4
182 74685117 Michele Tartara
183 8b3f1f42 Michele Tartara
in_chroot -- \
184 8b3f1f42 Michele Tartara
  cabal install --global \
185 71e00202 Michele Tartara
    hunit==1.2.5.2 \
186 71e00202 Michele Tartara
    happy==1.18.10 \
187 8b3f1f42 Michele Tartara
    hlint==1.8.34 \
188 8b3f1f42 Michele Tartara
    hscolour==1.20.3 \
189 71e00202 Michele Tartara
    temporary==1.1.2.3 \
190 8b3f1f42 Michele Tartara
    test-framework==0.6.1 \
191 8b3f1f42 Michele Tartara
    test-framework-hunit==0.2.7 \
192 8b3f1f42 Michele Tartara
    test-framework-quickcheck2==0.2.12.3
193 8b3f1f42 Michele Tartara
194 8b3f1f42 Michele Tartara
in_chroot -- \
195 e2bbdded Michele Tartara
  cabal install --global cabal-file-th
196 e2bbdded Michele Tartara
197 e2bbdded Michele Tartara
in_chroot -- \
198 8b3f1f42 Michele Tartara
  cabal install --global shelltestrunner
199 8b3f1f42 Michele Tartara
200 e2bbdded Michele Tartara
#Install selected packages from backports
201 e2bbdded Michele Tartara
in_chroot -- \
202 e2bbdded Michele Tartara
  $APT_INSTALL -t squeeze-backports \
203 e2bbdded Michele Tartara
    git \
204 e2bbdded Michele Tartara
    git-email \
205 e2bbdded Michele Tartara
    vim
206 e2bbdded Michele Tartara
207 e2bbdded Michele Tartara
in_chroot -- \
208 e2bbdded Michele Tartara
  $APT_INSTALL sudo fakeroot rsync locales less
209 e2bbdded Michele Tartara
210 e2bbdded Michele Tartara
echo "en_US.UTF-8 UTF-8" >> $CHDIR/etc/locale.gen
211 e2bbdded Michele Tartara
212 e2bbdded Michele Tartara
in_chroot -- \
213 e2bbdded Michele Tartara
  locale-gen
214 e2bbdded Michele Tartara
215 e2bbdded Michele Tartara
in_chroot -- \
216 e2bbdded Michele Tartara
  $APT_INSTALL lvm2 ssh bridge-utils iproute iputils-arping \
217 e2bbdded Michele Tartara
               ndisc6 python python-pyopenssl openssl \
218 e2bbdded Michele Tartara
               python-mock \
219 e2bbdded Michele Tartara
               socat fping
220 e2bbdded Michele Tartara
221 e2bbdded Michele Tartara
in_chroot -- \
222 e2bbdded Michele Tartara
  $APT_INSTALL qemu-utils
223 e2bbdded Michele Tartara
224 e2bbdded Michele Tartara
in_chroot -- \
225 e2bbdded Michele Tartara
  easy_install affinity
226 e2bbdded Michele Tartara
227 e2bbdded Michele Tartara
#Python development tools
228 e2bbdded Michele Tartara
in_chroot -- \
229 e2bbdded Michele Tartara
  $APT_INSTALL pandoc python-epydoc
230 e2bbdded Michele Tartara
231 9839902a Michele Tartara
#Tools for creating debian packages
232 9839902a Michele Tartara
in_chroot -- \
233 e2bbdded Michele Tartara
  $APT_INSTALL debhelper quilt
234 9839902a Michele Tartara
235 6676f007 Klaus Aehlig
# extra debian packages
236 6676f007 Klaus Aehlig
237 6676f007 Klaus Aehlig
for package in $CHROOT_EXTRA_DEBIAN_PACKAGES
238 6676f007 Klaus Aehlig
do in_chroot -- \
239 6676f007 Klaus Aehlig
  $APT_INSTALL $package
240 6676f007 Klaus Aehlig
done
241 6676f007 Klaus Aehlig
242 35133aae Michele Tartara
#Set default editor
243 35133aae Michele Tartara
in_chroot -- \
244 35133aae Michele Tartara
  update-alternatives --set editor $ALTERNATIVE_EDITOR
245 35133aae Michele Tartara
246 6676f007 Klaus Aehlig
# Final user hook
247 6676f007 Klaus Aehlig
248 6676f007 Klaus Aehlig
in_chroot -- $CHROOT_FINAL_HOOK
249 6676f007 Klaus Aehlig
250 8b3f1f42 Michele Tartara
rm -f $COMP_FILEPATH
251 8b3f1f42 Michele Tartara
echo "Creating compressed schroot image..."
252 8b3f1f42 Michele Tartara
cd $CHDIR
253 8b3f1f42 Michele Tartara
tar czf $COMP_FILEPATH ./*
254 8b3f1f42 Michele Tartara
cd $ROOT
255 8b3f1f42 Michele Tartara
256 8b3f1f42 Michele Tartara
rm -rf $CHDIR
257 8b3f1f42 Michele Tartara
rm -f $TEMP_CHROOT_CONF
258 d1068153 Michele Tartara
rm -rf $TEMP_DATA_DIR
259 3be0f700 Michele Tartara
260 3be0f700 Michele Tartara
echo "Chroot created. In order to run it:"
261 3be0f700 Michele Tartara
echo " * Copy the file $FINAL_CHROOT_CONF to $CONF_DIR/$FINAL_CHROOT_CONF"
262 3be0f700 Michele Tartara
echo " * Copy the file $COMP_FILEPATH to $CHROOT_DIR/$COMP_FILENAME"
263 3be0f700 Michele Tartara
264 3be0f700 Michele Tartara
echo "Then run \"schroot -c $CHROOTNAME\""