#!/bin/sh
# ***** BEGIN LICENSE BLOCK *****
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
# ***** END LICENSE BLOCK *****

alterator_api_version=1

. alterator-sh-functions
. install2-sh-functions
. install2-remount-functions

PROG=remount-destination

notify()
{
	[ -z "$AUTOINSTALL" ] || return 0
	alterator-mailbox-send "$1" ||:
}

run_remount_destination()
{
	sync
	if ! remount_destination >&2; then
		notify "error \"Destination filesystem remount error. See /tmp/remount.log\""
		return 1
	fi

	# notify interface about finish
	notify "done #t"
}

on_message()
{
	case "$in_action" in
		write)
			echo "$PROG: write init" >&2
			if [ -z "$AUTOINSTALL" ]; then
				run_remount_destination &
			else
				run_remount_destination
			fi
			;;
	esac
}

message_loop
