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 # Supported distributions (each i386/amd64):
12 # Scientific Linux Cern 5/6
14 # Packages you might want to install to use this command:
15 # debootstrap, rinse, xz-utils
18 # Define your local mirros here
19 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
20 MIRROR_DEBIAN
=http
://http.us.debian.org
/debian
21 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
22 MIRROR_TRISQUEL
=http
://mirror.fsf.org
/trisquel
/
23 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
25 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
,tasksel
,tasksel-data
26 EXCLUDE_WHEEZY
=info
,tasksel
,tasksel-data
27 EXCLUDE_JESSIE
=tasksel
,tasksel-data
28 EXCLUDE_STRETCH
=tasksel
,tasksel-data
29 EXCLUDE_BELENOS
=dhcp3-client
,dhcp3-common
,info
30 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
31 EXCLUDE_FLIDAS
=tasksel
,tasksel-data
32 EXCLUDE_XENIAL
=tasksel
,tasksel-data
34 INCLUDE_DEBIAN
=aptitude
40 if [ X
$1 = Xi386
]; then
47 if [ `id -u` != 0 ]; then
48 echo "You must be root to create chroots."
51 mknod
$xtmp/test-dev-null c
1 3
53 echo "Cannot create device files on $xtmp, aborting."
54 echo "Perhaps this directory is mounted with option nodev."
58 echo test > $xtmp/test-dev-null
60 echo "Cannot create device files on $xtmp, aborting."
61 echo "Perhaps this directory is mounted with option nodev."
65 rm -f $xtmp/test-dev-null
71 [ -z "$MIRROR_CENTOS" ] && return
72 cat <<EOM > $xtmp/post
74 mkdir -p $xtmp/etc/yum.repos.d/orig
75 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
76 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
85 [ -z "$MIRROR_SLC" ] && return
86 cat <<EOM > $xtmp/post
88 mkdir -p $xtmp/etc/yum.repos.d/orig
89 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
90 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
91 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
100 chroot
$xtmp aptitude clean
101 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf
$xtmp/etc
/machine-id
102 rm $xtmp/var
/lib
/apt
/lists
/*_
*
103 rm -f $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
109 # check if chroot works
110 echo "Installed packages in chroot:"
111 chroot
$xtmp rpm
-qa|
sort
112 echo -n "CHROOT rpm -qa: "
113 chroot
$xtmp rpm
-qa|
wc -l
115 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
116 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
117 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
118 rm -rf $xtmp/etc
/yum.repos.d
/orig
125 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
133 local domain
=$
(domainname
)
138 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
139 domainname
$domain # workaround for #613377
153 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
165 if [[ $DIST =~
64 ]]; then
174 local exc
="EXCLUDE_$DIST"
176 debootstrap
--arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
185 CENTOS5_32 CENTOS5_64
186 CENTOS6_32 CENTOS6_64
187 CENTOS7_32 CENTOS7_64
203 mk-basefile, create minimal base files for a Linux distritubtion
205 Copyright (C) 2011-2016 by Thomas Lange
207 Usage: mk-basefile [OPTION] ... DISTRIBUTION
209 -s Show list of supported linux distributions
210 -a Add xtattrs, acl and selinux properties to the tar file.
211 -d DIR Use DIR for creating the temporary subtree structure.
212 -z Use gzip for compressing the tar file.
213 -J Use xz for compressing the tar file.
214 -k Keep the temporary subtree structure, do not remove it.
217 Usage example: mk-basefile -J STRETCH64
218 This will create a STRETCH64.tar.xz basefile.
231 while getopts ashzJd
:k opt
; do
233 a
) attributes
="--xattrs --selinux --acl" ;;
234 d
) export TMPDIR
=$OPTARG ;;
235 z
) zip="gzip -9"; ext
=tar.gz
;;
236 J
) zip="xz -8" ext
=tar.xz
;;
239 s
) prtdists
; exit 0;;
240 ?
) exit 3 ;; # error in option parsing
243 shift $
(($OPTIND - 1))
245 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
246 if [ $?
-eq 1 ]; then
247 echo "mktemp failed. Aborting."
252 target
=$1 # also the name of the output file
255 CENTOS5_32
) centos i386
5 ;;
256 CENTOS5_64
) centos amd64
5 ;;
257 CENTOS6_32
) centos i386
6 ;;
258 CENTOS6_64
) centos amd64
6 ;;
259 CENTOS7_32
) centos i386
7 ;;
260 CENTOS7_64
) centos amd64
7 ;;
261 SLC5_32
) slc i386
5 ;;
262 SLC5_64
) slc amd64
5 ;;
263 SLC6_32
) slc i386
6 ;;
264 SLC6_64
) slc amd64
6 ;;
265 SLC7_64
) slc amd64
7 ;;
267 debgeneric
$target $MIRROR_TRISQUEL ;;
269 debgeneric
$target $MIRROR_UBUNTU ;;
270 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*)
271 debgeneric
$target $MIRROR_DEBIAN ;;
272 *) echo "Unknown distribution. Aborting."
278 if [ $cleanup -eq 1 ]; then