2 # mk-basefile, create basefiles for some distributions
4 # Thomas Lange, Uni Koeln, 2011-2017
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
,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_BELENOS
=dhcp3-client
,dhcp3-common
,info
34 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
35 EXCLUDE_FLIDAS
=udhcpc
,dibbler-client
,info
,tasksel
,tasksel-data
36 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
,tasksel
,tasksel-data
42 if [ X
$1 = Xi386
]; then
49 if [ `id -u` != 0 ]; then
50 echo "You must be root to create chroots."
53 mknod
$xtmp/test-dev-null c
1 3
55 echo "Cannot create device files on $xtmp, aborting."
56 echo "Perhaps this directory is mounted with option nodev."
60 echo test > $xtmp/test-dev-null
62 echo "Cannot create device files on $xtmp, aborting."
63 echo "Perhaps this directory is mounted with option nodev."
67 rm -f $xtmp/test-dev-null
73 # set local mirror for rinse post script
74 [ -z "$MIRROR_CENTOS" ] && return
75 cat <<EOM > $xtmp/post
77 mkdir -p $xtmp/etc/yum.repos.d/orig
78 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
79 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
87 # set local mirror for rinse post script
89 [ -z "$MIRROR_SLC" ] && 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,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
95 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
105 if [[ -e $cmd ]]; then
107 chroot
$xtmp "/tmp/$cmd"
112 chroot
$xtmp apt-get clean
113 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
114 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
115 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
116 > $xtmp/etc
/machine-id
122 # check if chroot works
123 echo "Installed packages in chroot:"
124 chroot
$xtmp rpm
-qa|
sort
125 echo -n "CHROOT rpm -qa: "
126 chroot
$xtmp rpm
-qa|
wc -l
128 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
129 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
130 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
131 rm -rf $xtmp/etc
/yum.repos.d
/orig
138 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
146 local domain
=$
(domainname
)
151 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
152 domainname
$domain # workaround for #613377
166 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
180 dist
=${DIST%%[0-9][0-9]}
181 local exc
="EXCLUDE_$dist"
185 if [ -n "$arch" ]; then
186 qemu-debootstrap
--arch $arch --exclude=${!exc} $dist $xtmp $mirror
187 target
="${target}_${arch^^}"
189 if [[ $DIST =~
64 ]]; then
194 debootstrap
--arch $arch --exclude=${!exc} $dist $xtmp $mirror
204 CENTOS5_32 CENTOS5_64
205 CENTOS6_32 CENTOS6_64
206 CENTOS7_32 CENTOS7_64
223 mk-basefile, create minimal base files for a Linux distritubtion
225 Copyright (C) 2011-2017 by Thomas Lange
227 Usage: mk-basefile [OPTION] ... DISTRIBUTION
229 -s Show list of supported linux distributions
230 -a Add xtattrs, acl and selinux properties to the tar file.
231 -f ARCH Build for foreign architecture ARCH.
232 -d DIR Use DIR for creating the temporary subtree structure.
233 -z Use gzip for compressing the tar file.
234 -J Use xz for compressing the tar file.
235 -k Keep the temporary subtree structure, do not remove it.
236 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
240 Usage example: mk-basefile -J STRETCH64
241 This will create a STRETCH64.tar.xz basefile.
255 while getopts ashzJd
:kf
:x
: opt
; do
257 a
) attributes
="--xattrs --selinux --acl" ;;
258 d
) export TMPDIR
=$OPTARG ;;
259 f
) export ARCH
=$OPTARG ;;
260 z
) zip="gzip -9"; ext
=tar.gz
;;
261 J
) zip="xz -8" ext
=tar.xz
;;
264 s
) prtdists
; exit 0;;
266 ?
) exit 3 ;; # error in option parsing
269 shift $
(($OPTIND - 1))
271 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
272 if [ $?
-eq 1 ]; then
273 echo "mktemp failed. Aborting."
278 target
=$1 # also the name of the output file
280 [ -z "$target" ] && usage
282 CENTOS5_32
) centos i386
5 ;;
283 CENTOS5_64
) centos amd64
5 ;;
284 CENTOS6_32
) centos i386
6 ;;
285 CENTOS6_64
) centos amd64
6 ;;
286 CENTOS7_32
) centos i386
7 ;;
287 CENTOS7_64
) centos amd64
7 ;;
288 SLC5_32
) slc i386
5 ;;
289 SLC5_64
) slc amd64
5 ;;
290 SLC6_32
) slc i386
6 ;;
291 SLC6_64
) slc amd64
6 ;;
292 SLC7_64
) slc amd64
7 ;;
294 debgeneric
$target $MIRROR_TRISQUEL ;;
296 debgeneric
$target $MIRROR_UBUNTU ;;
297 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*)
298 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
299 *) echo "Unknown distribution. Aborting."
305 if [ $cleanup -eq 1 ]; then