Replace hanging virt-copy-out commands
[ta/build-tools.git] / build_step_create_install_cd.sh
1 #!/bin/bash
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -x
17 set -e
18
19 scriptdir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
20 source $scriptdir/lib.sh
21 _read_manifest_vars
22
23 tmp=$WORKTMP/install_cd
24 iso_build_dir=$tmp/build
25
26 input_image=$(readlink -f ${1:-$WORKTMP/goldenimage/$GOLDEN_IMAGE_NAME})
27 output_image_path=${2:-$RESULT_IMAGES_DIR/install.iso}
28 output_bootcd_path=${3:-$RESULT_IMAGES_DIR/bootcd.iso}
29 mkdir -p $tmp
30 rm -rf $iso_build_dir
31 mkdir -p $iso_build_dir
32
33 reposnap_base=$(_read_build_config DEFAULT centos_reposnap)
34 release_version=$PRODUCT_RELEASE_LABEL
35 reposnap_base_dir="${reposnap_base}/os/x86_64/"
36 iso_image_label=$(_read_build_config DEFAULT iso_image_label)
37 cd_efi_dir="${reposnap_base_dir}/EFI"
38 cd_images_dir="${reposnap_base_dir}/images"
39 cd_isolinux_dir="${reposnap_base_dir}/isolinux"
40
41 remove_extra_slashes_from_url() {
42   echo $1 | sed -re 's#([^:])//+#\1/#g'
43 }
44
45 wget_dir() {
46   local url=$1
47   echo $url | grep -q /$ || _abort "wget path '$url' must end with slash for recursive wget"
48   # if any extra slashes within path, it messes up the --cut-dirs count
49   url=$(remove_extra_slashes_from_url $url)
50   # count cut length in case url depth changes
51   cut_dirs=$(echo $url | sed -re 's|.*://[^/]+/(.+)|\1|' -e 's|/$||' | grep -o / | wc -l)
52   wget -N -r --no-host-directories --no-verbose --cut-dirs=${cut_dirs} --reject index.html* --no-parent $url
53 }
54
55 pushd $iso_build_dir
56
57 # Get files needed for generating CD image.
58 wget_dir ${cd_efi_dir}/
59 wget_dir ${cd_images_dir}/
60 rm -f images/boot.iso
61 sync
62 wget_dir ${cd_isolinux_dir}/
63 chmod +w -R isolinux/ EFI/ images/
64
65 if [ -e $scriptdir/isolinux/isolinux.cfg ]; then
66     cp $scriptdir/isolinux/isolinux.cfg isolinux/isolinux.cfg
67 else
68     sed -i "s/^timeout.*/timeout 100/" isolinux/isolinux.cfg
69     sed -i "s/^ -  Press.*/Beginning the cloud installation process/" isolinux/boot.msg
70     sed -i "s/^#menu hidden/menu hidden/" isolinux/isolinux.cfg
71     sed -i "s/menu default//" isolinux/isolinux.cfg
72     sed -i "/^label linux/amenu default" isolinux/isolinux.cfg
73     sed -i "/append initrd/ s/$/ console=tty0 console=ttyS1,115200/" isolinux/isolinux.cfg
74 fi
75 cp -f $scriptdir/akraino_splash.png isolinux/splash.png
76
77 popd
78
79 pushd $tmp
80
81  # Copy latest kernel and initrd-provisioning from boot dir
82 qemu-img convert $input_image guest-image.raw
83 myloop=$(sudo losetup -fP --show guest-image.raw)
84 mkdir mnt
85 sudo mount -o loop ${myloop}p1 mnt/
86 sudo rsync -avA mnt/boot .
87 sudo chown -R $(id -u):$(id -g) boot
88 sudo umount mnt
89 sudo losetup -d ${myloop}
90 rm -f guest-image.raw
91
92 chmod u+w boot/
93 rm -f $iso_build_dir/isolinux/vmlinuz $iso_build_dir/isolinux/initrd.img
94 KVER=`ls -lrt boot/vmlinuz-* |grep -v rescue |tail -n1 |awk -F 'boot/vmlinuz-' '{print $2}'`
95 cp -fp boot/vmlinuz-${KVER} $iso_build_dir/isolinux/vmlinuz
96 cp -fp boot/initrd-provisioning.img $iso_build_dir/isolinux/initrd.img
97 rm -rf boot/
98
99 echo "Generating boot iso"
100 genisoimage  -U -r -v -T -J -joliet-long \
101   -V "${release_version}" -A "${release_version}" -P ${iso_image_label} \
102   -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
103   -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
104   -o boot.iso $iso_build_dir
105 _publish_image $tmp/boot.iso $output_bootcd_path
106
107 cp -f ${input_image} $iso_build_dir/
108
109 # Keep the placeholder
110 mkdir -p $iso_build_dir/rpms
111
112 echo "Generating product iso"
113 genisoimage  -U -r -v -T -J -joliet-long \
114   -V "${release_version}" -A "${release_version}" -P ${iso_image_label} \
115   -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
116   -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
117   -o release.iso $iso_build_dir
118 isohybrid $tmp/release.iso
119 _publish_image $tmp/release.iso $output_image_path
120
121 echo "Clean up to preserve workspace footprint"
122 rm -f $iso_build_dir/$(basename ${input_image})
123 rm -rf $iso_build_dir/rpms
124
125 popd