#!/bin/bash
set -e
cd "$(dirname "$0")"

ZIP="driver-manager-v1.0.0.zip"
rm -f "$ZIP"

# Include built APK if available
mkdir -p apk
RTL_APK="tools/rtl_tcp_andro/app/build/outputs/apk/release/app-release-unsigned.apk"
if [ -f "$RTL_APK" ]; then
    cp "$RTL_APK" apk/rtl_tcp_andro.apk
    echo "Including rtl_tcp_andro APK"
fi

FILES=(
    module.prop
    customize.sh
    post-fs-data.sh
    service.sh
    system.prop
    system/
    webroot/
    scripts/
    BUILDING_MODULES.md
)

# Include APK dir if it has files
if [ -f "apk/rtl_tcp_andro.apk" ]; then
    FILES+=(apk/)
fi

zip -r9 "$ZIP" "${FILES[@]}" \
    -x "*.git*" "build.sh" "tools/*" "README*"

echo "Built: $ZIP ($(du -h "$ZIP" | cut -f1))"
