For anyone who still needs or wants GKSU

I still need GKSU for a variety of applications. Or, at least, I want it since the alternatives are, for the moment, less than convenient. So, I have found the following solution that works for me. I have not detected any unforeseen issues as of yet (I have been running it for a few days now). But, if you decide to do this for yourself, you must accept full responsibility and so should not execute the following commands if you are unsure what you are doing.

Anyway, the above, said, here is how to reinstate GKSU:

Add artful repositories to the system

cat <<EOF | sudo tee /etc/apt/sources.list.d/artful.list
deb http://archive.ubuntu.com/ubuntu/ artful main universe
deb-src http://archive.ubuntu.com/ubuntu/ artful main universe
EOF

Update package cache

sudo apt-get update

Install necessary build tools

sudo apt-get install build-essential debhelper dpkg-dev

Install build-dependencies for gksu and compile its source package

sudo apt-get build-dep gksu
sudo apt-get source --compile gksu

Install self-compiled gksu packages:

sudo apt-get install ./*gksu*.deb

Test gksu (should work on Xorg-sessions)

gksu-properties # check that it has "Authentication mode" to "sudo"
gksu date
gksudo date

Remove artful repository from system for safety

sudo rm /etc/apt/sources.list.d/artful.list
sudo apt-get update

Original source for the above method can be found here:

Dear @stevecook172001 !

Could you please kindly add a link to the my original answer on AskUbuntu “How to install an application that requires gksu package on ubuntu 18.04?”?

Or at least mention me as an author of the method?
We live in FOSS world, not in copy-and-paste without references.

Any positive feedback will be gratefully appreciated too (here or on AskUbuntu) :slight_smile:

1 Like

No problem Norbert.

I wasn’t trying to pass it off as mine mate. I had just copied and pasted it into a text file last week and then couldn’t be arsed to find the original source.

Not a very good excuse. But it’s the truth…:slight_smile:

1 Like

Actually Norbert - while you are here, there is one outstanding issue with the above method. It’s not a biggie, but it would be nice to nail it down.

It concerns the invocation of gksu in the middle of a program being run. So, for example, if I double click a deb file to open with gdebi-gtk, it will open as requested. But, if I then try to install it, it would ordinarily bring up the gksu dialog at the point. With the current (reinstated) gksu, it is not doing that. The way I get round it, at present, is by opening gdebi-gtk with gksu, then opening the deb file from inside gedbi-gtk. Then installing. It would be nice to get gksu to open once inside gdebi-gtk (or any other program, presumably, that needs this function).

After adding the Artful repo, wouldn’t it be simpler to just install the gksu package rather than compiling it from source? Is there a reason to build it?

1 Like

You are right, it was too complicated. I have tested your idea, it works great.
So I edited answer on AskUbuntu. As with self-compiled packages we have two locally-installed packages (gksu and libgksu2-0).

Updated method is as follows:

  1. Add artful repositories to the system:

     cat <<EOF | sudo tee /etc/apt/sources.list.d/artful.list
     deb http://archive.ubuntu.com/ubuntu/ artful universe
     EOF
    
  2. Update package cache

     sudo apt-get update
    
  3. Install gksu package

     sudo apt-get install gksu
    
  4. Test gksu (should work on Xorg-sessions)

     gksu-properties # check that it has "Authentication mode" to "sudo"
     gksu date
     gksudo date
    
  5. Remove artful repository from system for safety

     sudo rm /etc/apt/sources.list.d/artful.list
     sudo apt-get update
    

Thank you!

I do not know what to do with this. Currently many packages are in migration stage - from gksu to pkexec. So this will be fixed soon.

1 Like

I found a simple script that acts like gksu.
Create a file called gksu, copy and paste the following in the file, make the file executable and copy it in your path (i.e. /usr/bin or .local/bin).
In advance it uses pkexec instead of gksu.
I tried it with my caja scripts and it works nice.

#!/bin/bash

sentinel="##@@##"
if [[ $(id -u) != “0” ]]; then
absScriptPath="$( cd “$(dirname “$0”)” ; pwd -P )/$(basename “$0”)"
pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" “$absScriptPath” “$sentinel” “$@”
exit 0
fi
# root here
if [[ “$1” == “$sentinel” ]]; then
shift
fi

$@

You can also add the following alias in your ~/.bashrc:

alias gksu='pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS'

2 Likes

Alternative way by using a bash script as a replacement for gksu:

Needs zenity for gui password dialog, so you’ll need

sudo apt-get install zenity

Here’s the script:

#!/bin/bash
#
# gksu replacement
# 
# save as /usr/local/bin/gksu
# mark executable: chmod +x /usr/local/bin/gksu
# set readonly for all, writable for root and group root
# use gksu command as usual

# exit, if no gui
if ! [ x$DISPLAY != x ] ; then
  echo "no gui detected - exiting!"
  exit 1
fi

# fetch command to execute
execcmd=$@

# fetch current user name
curuser=$(whoami)

# message to show
msg="sudo $execcmd\n\nEnter password for $curuser:"

# request user password
if PASS=$(zenity --entry --hide-text --text "$msg" --title "GKSU" 2> /dev/null); then
  if ! [ -z $PASS ]; then
    # check if password is valid
    echo "$PASS" | sudo -S -i -k pwd > /dev/null 2> /dev/null
    if ! [ $? -eq 0 ]; then
      # password is not valid: show warning
      zenity --warning --no-wrap --text "The password supplied was invalid!" --title "GKSU" 2> /dev/null
    else
      # password is valid: execute command
      echo "$PASS" | sudo -S -i -k $execcmd 2> /dev/null
      # eval exit code of command
      if ! [ $? -eq 0 ]; then
        zenity --warning --no-wrap --text "The command supplied could not be executed!" --title "GKSU" 2> /dev/null
      fi
    fi
  else
    # empty password: show warning
    zenity --warning --no-wrap --text "An empty password was supplied!" --title "GKSU" 2> /dev/null
  fi
fi

# clean exit
exit 0