#!/bin/bash
# FVWM-Crystal helper script that check for mount changes
# Usage: Exec exec $[FVWM_SYSTEMDIR]/scripts/DesktopCheckMounts <delay [s]>

# debug
#env >> /tmp/examine_env.$$ 2>1&

# the PID to kill if fvwm is interrupted
TMPFILE="/tmp/crystal_desktopcheckmount_$$"
touch ${TMPFILE}

cleanup() {
	rm ${TMPFILE}
	exit 0
}

trap cleanup INT QUIT TERM

# the main loop
CRC=$(mount|cut -d" " -f1)
while :
do
	sleep "$1"
	# fvwm is started by exec; be sure it is running
	pidof fvwm 1>/dev/null || pidof fvwm3 1>/dev/null || cleanup

	NEWCRC=$(mount|cut -d" " -f1)
	if [[ "$NEWCRC" != "$CRC" ]]; then
		CRC="${NEWCRC}"
		if [[ "${FVWM_IS_FVVWM3}" == "1" ]]; then
			FvwmPrompt LoadDesktopIcons
		else
			FvwmCommand LoadDesktopIcons
		fi
	fi
done
