#!/bin/bash

EXTLINUX_CONF="/boot/extlinux/extlinux.conf"
NEW_EXTLINUX_CONF="/tmp/extlinux.conf"

# Read device tree compatible string safely
COMPATIBLE=$(tr -d '\0' < /proc/device-tree/compatible 2>/dev/null)

if echo "$COMPATIBLE" | grep -qi "rk3399-vaaman"; then
    #sudo echo "Board detected: Vicharak Vaaman (RK3399)" >  /tmp/storage.log
    sudo cp "$EXTLINUX_CONF" /tmp/
    if [ -f "$EXTLINUX_CONF" ]; then
        if grep -q "panic=10" "$EXTLINUX_CONF"; then
            echo "Already applied." 
	    exit 1
        else
            # Append panic=10 to the end of the line starting with 'append'
            sudo sed -i '/^\s*append/ s/$/ panic=10/' "$NEW_EXTLINUX_CONF" 
	    sudo cp "$NEW_EXTLINUX_CONF" "$EXTLINUX_CONF" 
       fi
    else
        exit 1
    fi
else
	exit 1
fi
