#!/bin/bash
#########################################################################
#                      Version 0.1.1                                    #
# This will allow root privileges to the users desktop.                 #
# Author <lxgator@gmail.com>                                            #
# ----------------------------------------------------------------------#
# This program is free software; you can redistribute it and/or modify  #
# it under the terms of the GNU General Public License as published by  #
# the Free Software Foundation; either version 3 of the License, or (at #
# your option) any later version.                                       #
#########################################################################

IMAGE="/usr/share/access-root/images/access-root.png"
RICON='/usr/share/access-root/images/error.svg'

# Need root permission
if [ "$EUID" -ne 0 ]; then
`yad --error --width=350 --image=$RICON \
--window-icon=$RICON --center --title=$"Error" \
--text="\n\You need to be root to run Access Root!" --button=Cancel!/usr/share/access-root/images/cancel.svg:0`
exit 0
   else
exec
fi
function main ()
{
$(yad --title="Remove Privileges" \
--width=400 --height=100 \
--text="\n<b>Remove</b> root privileges from user?" \
--image="$IMAGE" \
--center \
--window-icon="$IMAGE" \
--button=No!/usr/share/access-root/images/cancel.svg:0 \
--button=Yes!/usr/share/access-root/images/ok.svg:1)
if [ "$?" = "1" ]; then 
mv /etc/shadow.orig /etc/shadow
sleep 1
$(yad --title='Privileges removed' \
--width=400 --height=100 \
--text="\nRoot privileges for user has been removed\n\nFor security reasons:\nThe user will be logged out of this session" \
--image=$IMAGE \
--center \
--window-icon=$IMAGE \
--button=Ok!/usr/share/access-root/images/ok.svg:0)
E_SESSION=$(who -uH | head -2 | tail -1 | cut -d' ' -f1)
LOGOUT=$(echo $E_SESSION)
pkill -u $LOGOUT 2>/dev/null
fi |
if [ "$?" = "0" ]; then 
yad --notification --image="$IMAGE" --text="Remove root privileges from user?"
exec "/usr/bin/access"
fi
 }
   main
exit 0
