#!/bin/dash

### helpers
#$1-errno $2 text
die() {
	if [ $DISPLAY ]; then
		Xdialog --infobox "$2" 0 0 10000
	else
		dialog --infobox "$2" 0 0
	fi
	exit $1
}

### main
PROGRAM=${0%-spot}
! type $PROGRAM > /dev/null && PROGRAM=${PROGRAM##*/}
if [ "$PROGRAM" = program ]; then
	die 0 "Symlink whatever-spot to me, to launch \"whatever\" as spot." 
fi

! [ $(id -u) = 0 ] && exec $PROGRAM "$@"
SPOT_HOME=$(awk -F: '$1=="spot" {print $6}' /etc/passwd)
#{ chown spot $SPOT_HOME/Downloads;
#chown spot /aufs/devsave/Downloads; } 2> /dev/null
#cd $SPOT_HOME/Downloads
exec /usr/bin/run-as-spot $PROGRAM "$@"
