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