2 # KIWI specific functions. Handle with care.
4 ################################################################
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 ################################################################
25 ############################################################
27 # post scriptlet generation functions
31 echo "compressing oem images... "
33 # do not store compressed file _and_ uncompressed one
34 [ -e "$imageout.gz" ] && rm -f "$imageout"
35 if [ -e "$imageout.iso" ]; then
36 echo "take iso file and create sha256..."
37 mv "$imageout.iso" "/$TOPDIR/KIWI/$imageout$buildnum.iso"
39 if [ -x /usr/bin/sha256sum ]; then
40 /usr/bin/sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
44 if [ -e "$imageout.install.iso" ]; then
45 echo "take install.iso file and create sha256..."
46 mv "$imageout.install.iso" "/$TOPDIR/KIWI/$imageout$buildnum.install.iso"
48 if [ -x /usr/bin/sha256sum ]; then
49 /usr/bin/sha256sum "$imageout$buildnum.install.iso" > "$imageout$buildnum.install.iso.sha256"
53 if [ -e "$imageout.qcow2" ]; then
54 mv "$imageout.qcow2" "/$TOPDIR/KIWI/$imageout$buildnum.qcow2"
56 if [ -x /usr/bin/sha256sum ]; then
57 echo "Create sha256 file..."
58 /usr/bin/sha256sum "$imageout$buildnum.qcow2" > "$imageout$buildnum.qcow2.sha256"
62 if [ -e "$imageout.raw.install.raw" ]; then
65 if [ -x /usr/bin/xz ]; then
66 # take xz to get support for sparse files
70 mv "$imageout.raw.install.raw" "/$TOPDIR/KIWI/$imageout$buildnum.raw.install.raw"
72 echo "\$compress_tool raw.install.raw file..."
73 \$compress_tool "$imageout$buildnum.raw.install.raw"
74 if [ -x /usr/bin/sha256sum ]; then
75 echo "Create sha256 file..."
76 /usr/bin/sha256sum "$imageout$buildnum.raw.install.raw.\${compress_suffix}" > "$imageout$buildnum.raw.install.raw.\${compress_suffix}.sha256"
80 if [ -e "$imageout.raw" ]; then
83 if [ -x /usr/bin/xz ]; then
84 # take xz to get support for sparse files
88 mv "$imageout.raw" "/$TOPDIR/KIWI/$imageout$buildnum.raw"
90 echo "\$compress_tool raw file..."
91 \$compress_tool "$imageout$buildnum.raw"
92 if [ -x /usr/bin/sha256sum ]; then
93 echo "Create sha256 file..."
94 /usr/bin/sha256sum "$imageout$buildnum.raw.\${compress_suffix}" > "$imageout$buildnum.raw.\${compress_suffix}.sha256"
103 echo "compressing vmx images... "
105 compress_tool="bzip2"
106 compress_suffix="bz2"
107 if [ -x /usr/bin/xz ]; then
108 # take xz to get support for sparse files
109 compress_tool="xz -2"
114 for suffix in "ovf" "qcow2" "ova" "tar" "vhdfixed" "vhd"; do
115 if [ -e "$imageout.\$suffix" ]; then
116 if [ "\$suffix" == "vhd" -o "\$suffix" == "vhdfixed" ]; then
117 mv "$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
119 echo "\$compress_tool \$suffix file..."
120 \$compress_tool "$imageout$buildnum.\$suffix"
121 SHAFILES="\$SHAFILES $imageout$buildnum.\$suffix.\${compress_suffix}"
123 elif [ "\$suffix" == "ovf" ]; then
124 mv "$imageout.\${suffix}/$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
125 SHAFILES="\$SHAFILES $imageout$buildnum.\$suffix"
127 mv "$imageout.\$suffix" "/$TOPDIR/KIWI/$imageout$buildnum.\$suffix"
128 SHAFILES="\$SHAFILES $imageout$buildnum.\$suffix"
132 # This option has a number of format parameters
133 for i in "$imageout.vmx" "$imageout.vmdk" "$imageout-disk*.vmdk"; do
134 test -e \$i && VMXFILES="\$VMXFILES \$i"
136 # take raw files as fallback
137 if [ -n "\$VMXFILES" ]; then
138 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" \$VMXFILES
139 SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
140 elif [ -z "\$SHAFILES" -a -e "$imageout.raw" ]; then
141 mv "$imageout.raw" "/$TOPDIR/KIWI/$imageout$buildnum-vmx.raw"
143 echo "\$compress_tool raw file..."
144 \$compress_tool "$imageout$buildnum-vmx.raw"
145 SHAFILES="\$SHAFILES $imageout$buildnum-vmx.raw.\${compress_suffix}"
148 if [ -e "$imageout.box" ]; then
149 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx-box.tar.bz2" $imageout.box $imageout.json
150 SHAFILES="\$SHAFILES $imageout$buildnum-vmx-box.tar.bz2"
152 if [ -e "$imageout.xenconfig" ]; then
153 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" $imageout.xenconfig $imageout.raw initrd-*
154 SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
156 # FIXME: do we need a single .raw file in any case ?
159 if [ -n "\$SHAFILES" -a -x /usr/bin/sha256sum ]; then
160 for i in \$SHAFILES; do
161 echo "Create sha256 file..."
162 /usr/bin/sha256sum "\$i" > "\$i.sha256"
165 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-raw.tar.bz2" \
166 --exclude="$imageout.iso" --exclude="$imageout.raw" --exclude="$imageout.qcow2" *
168 if [ -x /usr/bin/sha256sum ]; then
169 /usr/bin/sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
176 echo "compressing xen images... "
178 # do not store compressed file _and_ uncompressed one
179 [ -e "$imageout.gz" ] && rm -f "$imageout"
180 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-xen.tar.bz2" \
181 `grep ^kernel $imageout.xenconfig | cut -d'"' -f2` \
182 `grep ^ramdisk $imageout.xenconfig | cut -d'"' -f2` \
184 "$imageout.xenconfig" \
186 if [ -x /usr/bin/sha256sum ]; then
187 echo "Create sha256 file..."
189 /usr/bin/sha256sum "$imageout$buildnum-xen.tar.bz2" > "$imageout$buildnum-xen.tar.bz2.sha256"
196 echo "compressing pxe images... "
198 # do not store compressed file _and_ uncompressed one
199 [ -e "$imageout.gz" ] && rm -f "$imageout"
200 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-pxe.tar.bz2" ${imageout}* initrd-*
201 if [ -x /usr/bin/sha256sum ]; then
202 echo "Create sha256 file..."
204 /usr/bin/sha256sum "$imageout$buildnum-pxe.tar.bz2" > "$imageout$buildnum-pxe.tar.bz2.sha256"
213 mv "\$i" "/$TOPDIR/KIWI/\${i%.iso}$buildnum.iso"
215 if [ -x /usr/bin/sha256sum ]; then
216 echo "creating sha256 sum for iso images... "
219 /usr/bin/sha256sum "\$i" > "\$i.sha256"
229 file=\$(readlink -f "\$i")
230 [ -z "\$file" ] && echo readlink failed for $i
231 mv "\$file" "/$TOPDIR/KIWI/\${i%.tbz}$buildnum.tbz"
233 if [ -x /usr/bin/sha256sum ]; then
234 echo "creating sha256 sum for tar balls... "
237 /usr/bin/sha256sum "\$i" > "\$i.sha256"
243 kiwi_post_unknown() {
245 echo "compressing unkown images... "
246 cd /$TOPDIR/KIWI-$imgtype
247 # do not store compressed file _and_ uncompressed one
248 [ -e "$imageout.gz" ] && rm -f "$imageout"
249 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-$imgtype.tar.bz2" *
250 if [ -x /usr/bin/sha256sum ]; then
251 echo "Create sha256 file..."
253 /usr/bin/sha256sum "$imageout$buildnum-$imgtype.tar.bz2" > "$imageout$buildnum-$imgtype.tar.bz2.sha256"
258 ############################################################
260 recipe_setup_kiwi() {
261 TOPDIR=/usr/src/packages
262 test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
263 mkdir -p "$BUILD_ROOT$TOPDIR"
264 mkdir -p "$BUILD_ROOT$TOPDIR/OTHER"
265 mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES"
266 mkdir -p "$BUILD_ROOT$TOPDIR/KIWI"
267 # compat, older build versions did not clean TOPDIR ...
268 mkdir -p "$BUILD_ROOT$TOPDIR/BUILD"
269 mkdir -p "$BUILD_ROOT$TOPDIR/RPMS"
270 mkdir -p "$BUILD_ROOT$TOPDIR/SRPMS"
272 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
273 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
274 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
276 if test -z "$LINKSOURCES" ; then
277 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
279 cp -lR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
281 if test "$?" != 0 ; then
282 echo "source copy failed"
287 # extract macros from configuration
288 # some post scripts might call rpm-build and rely on the macros
289 queryconfig rawmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/.rpmmacros
292 recipe_prepare_kiwi() {
296 ## obsolete with current kiwi versions, only needed for kiwi 3.01 version
297 run_suse_isolinux() {
298 for i in $BUILD_ROOT/$TOPDIR/KIWIROOT/main/* ; do
299 test -d "$i" || continue
301 test "$i" = scripts && continue
302 test "$i" != "${i%0}" && continue
303 chroot $BUILD_ROOT su -c "suse-isolinux $TOPDIR/KIWIROOT/main/$i $TOPDIR/KIWI/$i.iso" - $BUILD_USER
307 build_kiwi_product() {
308 echo "running kiwi --create-instsource..."
309 # runs always as abuild user
310 mkdir -p "$BUILD_ROOT/$TOPDIR/KIWIROOT"
312 chroot "$BUILD_ROOT" chown -R abuild.abuild "$TOPDIR"
313 chroot "$BUILD_ROOT" rm -rf "$TOPDIR/KIWIROOT"
314 ver=`chroot "$BUILD_ROOT" su -c "/usr/sbin/kiwi --version | sed -n 's,.*kiwi version v\(.*\),\1,p'"`
315 test -n "$ver" || ver=`chroot "$BUILD_ROOT" su -c "/usr/sbin/kiwi --version | sed -n 's,.* vnr: \(.*\),\1,p'"`
316 if test "${ver:0:1}" == "3" ; then
317 # old style kiwi 3 builds
318 chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT -v --logfile terminal -p $TOPDIR/SOURCES --instsource-local --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
319 test ${ver:2:2} == "01" && run_suse_isolinux
321 VERBOSE_OPTION="-v 2"
322 # broken kiwi version, not accepting verbose level
323 test "${ver:0:1}" == "4" -a "${ver:2:2}" -lt 90 && VERBOSE_OPTION="-v -v"
324 chroot "$BUILD_ROOT" su -c "APPID=- LANG=POSIX /usr/sbin/kiwi --root $TOPDIR/KIWIROOT $VERBOSE_OPTION --logfile terminal -p $TOPDIR/SOURCES --create-instsource $TOPDIR/SOURCES" - abuild < /dev/null && BUILD_SUCCEEDED=true
327 # move created product to correct destination
328 pushd $BUILD_ROOT/$TOPDIR/KIWIROOT/main
330 test -e "$i" || continue
332 *.iso) if [ -x /usr/bin/sha256sum ]; then
333 /usr/bin/sha256sum "$i" > "$i.sha256"
334 mv "$i.sha256" $BUILD_ROOT/$TOPDIR/KIWI/.
336 mv "$i" $BUILD_ROOT/$TOPDIR/KIWI/. ;;
337 *.packages) mv $i $BUILD_ROOT/$TOPDIR/OTHER/. ;;
338 *.report) mv $i $BUILD_ROOT/$TOPDIR/OTHER/. ;;
341 *) test -d $i -a "$drop_repo" != true && mv $i $BUILD_ROOT/$TOPDIR/KIWI/. ;;
347 perform_image_build() {
352 # When people test mixed build with legacy and new kiwi version
353 # The zypper cache was used in different ways. Therefore this
354 # needs a cleanup before the build starts
355 echo "Cleanup zypper image build cache"
356 if [ -d "$BUILD_ROOT/var/cache/kiwi/zypper" ];then
357 rm -rf $BUILD_ROOT/var/cache/kiwi/zypper
359 echo "running kiwi --prepare for $imgtype..."
360 # Do not use $BUILD_USER here, since we always need root permissions
361 prepare_call="cd $TOPDIR/SOURCES && rm -rf $TOPDIR/KIWIROOT-$imgtype"
362 if [ "$legacy" = "true" ]; then
363 prepare_call="$prepare_call && /usr/sbin/kiwi --logfile terminal"
365 prepare_call="$prepare_call && LANG=en_US.UTF-8 /usr/bin/kiwi"
366 prepare_call="$prepare_call --compat -- --debug"
368 prepare_call="$prepare_call --prepare $TOPDIR/SOURCES"
369 prepare_call="$prepare_call --root $TOPDIR/KIWIROOT-$imgtype"
370 prepare_call="$prepare_call $KIWI_PARAMETERS"
372 su -c "$prepare_call" - root < /dev/null || cleanup_and_exit 1
374 echo "running kiwi --create for $imgtype..."
375 mkdir -p $BUILD_ROOT/$TOPDIR/KIWI-$imgtype
376 create_call="cd $TOPDIR/SOURCES"
377 if [ "$legacy" = "true" ]; then
378 create_call="$create_call && LANG=en_US.UTF-8 /usr/sbin/kiwi"
379 create_call="$create_call --logfile terminal"
381 create_call="$create_call && /usr/bin/kiwi --compat -- --debug"
383 create_call="$create_call --create $TOPDIR/KIWIROOT-$imgtype"
384 create_call="$create_call --type $imgtype"
385 create_call="$create_call -d $TOPDIR/KIWI-$imgtype"
386 create_call="$create_call $KIWI_PARAMETERS"
388 su -c "$create_call" - root < /dev/null || cleanup_and_exit 1
390 rm -rf "/$TOPDIR/KIWI.bundle"
393 perform_image_bundle() {
397 if [ "$legacy" = "true" ]; then
398 bundle_call="/usr/sbin/kiwi --bundle-build $TOPDIR/KIWI-$imgtype"
399 bundle_call="$bundle_call -d /$TOPDIR/KIWI.bundle/"
400 bundle_call="$bundle_call --bundle-id Build$RELEASE"
402 bundle_call="LANG=en_US.UTF-8 /usr/bin/kiwi result bundle"
403 bundle_call="$bundle_call --target-dir $TOPDIR/KIWI-$imgtype"
404 bundle_call="$bundle_call --id Build$RELEASE"
405 bundle_call="$bundle_call --bundle-dir /$TOPDIR/KIWI.bundle/"
407 if chroot $BUILD_ROOT su -c "$bundle_call" - root < /dev/null; then
408 mv "$BUILD_ROOT/$TOPDIR/KIWI.bundle/"* \
409 "$BUILD_ROOT/$TOPDIR/KIWI/" || cleanup_and_exit 1
410 rmdir "$BUILD_ROOT/$TOPDIR/KIWI.bundle"
414 # need another way to bundle
419 if [ -L "$BUILD_ROOT/usr/bin/kiwi" ];then
420 # The next generation of kiwi is installed to /usr/bin
421 # If this file is found we expect the new kiwi to be
425 # in any other case stick to the legacy kiwi
429 build_kiwi_appliance() {
430 if test -z "$RUNNING_IN_VM" ; then
431 # NOTE: this must be done with the outer system, because it loads
432 # the dm-mod kernel modules, which needs to fit to the kernel.
433 echo "starting device mapper for kiwi..."
434 test -x /etc/init.d/boot.device-mapper && \
435 /etc/init.d/boot.device-mapper start
437 KIWI_PROFILE=$(queryconfig \
438 --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" \
439 --archpath "$BUILD_ARCH" buildflags kiwiprofile
441 if test -n "$KIWI_PROFILE"; then
442 KIWI_PARAMETERS="$KIWI_PARAMETERS --add-profile $KIWI_PROFILE"
445 if is_legacy_kiwi; then
449 for imgtype in $imagetype ; do
450 perform_image_build $imagetype $legacy
451 if perform_image_bundle $imagetype $legacy; then
452 # bundling successful, skip alternative bundlers
458 if test -z "$RUN_BUNDLE"; then
459 # new kiwi has bundled our result already :)
464 # Legacy bundling code for kiwi version below 5.06.106
467 # create tar.gz of images, in case it makes sense
469 if test -n "$RELEASE"; then
470 buildnum="-Build$RELEASE"
473 imageout="$imagename.$imagearch-$imageversion"
474 for imgtype in $imagetype ; do
476 oem) kiwi_post_oem > $BUILD_ROOT/kiwi_post.sh ;;
477 vmx) kiwi_post_vmx > $BUILD_ROOT/kiwi_post.sh ;;
478 xen) kiwi_post_xen > $BUILD_ROOT/kiwi_post.sh ;;
479 pxe) kiwi_post_pxe > $BUILD_ROOT/kiwi_post.sh ;;
480 iso) kiwi_post_iso > $BUILD_ROOT/kiwi_post.sh ;;
481 tbz) kiwi_post_tbz > $BUILD_ROOT/kiwi_post.sh ;;
482 *) kiwi_post_unknown > $BUILD_ROOT/kiwi_post.sh ;;
484 cat >> $BUILD_ROOT/kiwi_post.sh <<-EOF
485 cd /$TOPDIR/KIWI-$imgtype
486 if [ -e "$imageout.channel" ]; then
487 echo "Found kiwi channel list file, exporting as well..."
488 cp "$imageout.channel" "/$TOPDIR/OTHER/$imageout$buildnum-$imgtype.channel"
490 if [ -e "$imageout.packages" ]; then
491 echo "Found kiwi package list file, exporting as well..."
492 cp "$imageout.packages" "/$TOPDIR/OTHER/$imageout$buildnum-$imgtype.packages"
494 if [ -e "$imageout.verified" ]; then
495 echo "Found rpm verification report, exporting as well..."
496 cp "$imageout.verified" "/$TOPDIR/OTHER/$imageout$buildnum-$imgtype.verified"
499 chroot $BUILD_ROOT su -c "sh -e /kiwi_post.sh" || cleanup_and_exit 1
500 rm -f $BUILD_ROOT/kiwi_post.sh
504 recipe_build_kiwi() {
505 imagetype=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE imagetype)
506 imagename=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE filename)
507 imageversion=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE version)
508 drop_repo=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$RECIPEFILE drop_repository)
510 # prepare rpms as source and createrepo on the repositories
511 ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
512 cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
513 for r in *[^:]/* ; do
514 test -L $r && continue
515 test -d $r || continue
516 repo="$TOPDIR/SOURCES/repos/$r/"
517 # create compatibility link for old kiwi versions
519 if test "$rc" != "$r" ; then
523 ln -s $rl$r "${rc%/*}/${rc##*/}"
524 repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
526 if test "$imagetype" != product -a "$DO_INIT" != "false" ; then
527 echo "creating repodata for $repo"
528 if chroot $BUILD_ROOT createrepo --no-database --simple-md-filenames --help >/dev/null 2>&1 ; then
529 chroot $BUILD_ROOT createrepo --no-database --simple-md-filenames "$repo"
531 chroot $BUILD_ROOT createrepo "$repo"
537 for t in $BUILD_ROOT/$TOPDIR/SOURCES/root.tar* ; do
538 test -f $t || continue
539 mkdir -p $BUILD_ROOT/$TOPDIR/SOURCES/root
540 chroot $BUILD_ROOT tar -C $TOPDIR/SOURCES/root -xf "$TOPDIR/SOURCES/${t##*/}"
543 # fix script permissions
544 chmod a+x $BUILD_ROOT/$TOPDIR/SOURCES/*.sh 2>/dev/null
546 # unpack tar files in image directories
547 if test -d $BUILD_ROOT/$TOPDIR/SOURCES/images ; then
549 cd $BUILD_ROOT/$TOPDIR/SOURCES/images
551 test -L $r && continue
552 test -d $r || continue
553 for t in $r/root.tar* ; do
554 test -f $t || continue
556 chroot $BUILD_ROOT tar -C $TOPDIR/SOURCES/images/$r/root -xf "$TOPDIR/SOURCES/images/$r/${t##*/}"
558 # fix script permissions
559 chmod a+x $BUILD_ROOT/$TOPDIR/SOURCES/images/$r/*.sh 2>/dev/null
560 # create compatibility link for old kiwi versions
562 if test "$rc" != "$r" ; then
566 ln -s $rl$r "${rc%/*}/${rc##*/}"
572 rm -f $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
573 ln -s $RECIPEFILE $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
575 if test "$imagetype" = product ; then
581 # Hook for running post kiwi build scripts like QA scripts if installed
582 if test -x $BUILD_ROOT/usr/lib/build/kiwi_post_run ; then
583 chroot $BUILD_ROOT su -c /usr/lib/build/kiwi_post_run || cleanup_and_exit 1
587 recipe_resultdirs_kiwi() {