#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -euo pipefail

# Visual feedback
echo "Downloading IMX415 4-Lane Overlay..."

# Define variables
OVERLAY_DIR="/boot/overlays-$(uname -r)"
FILE_NAME="rk3588-axon_v0.3-camera-imx415-csi0-alpha-4lane.dtbo.disabled"
URL="https://vicharak-files.vicharak.in/patch/${FILE_NAME}"

# Ensure script is run with root permissions
if [ "$EUID" -ne 0 ]; then
  echo "Error: Please run this script with sudo or as root." >&2
  exit 1
fi

# Navigate to destination directory
cd "$OVERLAY_DIR"

# Download the file silently
wget -q -O "$FILE_NAME" "$URL"

# Set standard read/write permissions (644) for overlay files
chmod 644 "$FILE_NAME"

echo "Successfully downloaded and configured ${FILE_NAME} in ${OVERLAY_DIR}."
