Linux Lite 8.0 RC1 has been released - Click here


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Lite Updates Notify - Development
#1

If I switch to sudo in the terminal:

Code:
sudo su

then run:

Code:
rm -rf /var/spool/cron/crontabs/bob && touch /var/spool/cron/crontabs/bob && echo "0 33 */21 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> /var/spool/cron/crontabs/bob

in a terminal, it works as expected.

If I run:

Code:
gksudo lite-updatenotify

from the terminal and set eg. 'Hourly' from the dialogue box, it will always error out. I'm probably missing something very simple, can you see why it is doing this?

Code:
#! /bin/bash
#--------------------------------------------------------------------------------------------------------
# Name: Lite Updates Notify
# Description: Set an Update frequency notification on Linux Lite.
# Authors:  Jerry Bezencon
# Website: https://www.linuxliteos.com
#--------------------------------------------------------------------------------------------------------

# Ensure multi-language support
export LANG=C

# Set the window icon variable
ic="/usr/share/icons/zenity-llcc.png"

# Set user logged in as variable
USERLOGGEDIN=$(whoami)

# Set working dir variable
DIR=/var/spool/cron/crontabs/

# Check if User is member of 'sudo' group
if [ "$(whoami)" != "root" ]; then
    (zenity --info --ok-label="Got it!" --title="You are not an Administrator" \
            --text="\n<b>You need to be an Administrator to use this application</b> \n \nAsk your System Administrator to add you to the <b>sudo</b> group." --no-wrap)
    exit 1

fi

# Lite Updates Notify Titlebar
LUN="Lite Updates Notify"

# UNI Zenity message
UNI="Update Notification Interval"

# Set app icon variable
APPICON=/usr/share/liteupdatenotify/icons/

# Start main dialogue

CHFREQ=$(zenity --title="$LUN" \
--ok-label="Set Frequency" \
--height=360 --width="560" \
--window-icon=$ic \
--list --imagelist --text "Select an Update notification frequency from below:\n" \
--column "  Select  " --column " Frequency" --column " Description" \
"$APPICON/clock.png" " Hourly" " Once every hour eg. 1pm, 2pm, 3pm etc" \
"$APPICON/clock.png" " Every 6 Hours" " First run at midnight, then every 6 hours" \
"$APPICON/clock.png" " Every 12 Hours" " First run at midnight, then every 12 hours" \
"$APPICON/clock.png" " Daily" " Every day at 7pm" \
"$APPICON/clock.png" " Every other Day" " Every other day at 7pm" \
"$APPICON/clock.png" " Weekly" " Once every week at 7pm on a Monday" \
"$APPICON/clock.png" " Every 2 Weeks" " Once every 2 weeks at 7pm on a Monday" \
"$APPICON/clock.png" " Every 3 Weeks" " Once every 3 weeks at 7pm on a Monday")

if [[ "$CHFREQ" =~ " Hourly" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 * * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Every 6 Hours" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 */6 * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Every 12 Hours" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 */12 * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Daily" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Every other Day" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */2 * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Weekly" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */7 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Every 2 Weeks" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */14 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

elif [[ "$CHFREQ" =~ " Every 3 Weeks" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */21 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close

            else

                                        zenity --error \
                                        --title="$LUN" --width=140 --text="An error occured! \n\nPlease try again."
                        fi

exit 0

Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#2

Newly created git here - https://github.com/linuxlite/liteupdatesnotify

Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#3

At first sight:

Code:
USERLOGGEDIN=$(whoami)
will return root. I believe you are looking for the sudoer user...


Code:
USERLOGGEDIN=$(sudo -u ${SUDO_USER:-$USER} whoami)
... that will return 'user' or bob in your example.

Now, we have to also look at:

Code:
rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 * * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN | zenity --progress --title="$LUN" --text="Setting $UNI, please do not interrupt this operation..." --pulsate --auto-kill --auto-close


... because I'm pretty sure user bob does not have read permissions to that location. I will look at this later with more time.

https://unlockforus.com

Sorry for seeming stupid and preferring Linux - I just don't know any better.

[Image: AGxgqJ6.png]
Reply
#4

Thanks Ralphy, it's just that I've been going cross-eyed with all this code lately.

Sent from my Phone using Tapatalk


Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#5

Ok, Jerry. We have to make few changes to make it work:

1) --list and --imagelist will not work together in zenity property.
2) zenity passes the first column values as output from the --list property. In this case the first column in the list was an image... so it returns a 0 (zero) instead of a value such as "Hour, Every 6 Hours, etc." Therefore to make this work, we need to remove --imagelist from zenity properties and make "Frequency" column the first one... Here is a fully working example:

$gksu bash lite-updatenotify.sh

lite-updatenotify.sh

Code:
#! /bin/bash
#--------------------------------------------------------------------------------------------------------
# Name: Lite Updates Notify
# Description: Set an Update frequency notification on Linux Lite.
# Authors:  Jerry Bezencon
# Website: https://www.linuxliteos.com
#--------------------------------------------------------------------------------------------------------

# Ensure multi-language support
export LANG=C

# set the window icon variable
ic="/usr/share/icons/zenity-llcc.png"

# set user logged in as variable
USERLOGGEDIN=$(sudo -u ${SUDO_USER:-$USER} whoami)

# set working dir variable
DIR=/var/spool/cron/crontabs/

# check if User is a member of 'sudo' group
if [ "$(whoami)" != "root" ]; then
    (zenity --info --width=380 --height=80 --ok-label="Got it!" --title="You are not an Administrator" \
            --text="\n<b>You need to be an Administrator to use this application</b> \n \nAsk your System Administrator to add you to the <b>sudo</b> group." --no-wrap)
    exit
fi

LUN="Lite Updates Notify"                   # Lite Updates Notify Titlebar
UNI="Update Notification Interval"          # UNI Zenity message
APPICON=/usr/share/liteupdatenotify/icons/  # Set app icon variable

# Start main dialogue
while (true); do
CHFREQ=$(zenity --list --width="480" --height=320 --title="     $LUN" --ok-label="Set" --cancel-label="Quit" --window-icon=$ic \
--text "Set the Updates notification frequency from the options below:\n" \
--column "     Frequency   " --column "Description" \
" ✔ Hourly" " Once every hour eg. 1pm, 2pm, 3pm etc" \
" ✔ Every 6 Hours" " First run at midnight, then every 6 hours" \
" ✔ Every 12 Hours" " First run at midnight, then every 12 hours" \
" ✔ Daily" " Every day at 7pm" \
" ✔ Every other Day     " " Every other day at 7pm" \
" ✔ Weekly" " Once every week at 7pm on a Monday" \
" ✔ Every 2 Weeks" " Once every 2 weeks at 7pm on a Monday" \
" ✔ Every 3 Weeks" " Once every 3 weeks at 7pm on a Monday" \
" ✘ Disable" "Disable Updates Notification")

if [ "$?" -eq "1" ]; then
    exit 0
fi

if [[ $CHFREQ =~ Disable ]]; then
    zenity --question --title=" $LUN" --text="\nAre you sure you want to disable Lite Updates notifications?"
    confirm=$?
    if [ "$confirm" -eq "0" ]; then
        rm -rf $DIR/$USERLOGGEDIN
        zenity --info --timeout=3 --title=" $LUN" --text="\nNotification Updates have been disabled!"
        exit 1
    else continue
    fi
fi
# set cron schedule
if [[ $CHFREQ =~ Hourly ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 * * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ "Every 6 Hours" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 */6 * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ "Every 12 Hours" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 */12 * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ Daily ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 * * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ "Every other Day" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */2 * * su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ Weekly ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */7 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ "Every 2 Weeks" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */14 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
elif [[ $CHFREQ =~ "Every 3 Weeks" ]]; then
    rm -rf $DIR/$USERLOGGEDIN && touch $DIR/$USERLOGGEDIN && echo "0 19 */21 * 1 su $USERLOGGEDIN -c /usr/local/sbin/updatenotify >/dev/null 2>&1" >> $DIR/$USERLOGGEDIN
fi

if [ "${PIPESTATUS[0]}" -ne "0" ]; then
    zenity --error \
        --title="Error" --text="\n An error occurred while scheduling updates notification."
        continue
    else
        zenity --width=320 --height=60 --info --timeout=3 --title=" $LUN" --text="\nUpdates notification has been successfully scheduled."

fi
done
exit 0




https://unlockforus.com

Sorry for seeming stupid and preferring Linux - I just don't know any better.

[Image: AGxgqJ6.png]
Reply
#6

You are a legend Ralphy. I'll take a look at this when I get home. You have access to the Github repo.

Sent from my Phone using Tapatalk


Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#7

Just be aware that in the previous sample the task is created to execute /usr/local/sbin/updatenotify but there is no such a file there. I didn't change it because I'm not sure if you will be using that location at some point.

Later, I'm off now

https://unlockforus.com

Sorry for seeming stupid and preferring Linux - I just don't know any better.

[Image: AGxgqJ6.png]
Reply
#8

Not a problem, cheers.

Sent from my Phone using Tapatalk


Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#9

I've added quite a bit of code to make the application more interactive.

For example, the user cannot launch the application unless it is in the sudoers group, which in turn asks for administrative password right from the application launch:

Code:
Exec=gksudo /usr/bin/lite-updatenotifiy

I think it would be better suited not to run the application as administrator and give the user the option to elevate:

Code:
Exec=/usr/bin/lite-updatenotifiy

and then ask for elevation once the application is launched:

[Image: ZqVTJeP.png]

I can push what I have to GH if you want.


https://unlockforus.com

Sorry for seeming stupid and preferring Linux - I just don't know any better.

[Image: AGxgqJ6.png]
Reply
#10

Go for it Ralphy.

Sent from my Phone using Tapatalk


Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)