Add initial code
[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="$WORKTMP/goldenimage/${GOLDEN_IMAGE_NAME}"
27 output_image_path="$1"
28 [[ $output_image_path =~ ^/ ]] || output_image_path=$(pwd)/$output_image_path
29 output_bootcd_path="$2"
30 [[ $output_bootcd_path =~ ^/ ]] || output_bootcd_path=$(pwd)/$output_bootcd_path
31 mkdir -p $tmp
32 rm -rf $iso_build_dir
33 mkdir -p $iso_build_dir
34
35 reposnap_base=$(_read_build_config DEFAULT centos_reposnap_base)
36 release_version=$PRODUCT_RELEASE_LABEL
37 reposnap_base_dir="${reposnap_base}/os/x86_64/"
38 iso_image_label=$(_read_build_config DEFAULT iso_image_label)
39 cd_efi_dir="${reposnap_base_dir}/EFI"
40 cd_images_dir="${reposnap_base_dir}/images"
41 cd_isolinux_dir="${reposnap_base_dir}/isolinux"
42
43 remove_extra_slashes_from_url() {
44   echo $1 | sed -re 's#([^:])//+#\1/#g'
45 }
46
47 get_nexus() {
48  $scriptdir/nexus3_dl.sh \
49     $nexus_url \
50     $(basename $nexus_reposnaps) \
51     ${reposnap_base#$nexus_reposnaps/}/os/x86_64 $@
52 }
53
54 wget_dir() {
55   local url=$1
56   echo $url | grep -q /$ || _abort "wget path '$url' must end with slash for recursive wget"
57   # if any extra slashes within path, it messes up the --cut-dirs count
58   url=$(remove_extra_slashes_from_url $url)
59   # count cut length in case url depth changes
60   cut_dirs=$(echo $url | sed -re 's|.*://[^/]+/(.+)|\1|' -e 's|/$||' | grep -o / | wc -l)
61   wget -N -r --no-host-directories --no-verbose --cut-dirs=${cut_dirs} --reject index.html* --no-parent $url
62 }
63
64 pushd $iso_build_dir
65
66 # Get files needed for generating CD image.
67 if echo $reposnap_base_dir | grep -E "https?://nexus3"; then
68   nexus_url=$(_read_build_config DEFAULT nexus_url)
69   nexus_reposnaps=$(_read_build_config DEFAULT nexus_reposnaps)
70   get_nexus "EFI/BOOT" "EFI/BOOT/fonts"
71   get_nexus "images:*efiboot.img" "images/pxeboot"
72   get_nexus "isolinux"
73 else
74   wget_dir ${cd_efi_dir}/
75   wget_dir ${cd_images_dir}/
76   rm -rf images/boot.iso
77   sync
78   wget_dir ${cd_isolinux_dir}/
79 fi
80 chmod +w -R isolinux/ EFI/ images/
81
82 if [ -e $scriptdir/isolinux/isolinux.cfg ]; then
83     cp $scriptdir/isolinux/isolinux.cfg isolinux/isolinux.cfg
84 else
85     sed -i "s/^timeout.*/timeout 100/" isolinux/isolinux.cfg
86     sed -i "s/^ -  Press.*/Beginning the cloud installation process/" isolinux/boot.msg
87     sed -i "s/^#menu hidden/menu hidden/" isolinux/isolinux.cfg
88     sed -i "s/menu default//" isolinux/isolinux.cfg
89     sed -i "/^label linux/amenu default" isolinux/isolinux.cfg
90     sed -i "/append initrd/ s/$/ console=tty0 console=ttyS1,115200/" isolinux/isolinux.cfg
91 fi
92 cp -f $scriptdir/akraino_splash.png isolinux/splash.png
93
94 popd
95
96 pushd $tmp
97
98  # Copy latest kernel and initrd-provisioning from boot dir
99 virt-copy-out -a $input_image /boot/ ./
100 chmod u+w boot/
101 rm -f $iso_build_dir/isolinux/vmlinuz $iso_build_dir/isolinux/initrd.img
102 KVER=`ls -lrt boot/vmlinuz-* |grep -v rescue |tail -n1 |awk -F 'boot/vmlinuz-' '{print $2}'`
103 cp -fp boot/vmlinuz-${KVER} $iso_build_dir/isolinux/vmlinuz
104 cp -fp boot/initrd-provisioning.img $iso_build_dir/isolinux/initrd.img
105 rm -rf boot/
106
107 echo "Generating boot iso"
108 _run_cmd genisoimage  -U -r -v -T -J -joliet-long \
109   -V "${release_version}" -A "${release_version}" -P ${iso_image_label} \
110   -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
111   -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
112   -o boot.iso $iso_build_dir
113 _publish_image $tmp/boot.iso $output_bootcd_path
114
115 cp -f ${input_image} $iso_build_dir/
116
117 # Keep the placeholder
118 mkdir -p $iso_build_dir/rpms
119
120 echo "Generating product iso"
121 _run_cmd genisoimage  -U -r -v -T -J -joliet-long \
122   -V "${release_version}" -A "${release_version}" -P ${iso_image_label} \
123   -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
124   -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot \
125   -o release.iso $iso_build_dir
126 _run_cmd isohybrid $tmp/release.iso
127 _publish_image $tmp/release.iso $output_image_path
128
129 echo "Clean up to preserve workspace footprint"
130 rm -f $iso_build_dir/$(basename ${input_image})
131 rm -rf $iso_build_dir/rpms
132
133 popd