#!/sbin/openrc-run

command=/usr/bin/true

depend()
{
	use net
}

status()
{
	/usr/bin/true
}

stop()
{
	PATH=/usr/sbin:/usr/bin:/sbin:/bin

	DIRS=""
	while read -r DEV MTPT FSTYPE OPTS REST; do
		if [ "$FSTYPE" = "fuse.potatofs" ]; then
			DIRS="$MTPT $DIRS"
		fi
	done < /etc/mtab

	if [ "$DIRS" ]; then
		fstab-decode umount -f -l $DIRS
	fi

	ALL_DONE=1
	for i in 1 2 3 4 5 6 7 8 9 10; do
		# Currently we can only test a single mountpoint
		# since we don't know which configuration is tied
		# to that mountpoint.
		if ! potatoctl status >/dev/null 2>&1; then
			ALL_DONE=0
		fi
		[ $ALL_DONE -eq 1 ] && break
		sleep 1
	done
}
