#!/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"
ABOUT="/usr/share/access-root/images/about.png"
RICON='/usr/share/access-root/images/error.svg'

# Need root permission

if [ "$EUID" -ne 0 ]; then
`yad --error --width=375 --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
# Check if access-root is running
AR=$(ps -ef | grep "access" | grep -v grep | wc -l)
if [ ${AR} -gt 7 ]; then
`yad --error --width=375 --image=$RICON \
--window-icon=$RICON --center --title=$"Error" \
--text="\n\Access Root application is already running!" \
--button=Ok!/usr/share/access-root/images/ok.svg:0`
exit 0
fi
function main() {
if [ -s /etc/shadow.orig ]
then
mv /etc/shadow.orig /etc/shadow
fi
cp /etc/shadow /etc/shadow.orig
$(yad --title="Access Root" \
--width=400 --height=100 \
--text=$"\n<b>Add</b> root privileges for this user?" \
--center \
--image="$IMAGE" \
--button=About!/usr/share/access-root/images/about.svg:3 \
--button=No!/usr/share/access-root/images/cancel.svg:0 \
--button=Yes!/usr/share/access-root/images/ok.svg:4 \
--window-icon="$IMAGE")
if [ "$?" = "4" ]; then
cd /etc
awk 'NR>1' /etc/shadow > /etc/shadow.new
cp '/etc/shadow.new' '/etc/shadow' 
awk -v n=1 -v s="root::15661:0:99999:7:::" 'NR == n {print s} {print}' shadow > shadow.new
cp '/etc/shadow.new' '/etc/shadow' 
rm -f '/etc/shadow.new'
sleep 0.50
yad --notification --image="$IMAGE" --text=$'Remove root privileges?'
sleep 0.50
exec "/usr/bin/access"
fi |
if [ "$?" = "0" ]; then
mv /etc/shadow.orig /etc/shadow | 
yad --title='Operation Canceled' \
--width=400 --height=100 \
--text=$'\nNo changes were made to the system.' \
--image="$IMAGE" \
--center \
--window-icon="$IMAGE" \
--button=Ok!/usr/share/access-root/images/ok.svg:0 
pkill -SIGKILL "access" 2>/dev/null
pkill -SIGKILL "access-root" 2>/dev/null
fi |
if [ "$?" = "3" ]; then 
yad --info \
--title="Access Root" \
--window-icon="$IMAGE" \
--center \
--image="$ABOUT" \
--width=300 \
--button="Cancel!/usr/share/access-root/images/cancel.svg:0"
exec "access-root" 
fi 
 }
   main
exit 0


