271 lines
9.1 KiB
Bash
271 lines
9.1 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# TEE supplicant service package build script for AMLbian
|
|
# This script builds tee-supplicant systemd service and init script package
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "${SCRIPT_DIR}")"
|
|
AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # Go up one more level from multimedia/tee
|
|
AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # Go up one more level from scripts
|
|
BUILD_DIR="${AMLBIAN_DIR}/../build"
|
|
|
|
# Source common functions
|
|
if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
|
|
source "${AMLBIAN_DIR}/lib/function-common.sh"
|
|
fi
|
|
|
|
# ==============================================================================
|
|
# Section 2: Default Configuration
|
|
# ==============================================================================
|
|
|
|
ARCH="${ARCH:-arm64}"
|
|
BOARD="${BOARD:-s6-bq201}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: TEE Supplicant Service Build Functions
|
|
# ==============================================================================
|
|
|
|
# Main Installation Function
|
|
function __tee_supplicant_install() {
|
|
local install_dir="${1}"
|
|
|
|
display_alert "TEE-SUPP" "Installing tee-supplicant service files" "info"
|
|
|
|
# Service files are expected to be in amlbian/lib/multimedia/optee-userspace
|
|
local service_dir="${AMLBIAN_DIR}/scripts/multimedia/tee/optee-userspace"
|
|
|
|
mkdir -p "${install_dir}/usr/bin"
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
|
|
# Install systemd service file
|
|
local service_file="${service_dir}/tee-supplicant.service"
|
|
if [[ -f "${service_file}" ]]; then
|
|
mkdir -p "${install_dir}/usr/lib/systemd/system"
|
|
install -m 0644 "${service_file}" "${install_dir}/usr/lib/systemd/system/"
|
|
display_alert "TEE-SUPP" "Installed systemd service file: ${service_file}" "debug"
|
|
else
|
|
display_alert "TEE-SUPP" "Systemd service file not found: ${service_file}" "error"
|
|
fi
|
|
|
|
# Install init script
|
|
local init_script="${service_dir}/tee-supplicant.init"
|
|
if [[ -f "${init_script}" ]]; then
|
|
mkdir -p "${install_dir}/etc/init.d"
|
|
install -m 0755 "${init_script}" "${install_dir}/etc/init.d/tee-supplicant"
|
|
display_alert "TEE-SUPP" "Installed init script: ${init_script}" "debug"
|
|
else
|
|
display_alert "TEE-SUPP" "Init script not found: ${init_script}" "error"
|
|
fi
|
|
|
|
display_alert "TEE-SUPP" "Service files installed to ${install_dir}" "success"
|
|
return 0
|
|
}
|
|
|
|
# Debian Package Creation
|
|
function __tee_supplicant_create_deb() {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
local pkg_arch="${ARCH}"
|
|
|
|
# Package details
|
|
local pkg_name="tee-supplicant"
|
|
local pkg_version="1.0.0"
|
|
local pkg_maintainer="Amlbian Builder <[email protected]>"
|
|
local pkg_description="tee-supplicant systemd service and init script"
|
|
local pkg_description_long="This package provides systemd service and SysV init script for tee-supplicant daemon (part of OPTEE userspace). It depends on optee-userspace package which provides the actual binary."
|
|
|
|
display_alert "TEE-SUPP" "Creating Debian package ${pkg_name}_${pkg_version}_${pkg_arch}.deb" "info"
|
|
|
|
# Create package directory structure
|
|
local deb_dir="${build_dir}/deb/${pkg_name}-${pkg_version}"
|
|
local debian_dir="${deb_dir}/DEBIAN"
|
|
|
|
mkdir -p "${debian_dir}"
|
|
|
|
# Copy installed files to package directory
|
|
if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then
|
|
cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true
|
|
display_alert "TEE-SUPP" "Copied installed files to package directory" "debug"
|
|
else
|
|
display_alert "TEE-SUPP" "No installed files found in ${install_dir}" "error"
|
|
return 1
|
|
fi
|
|
|
|
# Create control file with dependency on optee-userspace
|
|
cat > "${debian_dir}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${pkg_version}
|
|
Architecture: ${pkg_arch}
|
|
Maintainer: ${pkg_maintainer}
|
|
Depends: optee-userspace
|
|
Description: ${pkg_description}
|
|
${pkg_description_long}
|
|
Section: admin
|
|
Priority: optional
|
|
EOF
|
|
|
|
# Create postinst script for systemd service
|
|
cat > "${debian_dir}/postinst" << 'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
case "$1" in
|
|
configure)
|
|
# Update ldconfig cache
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
|
|
# Enable systemd service if systemd is available
|
|
if command -v systemctl >/dev/null 2>&1 && [ -f /usr/lib/systemd/system/tee-supplicant.service ]; then
|
|
systemctl daemon-reload >/dev/null 2>&1 || true
|
|
systemctl enable tee-supplicant.service >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
# Update init.d scripts if systemd is not used
|
|
if [ ! -x /bin/systemctl ] && [ -f /etc/init.d/tee-supplicant ]; then
|
|
update-rc.d tee-supplicant defaults >/dev/null 2>&1 || true
|
|
fi
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${debian_dir}/postinst"
|
|
|
|
# Create prerm script
|
|
cat > "${debian_dir}/prerm" << 'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
case "$1" in
|
|
remove|deconfigure)
|
|
# Stop service if running
|
|
if [ -f /etc/init.d/tee-supplicant ]; then
|
|
/etc/init.d/tee-supplicant stop >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
if command -v systemctl >/dev/null 2>&1 && [ -f /usr/lib/systemd/system/tee-supplicant.service ]; then
|
|
systemctl stop tee-supplicant.service >/dev/null 2>&1 || true
|
|
systemctl disable tee-supplicant.service >/dev/null 2>&1 || true
|
|
fi
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
# Create postrm script
|
|
cat > "${debian_dir}/postrm" << 'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
case "$1" in
|
|
purge|remove)
|
|
# Update ldconfig
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
|
|
# Clean up systemd service
|
|
if [ -f /usr/lib/systemd/system/tee-supplicant.service ]; then
|
|
rm -f /usr/lib/systemd/system/tee-supplicant.service
|
|
systemctl daemon-reload >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
# Clean up init.d scripts
|
|
if [ -f /etc/init.d/tee-supplicant ]; then
|
|
update-rc.d -f tee-supplicant remove >/dev/null 2>&1 || true
|
|
rm -f /etc/init.d/tee-supplicant
|
|
fi
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "${debian_dir}/postrm"
|
|
|
|
# Build Debian package
|
|
cd "${build_dir}/deb"
|
|
dpkg-deb --build "${pkg_name}-${pkg_version}" >/dev/null 2>&1
|
|
|
|
local deb_file="${pkg_name}-${pkg_version}.deb"
|
|
if [[ -f "${deb_file}" ]]; then
|
|
# Move to output directory
|
|
local output_dir="${BUILD_DIR}/output"
|
|
mkdir -p "${output_dir}"
|
|
mv "${deb_file}" "${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${pkg_version}_${pkg_arch}.deb"
|
|
display_alert "TEE-SUPP" "Package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${pkg_version}_${pkg_arch}.deb" "success"
|
|
return 0
|
|
else
|
|
display_alert "TEE-SUPP" "Failed to build Debian package" "error"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
function amlbian_build_tee_supplicant() {
|
|
# Check if optee-userspace is enabled
|
|
if ! is_unit_enabled "tee-supplicant" && ! is_unit_enabled "optee"; then
|
|
display_alert "[SKIP] >> tee-supplicant disabled (optee-userspace not enabled)" "" "info"
|
|
return
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Building tee-supplicant service package ${ARCH} ${BOARD}" "info"
|
|
|
|
# Create build directory structure
|
|
local build_root="${BUILD_DIR}/.tmp/tee-supplicant-build-${ARCH}"
|
|
local build_dir="${build_root}/build"
|
|
local install_dir="${build_root}/install"
|
|
|
|
rm -rf "${build_root}"
|
|
|
|
# Create directories
|
|
mkdir -p "${build_dir}" "${install_dir}"
|
|
|
|
display_alert "AMLOGIC: Build directory: ${build_dir}" "info"
|
|
display_alert "AMLOGIC: Install directory: ${install_dir}" "info"
|
|
display_alert "AMLOGIC: output_dir ${BUILD_DIR}/output" "info"
|
|
|
|
# Install tee-supplicant service files
|
|
if ! __tee_supplicant_install "${install_dir}"; then
|
|
display_alert "AMLOGIC: tee-supplicant installation failed" "error"
|
|
return 1
|
|
fi
|
|
|
|
# Create Debian package
|
|
if ! __tee_supplicant_create_deb "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: Package creation failed" "error"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: tee-supplicant service package build completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLIbian TEE Supplicant Service Build Script" "Arch: ${ARCH}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_tee_supplicant
|
|
|
|
display_alert "AMLOGIC: tee-supplicant service package build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-tee-supplicant.sh
|
|
# ============================================================================== |