#!/bin/sh
# Unmount file for PuppyRus ("Ext2", "Ext3", "Ext4", "SquashFS", "ISO")
#VERSION 3.6
if [ ! "$1" ]; then
  echo "Usage: $(basename "$0") FILE" >&2; exit 1
fi

[ -f "$1" ] && mntfile="$(realpath "$1")" || mntfile="$1"
mntpoint=/mnt/$(echo "${mntfile}" | tr ' ' '_' | sed "s#^\.##g" | sed "s#/#+#g")
status=0

if [ -d "${mntpoint}" ]; then
  sync
  busybox umount -d "${mntpoint}"
  status=$?
  rmdir "${mntpoint}" 2>/dev/null
  [ ${status} -gt 0 ] && echo "Unmount \"${mntfile}\" failed!"
  sync
else
  echo "$(basename "$0"): File \"${mntfile}\" is not mounted!"; status=1
fi

exit ${status}
