AArch64 (arm64) support for image building, mock
[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 iso_arch="$(uname -m)"
34 reposnap_base=$(_read_build_config DEFAULT centos_reposnap)
35 release_version=$PRODUCT_RELEASE_LABEL
36 reposnap_base_dir="${reposnap_base}/os/${iso_arch}/"
37 iso_image_label=$(_read_build_config DEFAULT iso_image_label)
38 cd_efi_dir="${reposnap_base_dir}/EFI"
39 cd_images_dir="${reposnap_base_dir}/images"
40 cd_isolinux_dir="${reposnap_base_dir}/isolinux"
41
42 remove_extra_slashes_from_url() {
43   echo $1 | sed -re 's#([^:])//+#\1/#g'
44 }
45
46 wget_dir() {
47   local url=$1
48   echo $url | grep -q /$ || _abort "wget path '$url' must end with slash for recursive wget"
49   # if any extra slashes within path, it messes up the --cut-dirs count
50   url=$(remove_extra_slashes_from_url $url)
51   # count cut length in case url depth changes
52   cut_dirs=$(echo $url | sed -re 's|.*://[^/]+/(.+)|\1|' -e 's|/$||' | grep -o / | wc -l)
53   wget -N -r --no-host-directories --no-verbose --cut-dirs=${cut_dirs} --reject index.html* --no-parent $url
54 }
55
56 pushd $iso_build_dir
57
58 # Get files needed for generating CD image.
59 wget_dir ${cd_efi_dir}/
60 wget_dir ${cd_images_dir}/
61 rm -f images/boot.iso
62 sync
63 chmod +w -R EFI/ images/
64 # AArch64 does not support PC-BIOS, so skip all isolinux processing
65 if [ "${iso_arch}" != 'aarch64' ]; then
66     wget_dir ${cd_isolinux_dir}/
67     chmod +w -R isolinux/
68
69     if [ -e $scriptdir/isolinux/isolinux.cfg ]; then
70         cp $scriptdir/isolinux/isolinux.cfg isolinux/isolinux.cfg
71     else
72         sed -i "s/^timeout.*/timeout 100/" isolinux/isolinux.cfg
73         sed -i "s/^ -  Press.*/Beginning the cloud installation process/" isolinux/boot.msg
74         sed -i "s/^#menu hidden/menu hidden/" isolinux/isolinux.cfg
75         sed -i "s/menu default//" isolinux/isolinux.cfg
76         sed -i "/^label linux/amenu default" isolinux/isolinux.cfg
77         sed -i "/append initrd/ s/$/ console=tty0 console=ttyS1,115200/" isolinux/isolinux.cfg
78     fi
79     cp -f $scriptdir/akraino_splash.png isolinux/splash.png
80 fi
81
82 popd
83
84 pushd $tmp
85
86  # Copy latest kernel and initrd-provisioning from boot dir
87 if [ "${iso_arch}" != 'aarch64' ]; then
88     qemu-img convert $input_image guest-image.raw
89     myloop=$(sudo losetup -fP --show guest-image.raw)
90     mkdir mnt
91     sudo mount -o loop ${myloop}p1 mnt/
92     sudo rsync -avA mnt/boot .
93     sudo chown -R $(id -u):$(id -g) boot
94     sudo umount mnt
95     sudo losetup -d ${myloop}
96     rm -f guest-image.raw
97 else
98     export LIBGUESTFS_BACKEND=direct
99     virt-copy-out -a $input_image /boot/ ./
100 fi
101
102 chmod u+w boot/
103 KVER=`ls -lrt boot/vmlinuz-* |grep -v rescue |tail -n1 |awk -F 'boot/vmlinuz-' '{print $2}'`
104 if [ "${iso_arch}" != 'aarch64' ]; then
105     rm -f $iso_build_dir/isolinux/vmlinuz $iso_build_dir/isolinux/initrd.img
106     cp -fp boot/vmlinuz-${KVER} $iso_build_dir/isolinux/vmlinuz
107     cp -fp boot/initrd-provisioning.img $iso_build_dir/isolinux/initrd.img
108 fi
109 rm -rf boot/
110
111 echo "Generating boot iso"
112 if [ "${iso_arch}" != 'aarch64' ]; then
113     bios_specific_args="-b isolinux/isolinux.bin -c isolinux/boot.cat \
114                         -no-emul-boot -boot-load-size 4 -boot-info-table"
115 fi
116 genisoimage  -U -r -v -T -J -joliet-long \
117   -V "${release_version}" -A "${release_version}" -P ${iso_image_label} \
118   ${bios_specific_args:-} \
119   -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
120   -o boot.iso $iso_build_dir
121 _publish_image $tmp/boot.iso $output_bootcd_path
122
123 cp -f ${input_image} $iso_build_dir/
124
125 # Keep the placeholder
126 mkdir -p $iso_build_dir/rpms
127
128 echo "Generating product iso"
129 genisoimage  -U -r -v -T -J -joliet-long \
130   -V "${release_version}" -A "${release_version}" -P ${iso_image_label} \
131   ${bios_specific_args:-} \
132   -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
133   -o release.iso $iso_build_dir
134 [ "${iso_arch}" = 'aarch64' ] || isohybrid $tmp/release.iso
135 _publish_image $tmp/release.iso $output_image_path
136
137 echo "Clean up to preserve workspace footprint"
138 rm -f $iso_build_dir/$(basename ${input_image})
139 rm -rf $iso_build_dir/rpms
140
141 popd