#!/bin/sh

# Apply IPAM404 configuration files
IPAM_TYPE=$(qiba-spi-get-production-info.sh -b)
if [ "$IPAM_TYPE" == "10" ]; then
    sed -i 's/mmcblk0/mmcblk1/g' /etc/qiba-update-client.conf
    sed -i 's/mmcblk0/mmcblk1/g' /etc/fw_env.config
    sync
fi

CONFIG_FILE="/mnt/shadow/config.json"
if ! [ -e $CONFIG_FILE ]; then
    # We only apply first boot logic on successfully initialized devices.
    exit 0
fi

ROOTPW=$(jq -r ".rootPasswordHash" $CONFIG_FILE)
if ! [ -z "$ROOTPW" ]; then
    usermod -p "$ROOTPW" root
    sync
fi

update-rc.d -f qiba-first-boot remove
