3 # mk-basefile, create basefiles for some distributions
5 # Thomas Lange, Uni Koeln, 2011-2017
6 # based on the Makefile implementation of Michael Goetze
8 # Usage example: mk-basefile -J STRETCH64
9 # This will create a STRETCH64.tar.xz basefile.
11 # Supported distributions (each i386/amd64):
15 # Scientific Linux Cern 5/6
17 # Packages you might want to install to use this command:
18 # debootstrap, rinse, xz-utils
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
://deb.debian.org
/debian
/
24 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
25 MIRROR_TRISQUEL
=http
://mirror.fsf.org
/trisquel
/
26 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
28 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
,tasksel
,tasksel-data
29 EXCLUDE_WHEEZY
=info
,tasksel
,tasksel-data
30 EXCLUDE_JESSIE
=info
,tasksel
,tasksel-data
31 EXCLUDE_STRETCH
=info
,tasksel
,tasksel-data
32 EXCLUDE_BUSTER
=tasksel
,tasksel-data
34 EXCLUDE_BELENOS
=dhcp3-client
,dhcp3-common
,info
35 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
36 EXCLUDE_FLIDAS
=udhcpc
,dibbler-client
,info
,tasksel
,tasksel-data
37 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
,tasksel
,tasksel-data
39 # we need aptitude in the base file, since users may want to use it for installing packages
40 INCLUDE_DEBIAN
=aptitude
46 if [ X
$1 = Xi386
]; then
53 if [ `id -u` != 0 ]; then
54 echo "You must be root to create chroots."
57 mknod
$xtmp/test-dev-null c
1 3
59 echo "Cannot create device files on $xtmp, aborting."
60 echo "Perhaps this directory is mounted with option nodev."
64 echo test > $xtmp/test-dev-null
66 echo "Cannot create device files on $xtmp, aborting."
67 echo "Perhaps this directory is mounted with option nodev."
71 rm -f $xtmp/test-dev-null
77 # set local mirror for rinse post script
78 [ -z "$MIRROR_CENTOS" ] && return
79 cat <<EOM > $xtmp/post
81 mkdir -p $xtmp/etc/yum.repos.d/orig
82 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
83 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
91 # set local mirror for rinse post script
93 [ -z "$MIRROR_SLC" ] && return
94 cat <<EOM > $xtmp/post
96 mkdir -p $xtmp/etc/yum.repos.d/orig
97 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
98 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
99 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
108 chroot
$xtmp apt-get clean
109 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
110 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
111 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
112 > $xtmp/etc
/machine-id
118 # check if chroot works
119 echo "Installed packages in chroot:"
120 chroot
$xtmp rpm
-qa|
sort
121 echo -n "CHROOT rpm -qa: "
122 chroot
$xtmp rpm
-qa|
wc -l
124 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
125 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
126 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
127 rm -rf $xtmp/etc
/yum.repos.d
/orig
134 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
142 local domain
=$
(domainname
)
147 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
148 domainname
$domain # workaround for #613377
162 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
176 dist
=${DIST%%[0-9][0-9]}
177 local exc
="EXCLUDE_$dist"
181 if [ -n "$arch" ]; then
182 qemu-debootstrap
--arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
183 target
="${target}_${arch^^}"
185 if [[ $DIST =~
64 ]]; then
190 debootstrap
--arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
200 CENTOS5_32 CENTOS5_64
201 CENTOS6_32 CENTOS6_64
202 CENTOS7_32 CENTOS7_64
219 mk-basefile, create minimal base files for a Linux distritubtion
221 Copyright (C) 2011-2017 by Thomas Lange
223 Usage: mk-basefile [OPTION] ... DISTRIBUTION
225 -s Show list of supported linux distributions
226 -a Add xtattrs, acl and selinux properties to the tar file.
227 -f ARCH Build for foreign architecture ARCH.
228 -d DIR Use DIR for creating the temporary subtree structure.
229 -z Use gzip for compressing the tar file.
230 -J Use xz for compressing the tar file.
231 -k Keep the temporary subtree structure, do not remove it.
234 Usage example: mk-basefile -J STRETCH64
235 This will create a STRETCH64.tar.xz basefile.
248 while getopts ashzJd
:kf
: opt
; do
250 a
) attributes
="--xattrs --selinux --acl" ;;
251 d
) export TMPDIR
=$OPTARG ;;
252 f
) export ARCH
=$OPTARG ;;
253 z
) zip="gzip -9"; ext
=tar.gz
;;
254 J
) zip="xz -8" ext
=tar.xz
;;
257 s
) prtdists
; exit 0;;
258 ?
) exit 3 ;; # error in option parsing
261 shift $
(($OPTIND - 1))
263 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
264 if [ $?
-eq 1 ]; then
265 echo "mktemp failed. Aborting."
270 target
=$1 # also the name of the output file
272 [ -z "$target" ] && usage
274 CENTOS5_32
) centos i386
5 ;;
275 CENTOS5_64
) centos amd64
5 ;;
276 CENTOS6_32
) centos i386
6 ;;
277 CENTOS6_64
) centos amd64
6 ;;
278 CENTOS7_32
) centos i386
7 ;;
279 CENTOS7_64
) centos amd64
7 ;;
280 SLC5_32
) slc i386
5 ;;
281 SLC5_64
) slc amd64
5 ;;
282 SLC6_32
) slc i386
6 ;;
283 SLC6_64
) slc amd64
6 ;;
284 SLC7_64
) slc amd64
7 ;;
286 debgeneric
$target $MIRROR_TRISQUEL ;;
288 debgeneric
$target $MIRROR_UBUNTU ;;
289 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*)
290 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
291 *) echo "Unknown distribution. Aborting."
297 if [ $cleanup -eq 1 ]; then