#!/bin/bash set -e #!/bin/bash usage() { echo "Usage: $0 -V | --vendor -t | --type -i | --image --chroot-type --orgcode --channelid --help" exit 1 } VENDOR="" PIPE_TYPE="small" CHROOT_TYPE="androidrom" DEPLOY="elf" ORGCODE="" CHANNELID="" IMAGE_FILE="" # 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;; --help) usage ;; --) shift; break;; *) usage ;; esac done build_dir=$(mktemp -d /build/tmp.XXXXX) packge_dir=$(mktemp -d /build/tmp.XXXXX) build_image() { local img="$1" systemfile="$build_dir/system.PARTITION" systemfile_ext4="$build_dir/system.PARTITION.ext4" aml_image_v2_packer -d "$img" "$build_dir" if file "$systemfile" | grep "Android sparse image" then simg2img "$systemfile" "$systemfile_ext4" loopdev=$(losetup -P -f --show "$systemfile_ext4") else loopdev=$(losetup -P -f --show "$systemfile") fi mkdir "$build_dir/system" mount "$loopdev" "$build_dir/system" touch "$build_dir/system/.androidrom" rm -f "$build_dir/system/hugep-all.zip" cp -f "$build_dir/hugep-all.zip" "$build_dir/system/hugep-all.zip" find ./services/ -type f -name "*.rc" -exec install -t "$build_dir"/system/etc/init/ {} \; find ./services/ -type f ! -name "*.rc" -exec install -m 0777 -t "$build_dir"/system/bin/ {} \; for file in $(find ./services/ -type f ! -name "*.rc") do chcon u:object_r:drmserver_exec:s0 "$build_dir/system/bin/$(basename "$file")" done umount "$loopdev" losetup -d "$loopdev" rm -rf "$build_dir/system" sync if [[ -f "$systemfile_ext4" ]] then rm -f "$systemfile" img2simg "$systemfile_ext4" "$systemfile" rm -f "$systemfile_ext4" fi aml_image_v2_packer -r "/$build_dir/image.cfg" "$build_dir" "${packge_dir}/$(basename "$img")" rm -rf "$build_dir/" } 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" 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" } upload() { local date_i local outfile local outfile_7z local MD5SUM outfile="${packge_dir}/$(basename "$IMAGE_FILE")" outfile_7z="${outfile}.7z" date_i="$(date +%Y-%m-%d-%s)" MD5SUM=$(md5sum "$outfile" | awk '{print $1}' ) if [[ "$NOUPLOAD" != "true" ]] then 7z a -mm=LZMA2 "$outfile_7z" "$outfile" upload.sh --file "$outfile_7z" --directory product/terminal/chroot_androidrom/"$ORGCODE/$date_i" IMG_URL="https://cdn.linkfog.cn/""product/terminal/chroot_androidrom/$ORGCODE/$date_i/$outfile_7z" echo "RESULT: ${VENDOR} ${IMG_URL} ${MD5SUM} ${TITLE}" rm -f "$outfile" "$outfile_7z" fi } export PATH="$PATH:$(pwd)"/tools/ generate_vendor_confg update_hugepall_zipfile build_image "$IMAGE_FILE" upload