#!/bin/bash
#
# auto-ER130-restore.sh
#
#
# ※zenityコマンドが必要です。
#

PATH=${PATH}:/usr/local/bin:${HOME}/bin
MEDIAPATH=/media/owner
MOVESH="/home/owner/bin/ER130-move.sh"
CTLSH="/home/owner/bin/er130-ctl.sh"
export DISPLAY=:0.0
export LANG=ja_JP.UTF-8


LABEL=ER130
mountpoint=
if test -n "${LABEL}"; then
mountpoint="${MEDIAPATH}/${LABEL}"
fi


# アンマウント
echo "${mountpoint}";
if test -n "${mountpoint}"; then
TEXT="`sudo umount "${mountpoint}" 2>&1`"
if test $? -eq 0; then
sudo rmdir "${mountpoint}" 2>/dev/null
touch /tmp/Ejection_Success
powerSwitch.USB_Switcher port1
${CTLSH} try_rec
RET=$?
	if test ${RET} -eq 1; then
	TEXT="try_recで異常発生"
	led-blue off
	zenity --error --title "devmon" --text "${TEXT}" &
	exit 1
	elif test ${RET} -eq 2; then
	led-blue off
	exit
	fi
else
led-error on
touch /tmp/Ejection_Failure
echo "${TEXT}"
sendmail
zenity --error --title "devmon" --text "${TEXT}" &
exit 1
fi
fi
led-blue off
exit
