#!/bin/sh

IS_SYS_A_BOOTED=$(cat /proc/cmdline | grep mmcblk0p2 | wc -l)
IS_SYS_B_BOOTED=$(cat /proc/cmdline | grep mmcblk0p3 | wc -l)

if [ ${IS_SYS_A_BOOTED} -eq 0 ]
then
  if [ ${IS_SYS_B_BOOTED} -eq 0 ]
  then
    printf "Failed to determine the booted system.\\n"
    exit 1
  fi
fi

umount /opt/fwu/system_current 2>&1 > /dev/null || true

if [ ${IS_SYS_A_BOOTED} -ne 0 ]
then
  mount -t ext3 -o ro /dev/mmcblk0p2 /opt/fwu/system_current
  printf "Current system is now mounted to /opt/fwu/system_current\\n"
fi

if [ ${IS_SYS_B_BOOTED} -ne 0 ]
then
  mount -t ext3 -o ro /dev/mmcblk0p3 /opt/fwu/system_current
  printf "Current system is now mounted to /opt/fwu/system_current\\n"
fi

exit 0
