Gksu replacement in gtk3


#1

I wrote a simple replacement for gksu using the dialog function of spacefm:

#!/bin/bash
eval "`spacefm -g --label "Authentication needed for $USER" --hbox --label "Password" --password --button cancel --button ok --title Spacesu`"

echo -e $dialog_password1 | sudo -S $@

It is not quite as sophisticated gksu, but works for simple cases.

Features to be added (hopefully):

  • authentication icon
  • handling for wrong password
  • remembering password like gksu?

Ideas, feedback?


#2

The script’s spacefm dependency totally ruins any possibility of this being used as a generic tool. Not quite sure what is your purpose here or what problem you are trying to solve.


#3

This modified version of similar zenity script, testing if I can make it work without zenity.

I wrote the original zenity script for bspwm edition, with the intention of avoiding gtk2 dependency.

So, intention is to have graphical authentication dialog without gtk2. Spacefm is installed anyway on the target system, so I don’t mind that.

I could make it use zenity or spacefm depending on what is installed?


#4

Gotcha. I was going to suggest zenity too, since it fits the role of a script dependency so much better. And it will allow you to extend the script functionality much more easily.

If you wish to work with spacefm (can’t think of a reason why you would want to do that) go for it. But zenity is the type of tool one would expect. It’s particularly powerful for your purposes because you can just as well integrate it with python instead of bash.


#5

I cannot. Someone who knows python could :slightly_smiling_face:

Spacefm seems to have more configuration options for dialog than zenity, which got me interested. Yad has that too I suppose…


#6

Maybe I’ll add a check in the beginning to see what is installed, in order if preference (and assumed rarity): yad, spacefm, zenity.


#7
#!/bin/sh
if [ -e /usr/bin/spacefm ]
	eval "`spacefm -g --label "Authentication needed for $USER" --hbox --icon dialog-password-symbolic.symbolic --password --button cancel --button ok --title Spacesu`"
	PASSWD="$(echo $dialog_password1)"
elif [ -e /usr/bin/yad ]; then
	PASSWD="$(yad --entry --entry-label "Password" --hide-text --image=dialog-password-symbolic.symbolic --text="Authentication needed for $USER" --title=spacesu --center)"
else
	PASSWD="$(zenity --password --title =Authentication)\n"
fi

echo -e $PASSWD | sudo -S $@

Now it supports also yad any zenity. Also icons now.

Next up error handling.


#8
#!/bin/sh
if [ -e /usr/bin/spacefm ]; then
	eval "`spacefm -g --label "Authentication needed for $USER" --hbox --icon dialog-password-symbolic.symbolic --password --button cancel --button ok --title Spacesu`"
	PASSWD="$dialog_password1"
elif [ -e /usr/bin/yad ]; then
	PASSWD="$(yad --entry --entry-label "Password" --hide-text --image=dialog-password-symbolic.symbolic --text="Authentication needed for $USER" --title=spacesu --center)"
else
	PASSWD="$(zenity --password --title =Authentication)"
fi

if ! [ -z "$PASSWD" ]; then
	echo "$PASSWD" | sudo -S "$@"
fi

if [ $? = 1 ]; then 
	if [ -e /usr/bin/spacefm ]; then
		eval "`spacefm -g --label "Wrong password, retry" --hbox --icon dialog-password-symbolic.symbolic --password --button cancel --button ok --title Spacesu`"
		PASSWD="$dialog_password1"
	elif [ -e /usr/bin/yad ]; then
		PASSWD="$(yad --entry --entry-label "Password" --hide-text --image=dialog-password-symbolic.symbolic --text="Wrong password, retry" --title=spacesu --center)"
	else
		PASSWD="$(zenity --password --title="Wrong password, retry")"
	fi
	echo "$PASSWD" | sudo -S "$@"
fi

Now it tolerates one failed password attempt.