github.com/verrazzano/verrazzano@v1.7.0/release/scripts/archive_source_prt.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2022, 2023, Oracle and/or its affiliates. 4 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 5 # 6 # A script to archive the source as a .tar.gz file. When the size of the source archive is more than 4GB, it is split into 7 # parts such that each part is not more than 4GB 8 9 set -e 10 11 SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P) 12 13 if [ -z "$1" ]; then 14 echo "Specify the directory containing the source files" 15 exit 1 16 fi 17 18 if [ -z "$2" ]; then 19 echo "Specify the directory in which the source archive is to be created" 20 exit 1 21 fi 22 23 if [ -z "$3" ]; then 24 echo "Specify the Verrazzano release version" 25 exit 1 26 fi 27 28 SOURCE_DIR=$1 29 ARCHIVE_DIR=$2 30 VERRAZZANO_VERSION=$3 31 32 VERRAZZANO_PREFIX="verrazzano" 33 VERRAZZANO_RELEASE=${VERRAZZANO_PREFIX}-${VERRAZZANO_VERSION} 34 SOURCE_ARCHIVE=${VERRAZZANO_RELEASE}.tar.gz 35 36 # Create an archive from source code in SOURCE_DIR 37 function createSourceArchive() { 38 cd $SOURCE_DIR 39 tar -czf ${ARCHIVE_DIR}/${SOURCE_ARCHIVE} * 40 } 41 42 # Split the generated tar file, such that each of the source code file has maximum of 4GB 43 # Resulting files will be ${VERRAZZANO_RELEASE}.part00.tar.gz, ${VERRAZZANO_RELEASE}.part01.tar.gz, etc 44 function splitSourceArchive() { 45 cd ${ARCHIVE_DIR} 46 if [ $(stat -c %s "${SOURCE_ARCHIVE}") -gt ${MAX_FILE_SIZE} ]; then 47 echo "The source archive ${SOURCE_ARCHIVE} is of size more than 4GB, splitting it into multiple files and restrict the maximum size to 4GB" 48 split -b 4G ${SOURCE_ARCHIVE} -d --additional-suffix=.tar.gz "${VERRAZZANO_RELEASE}.part" 49 split_count=0 50 for i in ${VERRAZZANO_RELEASE}.part*.tar.gz; 51 do 52 # Create sha256 for all the parts 53 ${SHA256_CMD} ${i} > ${i}.sha256 54 55 # Upload the file and the SHA to Object Storage for release branches 56 if [[ "${BRANCH_NAME}" == "release-"* ]];then 57 echo "Upload source archive ${i} and ${i}.sha256 ..." 58 oci --region ${OCI_REGION} os object put --force --namespace ${OBJECT_STORAGE_NS} -bn ${OBJECT_STORAGE_BUCKET} --name ${BRANCH_NAME}/${i} --file ${i} 59 oci --region ${OCI_REGION} os object put --force --namespace ${OBJECT_STORAGE_NS} -bn ${OBJECT_STORAGE_BUCKET} --name ${BRANCH_NAME}/${i}.sha256 --file ${i}.sha256 60 fi 61 split_count=$(($split_count+1)) 62 done 63 echo "The source archive is split into ${split_count} files, make sure that they can be combined to form a .tar.gz file, which can be extracted" 64 echo "Sample command to combine the parts: cat ${VERRAZZANO_RELEASE}.part*.tar.gz >${VERRAZZANO_RELEASE}_joined.tar.gz" 65 else 66 echo "Created source archive ${ARCHIVE_DIR}/${SOURCE_ARCHIVE}" 67 sha256sum ${SOURCE_ARCHIVE} > ${SOURCE_ARCHIVE}.sha256 68 # Upload the file and the SHA to Object Storage for release branches 69 if [[ "${BRANCH_NAME}" == "release-"* ]];then 70 echo "Upload source archive ${SOURCE_ARCHIVE} and ${SOURCE_ARCHIVE}.sha256 ..." 71 oci --region ${OCI_REGION} os object put --force --namespace ${OBJECT_STORAGE_NS} -bn ${OBJECT_STORAGE_BUCKET} --name ${BRANCH_NAME}/${SOURCE_ARCHIVE} --file ${SOURCE_ARCHIVE} 72 oci --region ${OCI_REGION} os object put --force --namespace ${OBJECT_STORAGE_NS} -bn ${OBJECT_STORAGE_BUCKET} --name ${BRANCH_NAME}/${SOURCE_ARCHIVE}.sha256 --file ${SOURCE_ARCHIVE}.sha256 73 fi 74 fi 75 } 76 77 # Command to calculate the SHA256 78 SHA256_CMD="sha256sum" 79 if [ "$(uname)" == "Darwin" ]; then 80 SHA256_CMD="shasum -a 256" 81 fi 82 83 # Restrict the maximum size of the file to 4GB 84 MAX_FILE_SIZE=4294967296 85 86 # Create ARCHIVE_DIR, if it is not there already 87 if [[ ! -d "${ARCHIVE_DIR}" ]]; then 88 mkdir -p ${ARCHIVE_DIR} 89 fi 90 91 if [ -d ${ARCHIVE_DIR} ]; then 92 if [ "$(ls -A ${ARCHIVE_DIR})" ]; then 93 echo "The directory ${ARCHIVE_DIR} to create the archive is not empty" 94 exit 1 95 fi 96 fi 97 98 # For release-* branch, check for environment variables required to upload the objects to store 99 if [[ "${BRANCH_NAME}" == "release-"* ]];then 100 if [ -z "$OCI_REGION" ] || [ -z "$OBJECT_STORAGE_NS" ] || [ -z "$OBJECT_STORAGE_BUCKET" ]; then 101 echo "This script requires environment variables - OCI_REGION, OBJECT_STORAGE_NS, and OBJECT_STORAGE_BUCKET" 102 exit 1 103 fi 104 fi 105 106 createSourceArchive 107 splitSourceArchive