upstream 5.1 sample config
[automated-distro-installer] / fai / config / basefiles / mk-basefile
1 #! /bin/bash
2
3 # mk-basefile, create basefiles for some distributions
4 #
5 # Thomas Lange, Uni Koeln, 2011-2015
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
13 # Ubuntu 14.04
14 # CentOS 5/6/7
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 # Define your local mirros here
22 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
23 MIRROR_DEBIAN=http://httpredir.debian.org/debian/
24 MIRROR_DEBIAN=http://localmirror/debian/
25 MIRROR_UBUNTU=http://mirror.netcologne.de/ubuntu/
26 MIRROR_CENTOS=http://mirror.netcologne.de/
27 #MIRROR_CENTOS=http://localmirror
28 #MIRROR_SLC=http://localmirror
29
30 EXCLUDE_SQUEEZE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
31 EXCLUDE_WHEEZY=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
32 EXCLUDE_JESSIE=isc-dhcp-client,isc-dhcp-common,info,tasksel,tasksel-data
33 EXCLUDE_TRUSTY=dhcp3-client,dhcp3-common,info
34
35 INCLUDE_DEBIAN=aptitude
36
37
38 setarch() {
39
40 l32=
41 if [ X$1 = Xi386 ]; then
42 l32=linux32
43 fi
44 }
45
46 check() {
47
48 if [ `id -u` != 0 ]; then
49 echo "You must be root to create chroots."
50 exit 1
51 fi
52 mknod $xtmp/test-dev-null c 1 3
53 if [ $? -eq 1 ]; then
54 echo "Cannot create device files on $xtmp, aborting."
55 echo "Perhaps this directory is mounted with option nodev."
56 rm -rf $xtmp
57 exit 1
58 fi
59 echo test > $xtmp/test-dev-null
60 if [ $? -eq 1 ]; then
61 echo "Cannot create device files on $xtmp, aborting."
62 echo "Perhaps this directory is mounted with option nodev."
63 rm -rf $xtmp
64 exit 1
65 fi
66 rm -f $xtmp/test-dev-null
67 }
68
69
70 mkpost-centos() {
71
72 [ -z "$MIRROR_CENTOS" ] && return
73 cat <<EOM > $xtmp/post
74 #! /bin/sh
75 mkdir -p $xtmp/etc/yum.repos.d/orig
76 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
77 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
78 EOM
79 chmod 555 $xtmp/post
80 }
81
82
83 mkpost-slc() {
84
85 ver=$1
86 [ -z "$MIRROR_SLC" ] && return
87 cat <<EOM > $xtmp/post
88 #! /bin/sh
89 mkdir -p $xtmp/etc/yum.repos.d/orig
90 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
91 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
92 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
93
94 EOM
95 chmod 555 $xtmp/post
96 }
97
98
99 cleanup-deb() {
100
101 chroot $xtmp aptitude clean
102 rm -f $xtmp/etc/hostname $xtmp/etc/resolv.conf $xtmp/etc/machine-id
103 rm $xtmp/var/lib/apt/lists/*_*
104 rm -f $xtmp/etc/udev/rules.d/70-persistent-net.rules
105 }
106
107
108 cleanup-rinse() {
109
110 # check if chroot works
111 echo "Installed packages in chroot:"
112 chroot $xtmp rpm -qa|sort
113 echo -n "CHROOT rpm -qa: "
114 chroot $xtmp rpm -qa|wc -l
115
116 rm -f $xtmp/etc/resolv.conf $xtmp/post
117 if [ -d $xtmp/etc/yum.repos.d/orig ]; then
118 mv $xtmp/etc/yum.repos.d/orig/* $xtmp/etc/yum.repos.d/
119 rm -rf $xtmp/etc/yum.repos.d/orig
120 fi
121 }
122
123
124 tarit() {
125
126 tar --xattrs --selinux --acl --one-file-system -C $xtmp -cf - . | $zip > $target.$ext
127 }
128
129
130 centos() {
131
132 local arch=$1
133 local vers=$2
134 local domain=$(domainname)
135
136 check
137 setarch $arch
138 mkpost-centos
139 $l32 rinse --directory $xtmp --distribution centos-$vers --arch $arch --before-post-install $xtmp/post
140 domainname $domain # workaround for #613377
141 cleanup-rinse
142 tarit
143 }
144
145
146 slc() {
147
148 local arch=$1
149 local vers=$2
150
151 check
152 setarch $arch
153 mkpost-slc $vers
154 $l32 rinse --directory $xtmp --distribution slc-$vers --arch $arch --before-post-install $xtmp/post
155 cleanup-rinse
156 tarit
157 }
158
159
160 squeeze() {
161
162 local arch=$1
163
164 check
165 debootstrap --arch $arch --exclude=${EXCLUDE_SQUEEZE} squeeze $xtmp ${MIRROR_DEBIAN}
166 cleanup-deb
167 tarit
168 }
169
170 wheezy() {
171
172 local arch=$1
173
174 check
175 debootstrap --arch $arch --exclude=${EXCLUDE_WHEEZY} wheezy $xtmp ${MIRROR_DEBIAN}
176 cleanup-deb
177 tarit
178 }
179
180 jessie() {
181
182 local arch=$1
183
184 check
185 debootstrap --arch $arch --exclude=${EXCLUDE_JESSIE} --include=${INCLUDE_DEBIAN} jessie $xtmp ${MIRROR_DEBIAN}
186 cleanup-deb
187 tarit
188 }
189
190 trusty() {
191
192 local arch=$1
193
194 check
195 debootstrap --arch $arch --exclude=${EXCLUDE_TRUSTY} --include=${INCLUDE_DEBIAN} trusty $xtmp ${MIRROR_UBUNTU}
196 cleanup-deb
197 tarit
198 }
199
200
201 unknown() {
202
203 echo "Unknown distribution. Aborting."
204 echo "Available:
205
206 CENTOS5_32 CENTOS5_64
207 CENTOS6_32 CENTOS6_64
208 CENTOS7_32 CENTOS7_64
209 SLC5_32 SLC5_64
210 SLC6_32 SLC6_64
211 TRUSTY32 TRUSTY64
212 SQUEEZE32 SQUEEZE64
213 WHEEZY32 WHEEZY64
214 JESSIE32 JESSIE64
215 "
216 exit 99
217 }
218
219
220 # main routine
221
222 ext=tar
223 zip=cat
224 tmpdir=/var/tmp
225
226 while getopts zJd: opt ; do
227 case "$opt" in
228 d) tmpdir=$OPTARG ;;
229 z) zip="gzip -9"; ext=tar.gz ;;
230 J) zip="xz -8" ext=tar.xz ;;
231 esac
232 done
233 shift $(($OPTIND - 1))
234
235 xtmp=$(mktemp -d $tmpdir/basefiles.XXXXXXXX)
236 if [ $? -eq 1 ]; then
237 echo "mktemp failed. Aborting."
238 exit 2
239 fi
240
241 target=$1 # also the name of the output file
242
243 case "$target" in
244 CENTOS5_32) centos i386 5 ;;
245 CENTOS5_64) centos amd64 5 ;;
246 CENTOS6_32) centos i386 6 ;;
247 CENTOS6_64) centos amd64 6 ;;
248 CENTOS7_32) centos i386 7 ;;
249 CENTOS7_64) centos amd64 7 ;;
250 SLC5_32) slc i386 5 ;;
251 SLC5_64) slc amd64 5 ;;
252 SLC6_32) slc i386 6 ;;
253 SLC6_64) slc amd64 6 ;;
254 TRUSTY32) trusty i386 ;;
255 TRUSTY64) trusty amd64 ;;
256 SQUEEZE32) squeeze i386 ;;
257 SQUEEZE64) squeeze amd64 ;;
258 WHEEZY32) wheezy i386 ;;
259 WHEEZY64) wheezy amd64 ;;
260 JESSIE32) jessie i386 ;;
261 JESSIE64) jessie amd64 ;;
262 *) unknown ;;
263 esac
264
265 # cleanup
266 rm -rf $xtmp