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
43 if [ X
$1 = Xi386
]; then
50 if [ `id -u` != 0 ]; then
51 echo "You must be root to create chroots."
54 mknod
$xtmp/test-dev-null c
1 3
56 echo "Cannot create device files on $xtmp, aborting."
57 echo "Perhaps this directory is mounted with option nodev."
61 echo test > $xtmp/test-dev-null
63 echo "Cannot create device files on $xtmp, aborting."
64 echo "Perhaps this directory is mounted with option nodev."
68 rm -f $xtmp/test-dev-null
74 # set local mirror for rinse post script
75 [ -z "$MIRROR_CENTOS" ] && return
76 cat <<EOM > $xtmp/post
78 mkdir -p $xtmp/etc/yum.repos.d/orig
79 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
80 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
88 # set local mirror for rinse post script
90 [ -z "$MIRROR_SLC" ] && return
91 cat <<EOM > $xtmp/post
93 mkdir -p $xtmp/etc/yum.repos.d/orig
94 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
95 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
96 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
106 if [[ -e $cmd ]]; then
108 chroot
$xtmp "/tmp/$cmd"
113 chroot
$xtmp apt-get clean
114 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
115 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
116 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
117 > $xtmp/etc
/machine-id
123 # check if chroot works
124 echo "Installed packages in chroot:"
125 chroot
$xtmp rpm
-qa|
sort
126 echo -n "CHROOT rpm -qa: "
127 chroot
$xtmp rpm
-qa|
wc -l
129 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
130 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
131 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
132 rm -rf $xtmp/etc
/yum.repos.d
/orig
139 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
147 local domain
=$
(domainname
)
152 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
153 domainname
$domain # workaround for #613377
167 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
181 dist
=${DIST%%[0-9][0-9]}
182 local exc
="EXCLUDE_$dist"
186 if [ -n "$arch" ]; then
187 qemu-debootstrap
--arch $arch --exclude=${!exc} $dist $xtmp $mirror
188 target
="${target}_${arch^^}"
190 if [[ $DIST =~
64 ]]; then
195 debootstrap
--arch $arch --exclude=${!exc} $dist $xtmp $mirror
205 CENTOS5_32 CENTOS5_64
206 CENTOS6_32 CENTOS6_64
207 CENTOS7_32 CENTOS7_64
224 mk-basefile, create minimal base files for a Linux distritubtion
226 Copyright (C) 2011-2017 by Thomas Lange
228 Usage: mk-basefile [OPTION] ... DISTRIBUTION
230 -s Show list of supported linux distributions
231 -a Add xtattrs, acl and selinux properties to the tar file.
232 -f ARCH Build for foreign architecture ARCH.
233 -d DIR Use DIR for creating the temporary subtree structure.
234 -z Use gzip for compressing the tar file.
235 -J Use xz for compressing the tar file.
236 -k Keep the temporary subtree structure, do not remove it.
237 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
241 Usage example: mk-basefile -J STRETCH64
242 This will create a STRETCH64.tar.xz basefile.
256 while getopts ashzJd
:kf
:x
: opt
; do
258 a
) attributes
="--xattrs --selinux --acl" ;;
259 d
) export TMPDIR
=$OPTARG ;;
260 f
) export ARCH
=$OPTARG ;;
261 z
) zip="gzip -9"; ext
=tar.gz
;;
262 J
) zip="xz -8" ext
=tar.xz
;;
265 s
) prtdists
; exit 0;;
267 ?
) exit 3 ;; # error in option parsing
270 shift $
(($OPTIND - 1))
272 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
273 if [ $?
-eq 1 ]; then
274 echo "mktemp failed. Aborting."
279 target
=$1 # also the name of the output file
281 [ -z "$target" ] && usage
283 CENTOS5_32
) centos i386
5 ;;
284 CENTOS5_64
) centos amd64
5 ;;
285 CENTOS6_32
) centos i386
6 ;;
286 CENTOS6_64
) centos amd64
6 ;;
287 CENTOS7_32
) centos i386
7 ;;
288 CENTOS7_64
) centos amd64
7 ;;
289 SLC5_32
) slc i386
5 ;;
290 SLC5_64
) slc amd64
5 ;;
291 SLC6_32
) slc i386
6 ;;
292 SLC6_64
) slc amd64
6 ;;
293 SLC7_64
) slc amd64
7 ;;
295 debgeneric
$target $MIRROR_TRISQUEL ;;
297 debgeneric
$target $MIRROR_UBUNTU ;;
298 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*)
299 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
300 *) echo "Unknown distribution. Aborting."
306 if [ $cleanup -eq 1 ]; then