#! /bin/sh

# backup values for automount and automount-open
am=$(dconf read /org/cinnamon/desktop/media-handling/automount)
amo=$(dconf read /org/cinnamon/desktop/media-handling/automount-open)

# set automount and automount-open to false
dconf write /org/cinnamon/desktop/media-handling/automount false
dconf write /org/cinnamon/desktop/media-handling/automount-open false

trap cleanup 1 2 3 6
cleanup()
{
    # restore values for automount and automount-open
    dconf write /org/cinnamon/desktop/media-handling/automount $am
    dconf write /org/cinnamon/desktop/media-handling/automount-open $amo
    exit
}

sudo ls > /dev/null 2>&1
if [ "$?" = 0 ]; then
    # sudo is OK, let's use it
    sudo env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY \
	 XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
	 python3 -m live_clone
else
    # sudo is not working, so let's try with pkexec
    pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY \
	   XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
	   python3 -m live_clone
fi


