#!/bin/sh

if mount $*; then
	exit
else
	if sudo -n mount $*; then
		exit
	else
		pass=$(yad --button="OK:0" --button="Cancel:1" --window-icon="drive-harddisk" --title="Mount as root" --image="drive-harddisk" --text "Type in your password to mount the drive.\n" --borders=6 --entry --entry-label="Password:  " --hide-text --on-top --skip-taskbar --center --width=375)

		if [ $? -eq 0 ]; then
			if echo "$pass" | su -c true "$USER"; then
				echo $pass | sudo -S mount $*
			else
				if yad --button="OK:0" --button="Cancel:1" --window-icon="drive-harddisk" --title="Password Incorrect" --image="drive-harddisk" --text "The password is incorrect! Try again." --borders=6 --on-top --skip-taskbar --center --width=375; then
					exec sh -c "~/.icewm/programs/sudo2k/mount2k $*"
				fi
			fi
		else
			exit 1
		fi
	fi
fi
