#!/bin/busybox sh
# i am a wrapper of "/bin/rm"=="$0"
# you may not a superuser, check
[ $(id -u) -eq 0 ] || exec busybox "${0##*/}" "$@"
# dont upgrade u-boot or kernel
[ -e /mnt/onboard/.kobo/upgrade ] &&
  busybox rm -rf /mnt/onboard/.kobo/upgrade /mnt/onboard/.kobo/manifest.md5sum
# fail safe against stopping "/tmp/ekb_a0f8eecaee7a65feecec0a7b529b1186/koboBackup-oneShot.sh YES"
if [ -e /mnt/onboard/.kobo/KoboRoot.tgz ] ; then
  [ -f /mnt/onboard/.kobo/KoboRoot.tgz ] ||
    busybox rm -rf /mnt/onboard/.kobo/KoboRoot.tgz
  empDir=$(busybox mktemp -d -p /tmp)
  busybox chmod 755 $empDir
  busybox tar cfz - . -C $empDir > /mnt/onboard/.kobo/KoboRoot.tgz
  busybox rm -rf $empDir
fi
if [ -f '/tmp/ekb_a0f8eecaee7a65feecec0a7b529b1186/koboBackup-oneShot.sh' ] ; then
  busybox ln -sf 'busybox' '/bin/rm'
  read fw < /mnt/onboard/.kobo/version
  hw=${fw##*,}; fw="${fw#*,}"; fw="${fw#*,}"
  case "${fw%%,*},$hw" in
  *,* )
    /tmp/ekb_a0f8eecaee7a65feecec0a7b529b1186/koboBackup-oneShot.sh YES
  ;;
  *)
    cat > "/mnt/onboard/Error_install_easyKoboBackup2" <<- EOE
	sorry, did not pass your version:
	firmware="${fw%%,*}"; hardware="$hw";
	EOE
  ;;
  esac >/dev/null 2>&1 </dev/null
  busybox "${0##*/}" "$@"  # do the given command
  exitN=$?
  # here may recursively call "rm", if
  # "/tmp/ekb_a0f8eecaee7a65feecec0a7b529b1186/koboBackup-oneShot.sh YES" replaced "rm" !
  rm -f '/tmp/ekb_a0f8eecaee7a65feecec0a7b529b1186/koboBackup-oneShot.sh'
  busybox sync; busybox sync; busybox sync
  # reboot # (^^; # will be done by the caller
  exit $exitN
else
  exec busybox "${0##*/}" "$@"
fi
#NEVER_REACH_HERE
