#!/bin/bash usage() { echo "Usage: $0 -V | --vendor -t | --type -i | --image --chroot-type --orgcode --channelid --packtype --help" exit 1 } VENDOR="" PIPE_TYPE="small" CHROOT_TYPE="androidrom" DEPLOY="elf" ORGCODE="" CHANNELID="" IMAGE_FILE="" PACK_TYPE="other" # new append NOUPLOAD="false" LOCAL="false" export PATH=${PATH}:$(pwd)/tools/ PARSED_ARUGMENTS=$(getopt -a -n "$0" -o V:t:i: --long help,vendor:,type:,image:,chroot-type:,orgcode:,channelid:, -- "$@") eval set -- "${PARSED_ARUGMENTS}" while : do case "$1" in -V | --vendor) VENDOR="$2"; shift 2 ;; -t | --type) PIPE_TYPE="$2"; shift 2 ;; -i | --image) IMAGE_FILE="$2"; shift 2 ;; --chroot-type) CHROOT_TYPE="$2"; shift 2 ;; --orgcode) ORGCODE="$2"; shift 2;; --channelid) CHANNELID="$2"; shift 2;; --packtype) PACK_TYPE="$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 yaml_file="$build_dir"/vendor.yaml yaml_file_src="$build_dir"/vendor.yaml.src cp vendor.yaml.src "$yaml_file_src" sed -i'' "s#__VENDOR__#$VENDOR#g" "$yaml_file_src" sed -i'' "s#__ORGCODE__#$ORGCODE#g" "$yaml_file_src" sed -i'' "s#__CHROOT_TYPE__#$CHROOT_TYPE#g" "$yaml_file_src" sed -i'' "s#__DEPLOY__#$DEPLOY#g" "$yaml_file_src" sed -i'' "s#__CHANNEL_ID__#$CHANNELID#g" "$yaml_file_src" sed -i'' "s#__PACK_TYPE__#$PACK_TYPE#g" "$yaml_file_src" aio -m enc -i "$yaml_file_src" -o "$yaml_file" } update_hugepall_zipfile() { local yaml_file local hugep_zip_file local hugep_zip_file_origin yaml_file="$build_dir"/vendor.yaml hugep_zip_file="$build_dir/hugep-all.zip" hugep_zip_file_origin="./services/hugep-all.zip" cp "$hugep_zip_file_origin" "$hugep_zip_file" zip -u -j "$hugep_zip_file" "$yaml_file" outfile_path="$packge_dir/$VENDOR-$ORGCODE-$CHANNELID-hugep-all.zip" mv "$hugep_zip_file" "$outfile_path" rm -rf "$build_dir" } upload() { local date_i local outfile local uri local random_num local -A result outfile="$outfile_path" date_i="$(date +%Y-%m-%d-%s)" random_num=$(< /dev/urandom tr -dC 0-9a-z | head -c 8) [[ -z "$URL_TAG" ]] && URL_TAG="${date_i}-${random_num}" uri="product/terminal/chroot_androidrom/""$ORGCODE/${date_i}-${URL_TAG}/$(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