#!/bin/bash usage() { echo "Usage: $0 --build-directory [build directory, default: /build] --vendor --orgcode --channel-id --package-type [packtype: owner or other; default: owner] --project-id --pipeline-id --url-tag --help" exit 1 } BUILD_DIR="./image_build" VENDOR="" ORGCODE="" CHANNELID="" PACK_TYPE="owner" PROJECT_ID="" PIPELINE_ID="" URL_TAG="" CHROOT_TYPE="androidrom" DEPLOY="elf" export PATH=${PATH}:$(pwd)/tools/ PARSED_ARUGMENTS=$(getopt -a -n "$0" -o 'x' --long help,build-directory:,vendor:,orgcode:,channel-id:,package-type:,project-id:,pipeline-id:,url-tag: -- "$@") eval set -- "${PARSED_ARUGMENTS}" while : do case "$1" in --build-directory) BUILD_DIR="$2"; shift 2;; --vendor) VENDOR="$2"; shift 2;; --orgcode) ORGCODE="$2"; shift 2;; --channel-id) CHANNELID="$2"; shift 2;; --package-type) PACK_TYPE="$2"; shift 2;; --project-id) PROJECT_ID="$2"; shift 2;; --pipeline-id) PIPELINE_ID="$2"; shift 2;; --url-tag) URL_TAG="$2"; shift 2;; --help) usage ;; --) shift; break;; *) usage ;; esac done build_dir=$(mktemp -d /build/tmp.XXXXX) packge_dir=$(mktemp -d "$BUILD_DIR"/tmp.XXXXX) outfile_path="" generate_vendor_confg() { local yaml_file_src local yaml_file local config_json_file yaml_file="$build_dir"/vendor.yaml yaml_file_src="$build_dir"/vendor.yaml.src cp vendor.yaml.src "$yaml_file_src" sed -i'' -e "s#__VENDOR__#$VENDOR#g" \ -e "s#__ORGCODE__#$ORGCODE#g" \ -e "s#__CHROOT_TYPE__#$CHROOT_TYPE#g" \ -e "s#__DEPLOY__#$DEPLOY#g" \ -e "s#__CHANNEL_ID__#$CHANNELID#g" \ -e "s#__PACK_TYPE__#$PACK_TYPE#g" \ -e "s#__CI_PROJECT_ID__#$PROJECT_ID#g" \ -e "s#__CI_PIPELINE_ID__#$PIPELINE_ID#g" "$yaml_file_src" aio -m enc -i "$yaml_file_src" -o "$yaml_file" config_json_file="$build_dir"/config.json cp config.json.src "$config_json_file" sed -i'' "s#__CHANNEL_ID__#$CHANNELID#g" "$config_json_file" } update_hugepall_zipfile() { local yaml_file local hugep_zip_file local hugep_zip_file_origin local config_json_file local config_json_file_bak yaml_file="$build_dir"/vendor.yaml hugep_zip_file="$build_dir/hugep-all.zip" hugep_zip_file_origin="./services/hugep-all.zip" config_json_file="$build_dir"/config.json config_json_file_bak="$build_dir"/config.json.bak cp "$config_json_file" "$config_json_file_bak" cp "$hugep_zip_file_origin" "$hugep_zip_file" zip -u -j "$hugep_zip_file" "$yaml_file" zip -u -j "$hugep_zip_file" "./services/hugep-start.sh" zip -u -j "$hugep_zip_file" "$config_json_file" zip -u -j "$hugep_zip_file" "$config_json_file_bak" zip -u -j "$hugep_zip_file" "./services/hugep" outfile_path="$packge_dir/$VENDOR-$ORGCODE-$CHANNELID-hugep-all.zip" mv "$hugep_zip_file" "$outfile_path" rm -rf "$build_dir" } upload() { local outfile local uri local -A result outfile="$outfile_path" uri="product/terminal/chroot_integration/""$ORGCODE/${CHANNELID}/$(basename "$outfile")" obsutil cp "$outfile" obs://fae-cdn.linkfog.cn/"$uri" result["url"]="https://fae-cdn.linkfog.cn/""$uri" result["md5"]="$(md5sum "${outfile}" | awk '{print $1}')" mkdir -p .result jq -n --arg url "${result[url]}" --arg md5 "${result[md5]}" '{$url, $md5}' > ".result/${PROJECT_ID}-${PIPELINE_ID}.json" echo ".result/${PROJECT_ID}-${PIPELINE_ID}.json" cat ".result/${PROJECT_ID}-${PIPELINE_ID}.json" rm -f "$outfile" rm -rf "$packge_dir" } export PATH="$PATH:$(pwd)"/tools/ generate_vendor_confg update_hugepall_zipfile upload