vsido-exit (systemd based logout script for VSIDO)

hakerdefo

Hi there Snap,
Thanks for the feedback. As I mentioned in my previous post I'll shortly be moving this over to GitHub and there I'll update the instruction on screen-lock helpers to reflect your suggestion.
Cheers!!!
You Can't Always Git What You Want

PackRat

QuoteI know it works with spectrwm, I'm curious if it works with dwm. Did you try it with your dwm build?

Quote from: ozitraveller on February 03, 2017, 03:23:07 AM
Jwm.  I did a quick build this morning before work.

I installed dwm, the script works as intended; good deal, dwm doesn't always work well with session management tools.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

Quote from: PackRat on February 03, 2017, 02:02:42 PM
QuoteI know it works with spectrwm, I'm curious if it works with dwm. Did you try it with your dwm build?

Quote from: ozitraveller on February 03, 2017, 03:23:07 AM
Jwm.  I did a quick build this morning before work.

I installed dwm, the script works as intended; good deal, dwm doesn't always work well with session management tools.

That's fantabulous  8)

I would again say this script wouldn't have been possible without PackRat.
It was his idea (Remember, he started the thread at code challenge).
And when I was happy and content with,
fluxbox-remote exit
for logout, it was PackRat who pushed me further  8)
And not to forget all the testing he has done  8)
Thanks a metric ton PackRat  :)

Cheers!!!
You Can't Always Git What You Want

PackRat

^ thanks, nice work writing the script.

Some simple tweaking - a bit of over-engineering for a script like this, but I wanted some practice.

Two changes:

the logout command is now:

loginctl terminate-session "$XDG_SESSION_ID

so no more parsing through awk. And the commands are now set up as variables so all a user/administrator has to do is change the variable to whatever custom command they want to use.

#!/usr/bin/env bash

LOGOUT="loginctl terminate-session "$XDG_SESSION_ID""
SUSPEND="systemctl suspend"
REBOOT="systemctl reboot"
POWEROFF="systemctl poweroff"

vslo_menu (){
vslo_ttle="vsido-logout"
vslo_clas="$vslo_ttle"
vslo_wico="/usr/share/pixmaps/logout_window_small.png"
vslo_wico_big="/usr/share/pixmaps/logout_window_big.png"
type xtrlock >/dev/null 2>&1
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
type dm-tool >/dev/null 2>&1
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
type slock >/dev/null 2>&1
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
type i3lock >/dev/null 2>&1
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
type light-locker >/dev/null 2>&1
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
type xscreensaver >/dev/null 2>&1
RETVAL=$?
if ! [[ "$RETVAL" == 0 ]]; then
vslo_main=$(yad --class="$vslo_clas" --title="$vslo_ttle" --window-icon="$vslo_wico" --center --fixed --on-top --buttons-layout=center --button="Cancel!!Cancel:1" --button="Logout!!Logout of VSIDO:3" --button="Suspend!!Suspend VSIDO:4" --button="Reboot!!Reboot VSIDO:5" --button="Shutdown!!Shutdown VSIDO:6")
fi
fi
fi
fi
fi
fi
vslo_main=$(yad --class="$vslo_clas" --title="$vslo_ttle" --window-icon="$vslo_wico" --center --fixed --on-top --buttons-layout=center --button="Cancel!!Cancel:1" --button="Lock Screen!!Lock the screen:2" --button="Logout!!Logout of VSIDO:3" --button="Suspend!!Suspend VSIDO:4" --button="Reboot!!Reboot VSIDO:5" --button="Shutdown!!Shutdown VSIDO:6")
vslo_main=$?
case "$vslo_main" in
1)
exit 1
;;
2)
type xtrlock >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
xtrlock -b
exit 0
fi
type dm-tool >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
dm-tool lock
exit 0
fi
type slock >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
slock
exit 0
fi
type i3lock >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
i3lock
exit 0
fi
type light-locker >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
light-locker-command -l
exit 0
fi
type xscreensaver >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
xscrsav=$(which xscreensaver)
active_xscrsav=$(pidof "$xscrsav")
if [[ -z "$active_xscrsav" ]]; then
xscreensaver -no-splash &
sleep 1
xscreensaver-command -lock
exit 0
fi
fi
xscrsav_user=$(ps -p "$active_xscrsav" -o ruser=)
xscrsav_user_id=$(id -u "$xscrsav_user")
current_user_id=$(id -u)
if [[ "$xscrsav_user_id" == "$current_user_id" ]]; then
xscreensaver-command -lock
exit 0
fi
if [[ "$current_user_id" == 0 ]]; then
su "$xscrsav_user" -c "xscreensaver-command -lock"
exit 0
fi
yad --title="$vslo_ttle" --class="$vslo_clas" --window-icon="$vslo_wico" --borders=20 --center --fixed --image="$vslo_wico_big" --on-top --button=gtk-ok --text="xscreensaver was started by another user.\nso current user can't use the lock function.\nauto-start xscreensaver with your session.\n"
exit 0
;;
3)
$LOGOUT
exit 0
;;
4)
$SUSPEND
exit 0
;;
5)
$REBOOT
exit 0
;;
6)
$POWEROFF
exit 0
;;
130)
exit 1
;;
252)
exit 1
;;
esac
}
while :
do
vslo_menu
done


@hackerdefo - or anyone that likes to see the icons in the dialog box, I shrank the icons to 22x22 and think it looks better. The icons do not overpower the text in the dialog box.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

Thanks for the ideas PackRat. Assigning commands to variables can make editing the script easy. And I'm in the process of updating the script so these suggestions will be implemented in the new version.
Cheers!!!
You Can't Always Git What You Want

ozitraveller

I just have one small comment to make:


130)
exit 1
;;
252)
exit 1
;;


Could we have a comment or variable to indicate what 130 and 252 mean, my memory isn't what it used to be.

:)


PackRat

#66
I think 130 is Script Terminated by CTL-c - which I think a user would only see if the script is run from a terminal and CTL-c issued when the terminal - not the dialog box - has focus. That stanza may be superfluous.

I think 252 is so the close button will function if a user leaves the dialog window decorated. Can't verify that one though.
Edit - sort of verified it. Comment out that sections and the close button no longer functions.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

jedi

Quote from: VastOne on February 02, 2017, 02:54:20 AM
This is a cleaned up version of V2 that hakerdefo created that has all the buttons and no icons and a cancel.. I also changed the title

Looks like this - Plain Jane Version - 34 Lines of code with 821 characters and all functional - A thing of beauty IMO thank you hakerdefo!



This is now the default for VSIDO

Very Nice VastOne!!!  Just added love the looks of it.  Small is nice!  Works as advertised.  Thanks to everyone who worked on this...
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

ozitraveller

Quote from: PackRat on February 06, 2017, 02:16:42 PM
I think 130 is Script Terminated by CTL-c - which I think a user would only see if the script is run from a terminal and CTL-c issued when the terminal - not the dialog box - has focus. That stanza may be superfluous.

I think 252 is so the close button will function if a user leaves the dialog window decorated. Can't verify that one though.
Edit - sort of verified it. Comment out that sections and the close button no longer functions.

Thanks PackRat!

hakerdefo

#69
It is released to the public  8)

It is now known as lepo-logout  ;D

Many things have been improved  :)

Here is the link to the GitHub repo,

lepo-logout on GitHub

Cheers!!!
You Can't Always Git What You Want

PackRat

Quote from: hakerdefo on February 09, 2017, 08:29:29 PM
Many things have been improved  :)

Care to elaborate? There a changelog somewhere.

It works - well done. Just did a quick proof read. Looks like the big change are the yad boxes (?) asking for a password if a user needs use sudo to shutdown or reboot.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

hakerdefo

#71
It now better handles inhibition locks. Avoid them when it can and ask when it can't.
It also handles multiuser scenario a bit better. root or superuser can reboot-shutdown evenif other users are logged in.
It can now reboot-shutdown system even without polkit.
Many improvements, wouldn't you agree?
Cheers!!!
You Can't Always Git What You Want

PackRat

Was cleaning up some other scripts so went ahead and added hibernate to the vsido-exit script should anyone want that. Haven't tested it, my harddrive with VSIDO bought the farm; should work though, standard systemctl command.



#!/usr/bin/env bash
vslo_menu (){
vslo_ttle="What would you like to do?"
vslo_clas="$vslo_ttle"
vslo_wico="/usr/share/icons/icon.png"
vslo_main=$(yad --title="$vslo_ttle" --class="$vslo_clas" --window-icon="$vslo_wico" --width="648" --height="48" --center --fixed --on-top --buttons-layout=center  --button="Cancel!! Cancel:1" --button="Logout!$vslo_bute!Logout of VSIDO:2" --button="Suspend!$vslo_buts!Suspend VSIDO:3" --button="Hibernate!$vslo_buts!Hibernate VSIDO:4" --button="Reboot!$vslo_butr!Reboot VSIDO:5" --button="Shutdown!$vslo_butq!Shutdown VSIDO:6")
vslo_main=$?
case "$vslo_main" in
1 | 252)
exit 1
;;
2)
id_of_session=$(loginctl session-status | head -n 1 | awk '{print $1}')
loginctl terminate-session "$id_of_session"
exit 0
;;
3)
systemctl suspend
exit 0
;;
4)
systemctl hibernate
exit 0
;;
5)
systemctl reboot
exit 0
;;
6)
systemctl poweroff
exit 0
;;
esac
}
while :
do
vslo_menu
done

I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

PackRat

Was bored, reworked the session exit script to vertical:

#!/bin/sh

yad --form --class=VsidoExit --width=165 --borders=5 --height=320 --undecorated --skip-taskbar --image=/home/doug/temp/vsido.png --image-on-top --center \
--field="  Log Out!gnome-logout!Log Out":fbtn "pkill `wmctrl -m | awk '/Name/ {print tolower($2)}'`" \
--field="  Hibernate!gnome-session-hibernate!Hibernate":fbtn "systemctl hybernate" \
--field="  Suspend!gnome-session-suspend!Suspend":fbtn "systemctl suspend" \
--field="  Restart!system-reboot!Restart":fbtn "systemctl reboot" \
--field="  Shut Down!gnome-shutdown!Shut Down":fbtn "systemctl poweroff" \
--button=gtk-cancel \


Cropped logo -


I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo