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_CENTOS
=http
://mirror.netcologne.de
/
27 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
,tasksel
,tasksel-data
28 EXCLUDE_WHEEZY
=info
,tasksel
,tasksel-data
29 EXCLUDE_JESSIE
=info
,tasksel
,tasksel-data
30 EXCLUDE_STRETCH
=info
,tasksel
,tasksel-data
31 EXCLUDE_BUSTER
=tasksel
,tasksel-data
33 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
34 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
,tasksel
,tasksel-data
36 # we need aptitude in the base file, since users may want to use it for installing packages
37 INCLUDE_DEBIAN
=aptitude
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
105 chroot
$xtmp apt-get clean
106 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
107 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
108 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
109 > $xtmp/etc
/machine-id
115 # check if chroot works
116 echo "Installed packages in chroot:"
117 chroot
$xtmp rpm
-qa|
sort
118 echo -n "CHROOT rpm -qa: "
119 chroot
$xtmp rpm
-qa|
wc -l
121 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
122 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
123 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
124 rm -rf $xtmp/etc
/yum.repos.d
/orig
131 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
139 local domain
=$
(domainname
)
144 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
145 domainname
$domain # workaround for #613377
159 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
173 dist
=${DIST%%[0-9][0-9]}
174 local exc
="EXCLUDE_$dist"
178 if [ -n "$arch" ]; then
179 qemu-debootstrap
--arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
180 target
="${target}_${arch^^}"
182 if [[ $DIST =~
64 ]]; then
187 debootstrap
--arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
197 CENTOS5_32 CENTOS5_64
198 CENTOS6_32 CENTOS6_64
199 CENTOS7_32 CENTOS7_64
216 mk-basefile, create minimal base files for a Linux distritubtion
218 Copyright (C) 2011-2017 by Thomas Lange
220 Usage: mk-basefile [OPTION] ... DISTRIBUTION
222 -s Show list of supported linux distributions
223 -a Add xtattrs, acl and selinux properties to the tar file.
224 -f ARCH Build for foreign architecture ARCH.
225 -d DIR Use DIR for creating the temporary subtree structure.
226 -z Use gzip for compressing the tar file.
227 -J Use xz for compressing the tar file.
228 -k Keep the temporary subtree structure, do not remove it.
231 Usage example: mk-basefile -J STRETCH64
232 This will create a STRETCH64.tar.xz basefile.
245 while getopts ashzJd
:kf
: opt
; do
247 a
) attributes
="--xattrs --selinux --acl" ;;
248 d
) export TMPDIR
=$OPTARG ;;
249 f
) export ARCH
=$OPTARG ;;
250 z
) zip="gzip -9"; ext
=tar.gz
;;
251 J
) zip="xz -8" ext
=tar.xz
;;
254 s
) prtdists
; exit 0;;
255 ?
) exit 3 ;; # error in option parsing
258 shift $
(($OPTIND - 1))
260 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
261 if [ $?
-eq 1 ]; then
262 echo "mktemp failed. Aborting."
267 target
=$1 # also the name of the output file
269 [ -z "$target" ] && usage
271 CENTOS5_32
) centos i386
5 ;;
272 CENTOS5_64
) centos amd64
5 ;;
273 CENTOS6_32
) centos i386
6 ;;
274 CENTOS6_64
) centos amd64
6 ;;
275 CENTOS7_32
) centos i386
7 ;;
276 CENTOS7_64
) centos amd64
7 ;;
277 SLC5_32
) slc i386
5 ;;
278 SLC5_64
) slc amd64
5 ;;
279 SLC6_32
) slc i386
6 ;;
280 SLC6_64
) slc amd64
6 ;;
281 SLC7_64
) slc amd64
7 ;;
283 debgeneric
$target $MIRROR_UBUNTU ;;
284 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*)
285 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
286 *) echo "Unknown distribution. Aborting."
292 if [ $cleanup -eq 1 ]; then