#!/bin/bash -e
# Prepare Dangerous Pi files for installation

# This script runs OUTSIDE the chroot environment
# It prepares files that will be copied into the image

echo "Preparing Dangerous Pi files..."

# Create temporary directory for files
mkdir -p "${ROOTFS_DIR}/tmp/dangerous-pi-files"

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Copy application structure from the files directory
cp -r "${SCRIPT_DIR}/files/app" "${ROOTFS_DIR}/tmp/dangerous-pi-files/"
cp -r "${SCRIPT_DIR}/files/systemd" "${ROOTFS_DIR}/tmp/dangerous-pi-files/"
cp -r "${SCRIPT_DIR}/files/scripts" "${ROOTFS_DIR}/tmp/dangerous-pi-files/"
cp -r "${SCRIPT_DIR}/files/etc" "${ROOTFS_DIR}/tmp/dangerous-pi-files/"
cp "${SCRIPT_DIR}/files/requirements.txt" "${ROOTFS_DIR}/tmp/dangerous-pi-files/"

# Create VERSION file
echo "0.1.0-$(date +%Y%m%d)" > "${ROOTFS_DIR}/tmp/dangerous-pi-files/VERSION"

# Create empty directories
mkdir -p "${ROOTFS_DIR}/tmp/dangerous-pi-files/data"
mkdir -p "${ROOTFS_DIR}/tmp/dangerous-pi-files/logs"

echo "Files prepared successfully"
