build_inf_centos: remove the build_image_rm
[pti/rtp.git] / scripts / build_inf_centos / build_inf_centos.sh
index 911f524..cb34833 100755 (executable)
@@ -26,6 +26,7 @@ SRC_ORAN_BRANCH="master"
 SRC_ORAN_URL="https://gerrit.o-ran-sc.org/r/pti/rtp"
 
 SCRIPTS_DIR=$(dirname $(readlink -f $0))
+SCRIPTS_NAME=$(basename $0)
 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
 
 #########################################################################
@@ -35,7 +36,7 @@ TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
 help_info () {
 cat << ENDHELP
 Usage:
-$(basename $0) [-w WORKSPACE_DIR] [-n] [-u] [-h]
+${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-n] [-u] [-h]
 where:
     -w WORKSPACE_DIR is the path for the project
     -n dry-run only for bitbake
@@ -50,14 +51,14 @@ ENDHELP
 echo_step_start() {
     [ -n "$1" ] && msg_step=$1
     echo "#########################################################################################"
-    echo "## STEP START: ${msg_step}"
+    echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
     echo "#########################################################################################"
 }
 
 echo_step_end() {
     [ -n "$1" ] && msg_step=$1
     echo "#########################################################################################"
-    echo "## STEP END: ${msg_step}"
+    echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
     echo "#########################################################################################"
     echo
 }
@@ -93,7 +94,7 @@ while getopts "w:b:e:r:unh" OPTION; do
             ;;
         u)
             SKIP_UPDATE="No"
-           ;;
+            ;;
         h)
             help_info
             exit
@@ -121,8 +122,12 @@ STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
 STX_MIRROR_DIR=${WORKSPACE}/mirror
 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
 
+SRC_META_PATCHES=${SCRIPTS_DIR}/meta-patches
+
+ISO_INF_COS=inf-image-centos-all-x86-64.iso
+
 prepare_workspace () {
-    msg_step="Create workspace for the build"
+    msg_step="Create workspace for the CentOS build"
     echo_step_start
 
     mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} ${STX_PRJ_OUTPUT}
@@ -139,7 +144,7 @@ prepare_workspace () {
 }
 
 create_env () {
-    msg_step="Create env file for the build"
+    msg_step="Create env file for the CentOS build"
     echo_step_start
 
     ENV_FILENAME=env.${PRJ_NAME}
@@ -230,81 +235,69 @@ repo_init_sync () {
     echo_step_end
 }
 
-create_build_docker () {
-    msg_step="Create build environment docker container"
-    echo_step_start
-
-    cd ${MY_REPO_ROOT_DIR}/stx-tools/
-    export PATH=$PATH:$PWD
-
-    echo "MYUNAME=${USER}" > localrc
-    echo "PROJECT=${PRJ_NAME}" >> localrc
-    echo "HOST_PREFIX=${WORKSPACE}" >> localrc
-    echo "HOST_MIRROR_DIR=${WORKSPACE}/mirror" >> localrc
-    echo "LAYER=${LAYER}" >> localrc
-    echo "MY_EMAIL=jackie.huang@windriver.com" >> localrc
-
-    # workarounds
-    #git checkout master
-    #sed -i 's/docker /sudo docker /' tb.sh
-
-    #RUN_CMD="tb.sh create"
-    #run_cmd "Create build environment docker image"
-
-    RUN_CMD="tb.sh run"
-    run_cmd "Create build environment docker container"
+patch_src () {
+    echo_step_start "Some source codes need to be patched for INF project"
+
+    sed -i "s|/import/mirrors|${STX_MIRROR_DIR}|" \
+        $MY_REPO/stx/metal/installer/pxe-network-installer/centos/build_srpm.data
+
+    # Apply meta patches
+    cd ${SRC_META_PATCHES}
+    src_dirs=$(find . -type f -printf "%h\n"|uniq)
+    for d in ${src_dirs}; do
+        cd ${MY_REPO_ROOT_DIR}/${d}
+
+        # backup current branch
+        local_branch=$(git rev-parse --abbrev-ref HEAD)
+        if [ "${local_branch}" = "HEAD" ]; then
+            git checkout ${STX_SRC_BRANCH}
+            local_branch=$(git rev-parse --abbrev-ref HEAD)
+        fi
+        git branch -m "${local_branch}_${TIMESTAMP}"
+        git checkout ${STX_SRC_BRANCH}
+
+        for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
+            echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
+            git am ${SRC_META_PATCHES}/${d}/${p}
+        done
+    done
 
     echo_step_end
 }
 
-exec_build_docker () {
-    msg_step="Enter a bash shell within the build environment container"
-    echo_step_start
-
-    cd ${MY_REPO_ROOT_DIR}/stx-tools/
-    export PATH=$PATH:$PWD
-
-    RUN_CMD="tb.sh exec"
-    run_cmd "Enter a bash shell within the build environment container"
-
-    #cd $MY_REPO_ROOT_DIR/stx-tools/centos-mirror-tools/
-    #RUN_CMD="sudo -E ./download_mirror.sh"
-    #run_cmd "Download rpms"
-
-    echo_step_end
+populate_dl () {
+    ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/generate-centos-repo.sh ${STX_MIRROR_DIR}/stx-6.0
+    ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/populate_downloads.sh ${STX_MIRROR_DIR}/stx-6.0
 }
 
-# To be removed:
-# This build script can not successfully build out the image yet,
-# get the upstream image temporary so we can still test the CI job to
-# upload the image to nexus
-ISO_STX_COS=bootimage.iso
-ISO_UP_VER=6.0.0
-ISO_UP=http://mirror.starlingx.cengn.ca/mirror/starlingx/release/${ISO_UP_VER}/centos/flock/outputs/iso/${ISO_STX_COS}
-ISO_INF_COS=inf-image-centos-all-x86-64.iso
-
-
 build_image () {
     echo_step_start "Build CentOS images"
 
     mkdir -p ${STX_PRJ_OUTPUT}
-    cd ${STX_PRJ_OUTPUT}
-    wget -q ${ISO_UP} -O ${ISO_INF_COS}
-    ls -lh ${STX_PRJ_OUTPUT}/${ISO_INF_COS}
+    cd ${MY_BUILD_DIR}
+    RUN_CMD="build-pkgs --build-avoidance"
+    run_cmd "Build pkgs"
+
+    # The first run always fail
+    build-iso || sleep 60
+
+    RUN_CMD="build-iso"
+    run_cmd "Build ISO image"
+
+    cp -f ${MY_BUILD_DIR}/export/bootimage.iso ${STX_PRJ_OUTPUT}/${ISO_INF_COS}
 
     echo_step_end
 
     echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_COS}"
 }
 
-
 #########################################################################
 # Main process
 #########################################################################
 
 prepare_workspace
 create_env
-#repo_init_sync
-#create_build_docker
-#exec_build_docker
+repo_init_sync
+patch_src
+populate_dl
 build_image