#!/bin/sh

dump_autostart() {
    dfpath="$SNAP_USER_DATA/.config/autostart/foo.desktop"

    test -e "$dfpath" && return

    echo "generating autostart file $dfpath"

    mkdir -p $SNAP_USER_DATA/.config/autostart
    cat <<EOF > $dfpath
[Desktop Entry]
Name=foo autostart
Exec=/foo/bar/baz/bin/foobar --autostart a b c
EOF
}

case "$1" in
    --autostart)
        echo "autostarting with args '$@'" | tee $SNAP_USER_DATA/foo-autostarted
        ;;
    *)
        echo "regular run with args '$@'"
        dump_autostart
        ;;
esac
