build/docker-build.sh
akadmin efb4feb07b Initial commit: build env for the Ubtouch OS
Change-Id: I4bf8c32811d2785bd86a532f4cb435794f5c14d2
2025-10-08 16:49:47 +03:00

102 lines
2.8 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
# ===============================
# CONFIGURATION
# ===============================
CLEAN_BUILD="${CLEAN_BUILD:-false}"
HALIUM_REPO="${HALIUM_REPO:-https://gitlab.com/ubports/porting/community-ports/halium-generic-adaptation-build-tools.git}"
HALIUM_BRANCH="${HALIUM_BRANCH:-main}"
WORKDIR="$(pwd)"
OUTDIR="${WORKDIR}/out"
OTADIR="${WORKDIR}/ota"
BUILDDIR="${WORKDIR}/build"
# ===============================
# LOGGING FUNCTIONS
# ===============================
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" >&2
}
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
log "Build failed with exit code $exit_code"
fi
}
trap cleanup EXIT
# ===============================
# PREPARE BUILD ENV
# ===============================
if [ "$CLEAN_BUILD" = "true" ]; then
log "Performing clean build: removing previous artifacts"
rm -rf "$OUTDIR" "$OTADIR" "$BUILDDIR"
else
log "Incremental build enabled (set CLEAN_BUILD=true to force wipe)"
fi
mkdir -p "$OUTDIR" "$OTADIR"
# ===============================
# CLONE HALIUM TOOLS
# ===============================
if [ ! -d "$BUILDDIR" ]; then
log "Cloning Halium build tools from $HALIUM_REPO (branch: $HALIUM_BRANCH)"
git clone -b "$HALIUM_BRANCH" "$HALIUM_REPO" "$BUILDDIR"
else
log "Halium build tools already present, pulling latest changes"
(cd "$BUILDDIR" && git fetch && git checkout "$HALIUM_BRANCH" && git pull --rebase) || true
fi
# ===============================
# BUILD KERNEL
# ===============================
log "Starting kernel build..."
"$BUILDDIR/build.sh"
log "Kernel build completed successfully"
# ===============================
# ROOTFS & OTA PREP
# ===============================
DATETIME=$(date +%Y%m%d-%H%M)
DEVICE="$(source deviceinfo && echo "$deviceinfo_codename")"
log "Preparing OTA for device: $DEVICE"
"$BUILDDIR/prepare-fake-ota.sh" "$OUTDIR/device_${DEVICE}.tar.xz" "$OTADIR"
log "Generating system image..."
"$BUILDDIR/system-image-from-ota.sh" "$OTADIR/ubuntu_command" "$OUTDIR"
mv "$OUTDIR/rootfs.img" "$OUTDIR/ubuntu.img"
# ===============================
# PACKAGE ARTIFACTS
# ===============================
cd "$OUTDIR"
log "Compressing ubuntu.img with zstd..."
rm -f ubuntu.img.zst
log "Cleaning generated {init}/boot artifacts inorder to use prebuilt ones"
rm -rf boot.img init_boot.img
log "Copying prebuilt artifacts"
cp -r ../boot.img .
cp -r ../init_boot.img .
zstd -q -f ubuntu.img
ZIPNAME="ubuntu-touch-${DEVICE}-${DATETIME}.zip"
log "Creating flashable zip: $ZIPNAME"
zip -r9 "$ZIPNAME" boot.img init_boot.img *.zst
cd "$WORKDIR"
# ===============================
# DONE
# ===============================
log "======================================="
log "Build completed successfully!"
log "Artifacts available in: $OUTDIR"
ls -lh "$OUTDIR"
log "======================================="