/[fai]/trunk/examples/simple/basefiles/mk-basefile
ViewVC logotype

Contents of /trunk/examples/simple/basefiles/mk-basefile

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6656 - (show annotations) (download)
Thu Sep 8 00:27:49 2011 UTC (20 months, 1 week ago) by lange
File size: 4785 byte(s)
fix syntax error
1 #! /bin/bash
2
3 # mk-basefile, create basefiles for some distributions
4 #
5 # Thomas Lange, Uni Koeln, 2011
6 # based on the Makefile implementation of Michael Goetze
7 #
8 # Usage example: fai-mk-basefile -J SQUEEZE64
9 # This will create a SQUEEZE64.tar.xz basefile.
10
11 # Supported distributions (each i386/amd64):
12 # Debian GNU/Linux 6.0
13 # Ubuntu 10.04
14 # CentOS 5/6
15 # Scientific Linux Cern 5/6
16 #
17 # Packages you might want to install to use this command:
18 # debootstrap, rinse, xz-utils
19
20
21 xtmp=$(mktemp -d /tmp/basefiles.XXXXXXXX)
22 if [ $? -eq 1 ]; then
23 echo "mktemp failed. Aborting."
24 exit 2
25 fi
26
27 # Define your local mirros here
28 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
29 MIRROR_DEBIAN=http://cdn.debian.net/debian/
30 MIRROR_DEBIAN=http://kueppers/debian/
31 MIRROR_UBUNTU=http://ftp.halifax.rwth-aachen.de/ubuntu/
32 MIRROR_CENTOS=http://mirror.netcologne.de/
33 #MIRROR_CENTOS=http://kueppers
34 #MIRROR_SLC=http://kueppers
35
36 EXCLUDE_SQUEEZE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
37 EXCLUDE_LUCID=dhcp3-client,dhcp3-common
38
39
40
41 setarch() {
42
43 l32=
44 if [ X$1 = Xi386 ]; then
45 l32=linux32
46 fi
47 }
48
49 check() {
50
51 if [ `id -u` != 0 ]; then
52 echo "You must be root to create chroots."
53 exit 1
54 fi
55 mknod $xtmp/test-dev-null c 1 3
56 if [ $? -eq 1 ]; then
57 echo "Cannot create device files on $xtmp, aborting."
58 rm -rf $xtmp
59 exit 1
60 fi
61 echo test > $xtmp/test-dev-null
62 if [ $? -eq 1 ]; then
63 echo "Cannot use device files on $xtmp, aborting."
64 rm -rf $xtmp
65 exit 1
66 fi
67 rm -f $xtmp/test-dev-null
68 }
69
70
71 mkpost-centos() {
72
73 [ -z "$MIRROR_CENTOS" ] && return
74 cat <<EOM > $xtmp/post
75 #! /bin/sh
76 mkdir -p $xtmp/etc/yum.repos.d/orig
77 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
78 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
79 EOM
80 chmod 555 $xtmp/post
81 }
82
83
84 mkpost-slc() {
85
86 ver=$1
87 [ -z "$MIRROR_SLC" ] && return
88 cat <<EOM > $xtmp/post
89 #! /bin/sh
90 mkdir -p $xtmp/etc/yum.repos.d/orig
91 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
92 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
93 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
94
95 EOM
96 chmod 555 $xtmp/post
97 }
98
99
100 cleanup-deb() {
101
102 chroot $xtmp aptitude clean
103 rm $xtmp/etc/hostname $xtmp/etc/resolv.conf
104 rm $xtmp/var/lib/apt/lists/*_*
105 rm -f $xtmp/etc/udev/rules.d/70-persistent-net.rules
106 }
107
108
109 cleanup-rinse() {
110
111 # check if chroot works
112 echo "Installed packages in chroot:"
113 chroot $xtmp rpm -qa
114 echo -n "CHROOT rpm -qa: "
115 chroot $xtmp rpm -qa|wc -l
116
117 rm -f $xtmp/etc/resolv.conf $xtmp/post
118 if [ -d $xtmp/etc/yum.repos.d/orig ]; then
119 mv $xtmp/etc/yum.repos.d/orig/* $xtmp/etc/yum.repos.d/
120 rm -rf $xtmp/etc/yum.repos.d/orig
121 fi
122 }
123
124
125 tarit() {
126
127 tar --one-file-system -C $xtmp -cf - . | $zip > $target.$ext
128 }
129
130
131 centos() {
132
133 local arch=$1
134 local vers=$2
135 local domain=$(domainname)
136
137 check
138 setarch $arch
139 mkpost-centos
140 $l32 rinse --directory $xtmp --distribution centos-$vers --arch $arch --before-post-install $xtmp/post
141 domainname $domain # workaround for #613377
142 cleanup-rinse
143 tarit
144 }
145
146
147 slc() {
148
149 local arch=$1
150 local vers=$2
151
152 check
153 setarch $arch
154 mkpost-slc $vers
155 $l32 rinse --directory $xtmp --distribution slc-$vers --arch $arch --before-post-install $xtmp/post
156 cleanup-rinse
157 tarit
158 }
159
160
161 squeeze() {
162
163 local arch=$1
164
165 check
166 debootstrap --arch $arch --exclude=${EXCLUDE_SQUEEZE} squeeze $xtmp ${MIRROR_DEBIAN}
167 cleanup-deb
168 tarit
169 }
170
171 lucid() {
172
173 local arch=$1
174
175 check
176 debootstrap --arch $arch --exclude=${EXCLUDE_LUCID} lucid $xtmp ${MIRROR_UBUNTU}
177 cleanup-deb
178 tarit
179 }
180
181
182 unknown() {
183
184 echo "Unknown distribution. Aborting."
185 echo "Available:
186
187 CENTOS5_32 CENTOS5_64
188 CENTOS6_32 CENTOS6_64
189 SLC5_32 SLC5_64
190 SLC6_32 SLC6_64
191 LUCID32 LUCID64
192 SQUEEZE32 SQUEEZE64
193 "
194 exit 99
195 }
196
197
198 # main routine
199
200 ext=tar
201 zip=cat
202
203 while getopts zJ opt ; do
204 case "$opt" in
205 z) zip="gzip -9"; ext=tar.gz ;;
206 J) zip="xz -8" ext=tar.xz ;;
207 esac
208 done
209 shift $(($OPTIND - 1))
210
211
212 target=$1 # also the name of the output file
213
214 case "$target" in
215 CENTOS5_32) centos i386 5 ;;
216 CENTOS5_64) centos amd64 5 ;;
217 CENTOS6_32) centos i386 6 ;;
218 CENTOS6_64) centos amd64 6 ;;
219 SLC5_32) slc i386 5 ;;
220 SLC5_64) slc amd64 5 ;;
221 SLC6_32) slc i386 6 ;;
222 SLC6_64) slc amd64 6 ;;
223 LUCID32) lucid i386 ;;
224 LUCID64) lucid amd64 ;;
225 SQUEEZE32) squeeze i386 ;;
226 SQUEEZE64) squeeze amd64 ;;
227 *) unknown ;;
228 esac
229
230 # cleanup
231 rm -rf $xtmp

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5