2 # mk-basefile, create basefiles for some distributions
4 # Thomas Lange, Uni Koeln, 2011-2020
5 # based on the Makefile implementation of Michael Goetze
7 # Usage example: mk-basefile -J STRETCH64
8 # This will create a STRETCH64.tar.xz basefile.
10 # Supported distributions (each i386/amd64):
14 # Scientific Linux Cern 5/6
16 # Packages you might want to install to use this command:
17 # debootstrap, rinse, xz-utils
20 # Define your local mirros here
21 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
22 MIRROR_DEBIAN
=http
://deb.debian.org
/debian
/
23 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
24 MIRROR_TRISQUEL
=http
://mirror.fsf.org
/trisquel
/
25 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
27 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
35 EXCLUDE_BELENOS
=dhcp3-client
,dhcp3-common
,info
36 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
37 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
38 EXCLUDE_FLIDAS
=udhcpc
,dibbler-client
,info
39 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
40 EXCLUDE_ETIONA
=udhcpc
,dibbler-client
,info
41 EXCLUDE_FOCAL
=udhcpc
,dibbler-client
,info
42 EXCLUDE_NABIA
=udhcpc
,dibbler-client
,info
44 # here you can add packages, that are needed very early
46 INCLUDE_ETIONA
=ifupdown
47 INCLUDE_NABIA
=ifupdown
52 if [ X
$1 = Xi386
]; then
59 if [ $
(id
-u) != 0 ]; then
60 echo "You must be root to create chroots."
63 mknod
$xtmp/test-dev-null c
1 3
65 echo "Cannot create device files on $xtmp, aborting."
66 echo "Perhaps this directory is mounted with option nodev."
70 echo test > $xtmp/test-dev-null
72 echo "Cannot create device files on $xtmp, aborting."
73 echo "Perhaps this directory is mounted with option nodev."
77 rm -f $xtmp/test-dev-null
83 # set local mirror for rinse post script
84 [ -z "$MIRROR_CENTOS" ] && return
85 cat <<EOM > $xtmp/post
87 mkdir -p $xtmp/etc/yum.repos.d/orig
88 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
89 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
97 # set local mirror for rinse post script
99 [ -z "$MIRROR_SLC" ] && return
100 cat <<EOM > $xtmp/post
102 mkdir -p $xtmp/etc/yum.repos.d/orig
103 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
104 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
105 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
115 if [[ -e $cmd ]]; then
117 chroot
$xtmp "/tmp/$cmd"
122 chroot
$xtmp apt-get clean
123 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
124 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
125 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
126 > $xtmp/etc
/machine-id
132 # check if chroot works
133 echo "Installed packages in chroot:"
134 chroot
$xtmp rpm
-qa|
sort
135 echo -n "CHROOT rpm -qa: "
136 chroot
$xtmp rpm
-qa|
wc -l
138 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
139 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
140 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
141 rm -rf $xtmp/etc
/yum.repos.d
/orig
148 tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
156 local domain
=$
(domainname
)
161 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
162 domainname
$domain # workaround for #613377
176 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
190 dist
=${DIST%%[0-9][0-9]}
191 local exc
="EXCLUDE_$dist"
192 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
193 local inc
="INCLUDE_$dist"
194 [ -n "${!inc}" ] && inc
="--include=${!inc}" ||
unset inc
199 if [ -n "$arch" ]; then
200 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
201 target
="${target}_${arch^^}"
203 if [[ $DIST =~
64 ]]; then
208 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
218 CENTOS5_32 CENTOS5_64
219 CENTOS6_32 CENTOS6_64
220 CENTOS7_32 CENTOS7_64
237 BULLSEYE32 BULLSEYE64
245 mk-basefile, create minimal base files for a Linux distritubtion
247 Copyright (C) 2011-2020 by Thomas Lange
249 Usage: mk-basefile [OPTION] ... DISTRIBUTION
251 -s Show list of supported linux distributions
252 -f ARCH Build for foreign architecture ARCH.
253 -d DIR Use DIR for creating the temporary subtree structure.
254 -z Use gzip for compressing the tar file.
255 -J Use xz for compressing the tar file.
256 -k Keep the temporary subtree structure, do not remove it.
257 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
261 Usage example: mk-basefile -J STRETCH64
262 This will create a STRETCH64.tar.xz basefile.
274 attributes
="--xattrs --selinux --acls"
276 while getopts ashzJd
:kf
:x
: opt
; do
278 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
279 d
) export TMPDIR
=$OPTARG ;;
280 f
) export ARCH
=$OPTARG ;;
281 z
) zip="gzip -9"; ext
=tar.gz
;;
282 J
) zip="xz -8" ext
=tar.xz
;;
285 s
) prtdists
; exit 0;;
287 ?
) exit 3 ;; # error in option parsing
290 shift $
((OPTIND
- 1))
292 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
293 if [ $?
-eq 1 ]; then
294 echo "mktemp failed. Aborting."
299 target
=$1 # also the name of the output file
301 [ -z "$target" ] && usage
303 CENTOS5_32
) centos i386
5 ;;
304 CENTOS5_64
) centos amd64
5 ;;
305 CENTOS6_32
) centos i386
6 ;;
306 CENTOS6_64
) centos amd64
6 ;;
307 CENTOS7_32
) centos i386
7 ;;
308 CENTOS7_64
) centos amd64
7 ;;
309 CENTOS8_64
) centos amd64
8 ;;
310 SLC5_32
) slc i386
5 ;;
311 SLC5_64
) slc amd64
5 ;;
312 SLC6_32
) slc i386
6 ;;
313 SLC6_64
) slc amd64
6 ;;
314 SLC7_64
) slc amd64
7 ;;
315 BELENOS
*|FLIDAS
*|ETIONA
*|NABIA
*)
316 debgeneric
$target $MIRROR_TRISQUEL ;;
317 TRUSTY
*|XENIAL
*|BIONIC
*|FOCAL
*)
318 debgeneric
$target $MIRROR_UBUNTU ;;
319 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|BULLSEYE
*|SID
*)
320 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
321 *) echo "Unknown distribution. Aborting."
327 if [ $cleanup -eq 1 ]; then