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
://httpredir.debian.org
/debian
/
21 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
22 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
24 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
,tasksel
,tasksel-data
25 EXCLUDE_WHEEZY
=info
,tasksel
,tasksel-data
26 EXCLUDE_JESSIE
=tasksel
,tasksel-data
27 EXCLUDE_STRETCH
=tasksel
,tasksel-data
29 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
30 EXCLUDE_XENIAL
=tasksel
,tasksel-data
32 INCLUDE_DEBIAN
=aptitude
38 if [ X
$1 = Xi386
]; then
45 if [ `id -u` != 0 ]; then
46 echo "You must be root to create chroots."
49 mknod
$xtmp/test-dev-null c
1 3
51 echo "Cannot create device files on $xtmp, aborting."
52 echo "Perhaps this directory is mounted with option nodev."
56 echo test > $xtmp/test-dev-null
58 echo "Cannot create device files on $xtmp, aborting."
59 echo "Perhaps this directory is mounted with option nodev."
63 rm -f $xtmp/test-dev-null
69 [ -z "$MIRROR_CENTOS" ] && return
70 cat <<EOM > $xtmp/post
72 mkdir -p $xtmp/etc/yum.repos.d/orig
73 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
74 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
83 [ -z "$MIRROR_SLC" ] && return
84 cat <<EOM > $xtmp/post
86 mkdir -p $xtmp/etc/yum.repos.d/orig
87 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
88 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
89 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
98 chroot
$xtmp aptitude clean
99 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf
$xtmp/etc
/machine-id
100 rm $xtmp/var
/lib
/apt
/lists
/*_
*
101 rm -f $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
107 # check if chroot works
108 echo "Installed packages in chroot:"
109 chroot
$xtmp rpm
-qa|
sort
110 echo -n "CHROOT rpm -qa: "
111 chroot
$xtmp rpm
-qa|
wc -l
113 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
114 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
115 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
116 rm -rf $xtmp/etc
/yum.repos.d
/orig
123 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
131 local domain
=$
(domainname
)
136 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
137 domainname
$domain # workaround for #613377
151 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
163 if [[ $DIST =~
64 ]]; then
172 local exc
="EXCLUDE_$DIST"
174 debootstrap
--arch $arch --exclude=${!exc} --include=${INCLUDE_DEBIAN} $dist $xtmp $mirror
183 CENTOS5_32 CENTOS5_64
184 CENTOS6_32 CENTOS6_64
185 CENTOS7_32 CENTOS7_64
201 mk-basefile, create minimal base files for a Linux distritubtion
203 Copyright (C) 2011-2016 by Thomas Lange
205 Usage: mk-basefile [OPTION] ... DISTRIBUTION
207 -s Show list of supported linux distributions
208 -a Add xtattrs, acl and selinux properties to the tar file.
209 -d DIR Use DIR for creating the temporary subtree structure.
210 -z Use gzip for compressing the tar file.
211 -J Use xz for compressing the tar file.
212 -k Keep the temporary subtree structure, do not remove it.
215 Usage example: mk-basefile -J STRETCH64
216 This will create a STRETCH64.tar.xz basefile.
229 while getopts ashzJd
:k opt
; do
231 a
) attributes
="--xattrs --selinux --acl" ;;
232 d
) export TMPDIR
=$OPTARG ;;
233 z
) zip="gzip -9"; ext
=tar.gz
;;
234 J
) zip="xz -8" ext
=tar.xz
;;
237 s
) prtdists
; exit 0;;
238 ?
) exit 3 ;; # error in option parsing
241 shift $
(($OPTIND - 1))
243 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
244 if [ $?
-eq 1 ]; then
245 echo "mktemp failed. Aborting."
250 target
=$1 # also the name of the output file
253 CENTOS5_32
) centos i386
5 ;;
254 CENTOS5_64
) centos amd64
5 ;;
255 CENTOS6_32
) centos i386
6 ;;
256 CENTOS6_64
) centos amd64
6 ;;
257 CENTOS7_32
) centos i386
7 ;;
258 CENTOS7_64
) centos amd64
7 ;;
259 SLC5_32
) slc i386
5 ;;
260 SLC5_64
) slc amd64
5 ;;
261 SLC6_32
) slc i386
6 ;;
262 SLC6_64
) slc amd64
6 ;;
263 SLC7_64
) slc amd64
7 ;;
265 debgeneric
$target $MIRROR_UBUNTU ;;
266 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*)
267 debgeneric
$target $MIRROR_DEBIAN ;;
268 *) echo "Unknown distribution. Aborting."
274 if [ $cleanup -eq 1 ]; then