b81965fc2a01697fea48d3b82ba9a76757b52833
2 # mk-basefile, create basefiles for some distributions
4 # Thomas Lange, Uni Koeln, 2011-2021
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
37 EXCLUDE_BELENOS
=dhcp3-client
,dhcp3-common
,info
38 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
39 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
40 EXCLUDE_FLIDAS
=udhcpc
,dibbler-client
,info
41 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
42 EXCLUDE_ETIONA
=udhcpc
,dibbler-client
,info
43 EXCLUDE_FOCAL
=udhcpc
,dibbler-client
,info
44 EXCLUDE_NABIA
=udhcpc
,dibbler-client
,info
48 # here you can add packages, that are needed very early
50 INCLUDE_ETIONA
=ifupdown
51 INCLUDE_NABIA
=ifupdown
52 INCLUDE_ARAMO
=ifupdown
57 if [ X
$1 = Xi386
]; then
64 if [ $
(id
-u) != 0 ]; then
65 echo "You must be root to create chroots."
68 mknod
$xtmp/test-dev-null c
1 3
70 echo "Cannot create device files on $xtmp, aborting."
71 echo "Perhaps this directory is mounted with option nodev."
75 echo test > $xtmp/test-dev-null
77 echo "Cannot create device files on $xtmp, aborting."
78 echo "Perhaps this directory is mounted with option nodev."
82 rm -f $xtmp/test-dev-null
88 # set local mirror for rinse post script
89 [ -z "$MIRROR_CENTOS" ] && return
90 cat <<EOM > $xtmp/post
92 mkdir -p $xtmp/etc/yum.repos.d/orig
93 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
94 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
102 # set local mirror for rinse post script
104 [ -z "$MIRROR_SLC" ] && return
105 cat <<EOM > $xtmp/post
107 mkdir -p $xtmp/etc/yum.repos.d/orig
108 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
109 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
110 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
120 if [[ -e $cmd ]]; then
122 chroot
$xtmp "/tmp/$cmd"
127 chroot
$xtmp apt-get clean
128 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
129 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
130 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
131 > $xtmp/etc
/machine-id
137 # check if chroot works
138 echo "Installed packages in chroot:"
139 chroot
$xtmp rpm
-qa|
sort
140 echo -n "CHROOT rpm -qa: "
141 chroot
$xtmp rpm
-qa|
wc -l
143 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
144 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
145 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
146 rm -rf $xtmp/etc
/yum.repos.d
/orig
153 tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
161 local domain
=$
(domainname
)
166 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
167 domainname
$domain # workaround for #613377
181 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
195 dist
=${DIST%%[0-9][0-9]}
196 local exc
="EXCLUDE_$dist"
197 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
198 local inc
="INCLUDE_$dist"
199 [ -n "${!inc}" ] && inc
="--include=${!inc}" ||
unset inc
204 if [ -n "$arch" ]; then
205 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
206 target
="${target}_${arch^^}"
208 if [[ $DIST =~
64 ]]; then
213 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
223 CENTOS5_32 CENTOS5_64
224 CENTOS6_32 CENTOS6_64
225 CENTOS7_32 CENTOS7_64
244 BULLSEYE32 BULLSEYE64
245 BOOKWORM32 BOOKWORM64
254 mk-basefile, create minimal base files for a Linux distritubtion
256 Copyright (C) 2011-2020 by Thomas Lange
258 Usage: mk-basefile [OPTION] ... DISTRIBUTION
260 -s Show list of supported linux distributions
261 -f ARCH Build for foreign architecture ARCH.
262 -d DIR Use DIR for creating the temporary subtree structure.
263 -z Use gzip for compressing the tar file.
264 -J Use xz for compressing the tar file.
265 -k Keep the temporary subtree structure, do not remove it.
266 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
270 Usage example: mk-basefile -J STRETCH64
271 This will create a STRETCH64.tar.xz basefile.
283 attributes
="--xattrs --selinux --acls"
285 while getopts ashzJd
:kf
:x
: opt
; do
287 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
288 d
) export TMPDIR
=$OPTARG ;;
289 f
) export ARCH
=$OPTARG ;;
290 z
) zip="gzip -9"; ext
=tar.gz
;;
291 J
) zip="xz -8" ext
=tar.xz
;;
294 s
) prtdists
; exit 0;;
296 ?
) exit 3 ;; # error in option parsing
299 shift $
((OPTIND
- 1))
301 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
302 if [ $?
-eq 1 ]; then
303 echo "mktemp failed. Aborting."
308 target
=$1 # also the name of the output file
310 [ -z "$target" ] && usage
312 CENTOS5_32
) centos i386
5 ;;
313 CENTOS5_64
) centos amd64
5 ;;
314 CENTOS6_32
) centos i386
6 ;;
315 CENTOS6_64
) centos amd64
6 ;;
316 CENTOS7_32
) centos i386
7 ;;
317 CENTOS7_64
) centos amd64
7 ;;
318 CENTOS8_64
) centos amd64
8 ;;
319 SLC5_32
) slc i386
5 ;;
320 SLC5_64
) slc amd64
5 ;;
321 SLC6_32
) slc i386
6 ;;
322 SLC6_64
) slc amd64
6 ;;
323 SLC7_64
) slc amd64
7 ;;
324 BELENOS
*|FLIDAS
*|ETIONA
*|NABIA
*|ARAMO
*)
325 debgeneric
$target $MIRROR_TRISQUEL ;;
326 TRUSTY
*|XENIAL
*|BIONIC
*|FOCAL
*|JAMMY
*)
327 debgeneric
$target $MIRROR_UBUNTU ;;
328 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|BULLSEYE
*|BOOKWORM
*|TRIXIE
*|SID
*)
329 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
330 *) echo "Unknown distribution. Aborting."
336 if [ $cleanup -eq 1 ]; then