#!/bin/sh

source /etc/prplconfig

(
    # Vendor/board specific firstboot commands
    for file in /usr/bin/reset_soft_*; do [ -f ${file} ] && ${file}; done

    # Reset /etc/uci-defaults state
    [ -f /cfg/failed-uci-defaults ] && rm -rf /cfg/failed-uci-defaults

    if [ -n "$CONFIG_SAH_BOARD_CONFIGURATOR_RAM_OVERLAYFS" ]; then
        rm -rf /cfg/prplos-config /cfg/prplos-config-work
    fi

    # Check if overlayfs is mounted on RAM
    if ! grep -q "^overlayfs:/tmp" /proc/mounts; then
        # Check if the script was called with -r
        firstboot -y || true
    fi
    if [ "$1" = "-r" ]; then
        # Reboot the device
        reboot
    fi
) &
