#!/bin/sh
source /etc/preinit
script_init

echo "current firmware: $(currentFirmware)"
printSoftwareInfo

firmware="$1"
if [ "$firmware" != "auto" ] && [ "$firmware" != "_nand_" ]; then
  firmware="$(echo "$firmware" |  sed -re 's/^\/usr\/share\/games\/(nes\/kachikachi\/)?/\/var\/games\//')"
  firmware="$(readlink -f "$firmware")"
  checkFirmware "$firmware" || exit 1
fi

[ "$cfg_firmware" == "$firmware" ] && exit 0
cfg_firmware="$firmware"
save_config

[ "$(currentFirmware)" == "$firmware" ] && exit 0
[ "$(currentFirmware)" == "auto" ] && exit 0 #?

state_path="/var/saves/$modname"
state_file="$state_path/menu"
rm -f $state_file

echo "changing firmware to: $firmware"
reboot
exit 0
