152392d5b17c0bc1a59703736627168a6699c361
3 # mk-basefile, create basefiles for some distributions
5 # Thomas Lange, Uni Koeln, 2011-2018
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
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
42 # here you can add packages, that are needed very early
49 if [ X
$1 = Xi386
]; then
56 if [ `id -u` != 0 ]; then
57 echo "You must be root to create chroots."
60 mknod
$xtmp/test-dev-null c
1 3
62 echo "Cannot create device files on $xtmp, aborting."
63 echo "Perhaps this directory is mounted with option nodev."
67 echo test > $xtmp/test-dev-null
69 echo "Cannot create device files on $xtmp, aborting."
70 echo "Perhaps this directory is mounted with option nodev."
74 rm -f $xtmp/test-dev-null
80 # set local mirror for rinse post script
81 [ -z "$MIRROR_CENTOS" ] && return
82 cat <<EOM > $xtmp/post
84 mkdir -p $xtmp/etc/yum.repos.d/orig
85 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
86 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
94 # set local mirror for rinse post script
96 [ -z "$MIRROR_SLC" ] && return
97 cat <<EOM > $xtmp/post
99 mkdir -p $xtmp/etc/yum.repos.d/orig
100 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
101 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
102 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
112 if [[ -e $cmd ]]; then
114 chroot
$xtmp "/tmp/$cmd"
119 chroot
$xtmp apt-get clean
120 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
121 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
122 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
123 > $xtmp/etc
/machine-id
129 # check if chroot works
130 echo "Installed packages in chroot:"
131 chroot
$xtmp rpm
-qa|
sort
132 echo -n "CHROOT rpm -qa: "
133 chroot
$xtmp rpm
-qa|
wc -l
135 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
136 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
137 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
138 rm -rf $xtmp/etc
/yum.repos.d
/orig
145 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
153 local domain
=$
(domainname
)
158 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
159 domainname
$domain # workaround for #613377
173 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
187 dist
=${DIST%%[0-9][0-9]}
188 local exc
="EXCLUDE_$dist"
189 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
193 if [ -n "$INCLUDE_DEBIAN" ]; then
194 local inc
="--include=$INCLUDE_DEBIAN"
197 if [ -n "$arch" ]; then
198 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
199 target
="${target}_${arch^^}"
201 if [[ $DIST =~
64 ]]; then
206 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
216 CENTOS5_32 CENTOS5_64
217 CENTOS6_32 CENTOS6_64
218 CENTOS7_32 CENTOS7_64
239 mk-basefile, create minimal base files for a Linux distritubtion
241 Copyright (C) 2011-2018 by Thomas Lange
243 Usage: mk-basefile [OPTION] ... DISTRIBUTION
245 -s Show list of supported linux distributions
246 -f ARCH Build for foreign architecture ARCH.
247 -d DIR Use DIR for creating the temporary subtree structure.
248 -z Use gzip for compressing the tar file.
249 -J Use xz for compressing the tar file.
250 -k Keep the temporary subtree structure, do not remove it.
251 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
255 Usage example: mk-basefile -J STRETCH64
256 This will create a STRETCH64.tar.xz basefile.
268 attributes
="--xattrs --selinux --acls"
270 while getopts ashzJd
:kf
:x
: opt
; do
272 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
273 d
) export TMPDIR
=$OPTARG ;;
274 f
) export ARCH
=$OPTARG ;;
275 z
) zip="gzip -9"; ext
=tar.gz
;;
276 J
) zip="xz -8" ext
=tar.xz
;;
279 s
) prtdists
; exit 0;;
281 ?
) exit 3 ;; # error in option parsing
284 shift $
(($OPTIND - 1))
286 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
287 if [ $?
-eq 1 ]; then
288 echo "mktemp failed. Aborting."
293 target
=$1 # also the name of the output file
295 [ -z "$target" ] && usage
297 CENTOS5_32
) centos i386
5 ;;
298 CENTOS5_64
) centos amd64
5 ;;
299 CENTOS6_32
) centos i386
6 ;;
300 CENTOS6_64
) centos amd64
6 ;;
301 CENTOS7_32
) centos i386
7 ;;
302 CENTOS7_64
) centos amd64
7 ;;
303 SLC5_32
) slc i386
5 ;;
304 SLC5_64
) slc amd64
5 ;;
305 SLC6_32
) slc i386
6 ;;
306 SLC6_64
) slc amd64
6 ;;
307 SLC7_64
) slc amd64
7 ;;
308 BELENOS
*|FLIDAS
*|ETIONA
*)
309 debgeneric
$target $MIRROR_TRISQUEL ;;
310 TRUSTY
*|XENIAL
*|BIONIC
*)
311 debgeneric
$target $MIRROR_UBUNTU ;;
312 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|SID
*)
313 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
314 *) echo "Unknown distribution. Aborting."
320 if [ $cleanup -eq 1 ]; then