Forum › Forums › General › Tips and Tricks › Update notifier – low resources script to check and install updates
- This topic has 34 replies, 6 voices, and was last updated Feb 26-2:01 pm by Lead Farmer.
-
AuthorPosts
-
February 16, 2023 at 4:05 pm #99700Member
Lead Farmer
One of the thing that is missing in Antix, is update notification,you can install apt-notifier, but I didn’t like that it takes a lot of resources for doing nothing most of the time (see image1).
Although I’m only starting to mess around with bash and fish, I made this bash to notify if there is update and the option install them.
#!/bin/bash # Set this bash scrip with crontab to check and install updates export DISPLAY=:0.0 UPGRADS_NUM=$(apt list --upgradable | wc -l) # Set X and Y where the massage will show on your screen X=1366 Y=768 if [[ $UPGRADS_NUM != 1 ]]; then yad \ --borders=20 \ --timeout=60 \ --title="Update Available" \ --text="You can update $(($UPGRADS_NUM-1)) packages" \ --geometry=200x120+$X+$Y \ --button='Install:bash -c "/usr/local/bin/yad-updater"' \ --button="Cancel:1" fi exit 0Set X and Y where on the screen the notification will show, if you want the notification to show at bottom right no matter the screen resolution is replace X and Y with:
X=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1) Y=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)You can set script to run every period with crontab, I set mine to run every day at 13:05
05 13 * * * /home/oren/Documents/upgradable_massage.sh#######
EDIT: This will only show unupgraded packages since the last update see posts #99815 and #99840 about doing update check before showing the massage.- This topic was modified 2 months, 3 weeks ago by Lead Farmer.
- This topic was modified 2 months, 2 weeks ago by Lead Farmer.
- This topic was modified 2 months, 2 weeks ago by Lead Farmer.
Attachments:
February 16, 2023 at 4:28 pm #99711MemberPPC
::Nice idea!
I dabbled with that problem (checking for updates) before and I came up with a solution in FT10- if no updates were performed in the last X days (by default 8) remind the user, once a day, to check for updates, running antiX-Updater (it also does the same that your script does- it tells users how many packages can be upgraded, considering the information provided by the last time you ran “apt update”.Unfortunately, I think that your script only checks for the number of packages that you did not upgrade, since you last updated the available package list. By this I mean that I think this script does not check if there are new versions of the packages in the Repositories… I may be wrong on that assumption…
Edit: I just checked and I think I was right… If you want, I can share the code of my update-reminder script here- the idea is similar to your’s and you can adapt it to be a cron job (my idea is to perform the check if there’s need to remind the user to update twice a day- ideally in the middle of the morning and in the middle of the after noon) and also always at startup (that can be done adding the script to the startup file of your window manager). Also, anacron is “better” for that task, because, if the computer was off when the check should have been made, it will notice that and run the script. I did not study this, but I seem to recall that I did not use anacron because anticapitalista told me it can use system resources (power, on laptops).
P.
- This reply was modified 2 months, 3 weeks ago by PPC.
- This reply was modified 2 months, 3 weeks ago by PPC.
February 16, 2023 at 5:50 pm #99721MemberLead Farmer
::Unfortunately, I think that your script only checks for the number of packages that you did not upgrade, since you last updated the available package list. By this I mean that I think this script does not check if there are new versions of the packages in the Repositories… I may be wrong on that assumption…
I think I understand what you mean about only checking for the number of packages that you did not upgrade.
I think I will rewrite the script with $(sudo apt update) and let it run a few time a day, and if a sudo permission was giving recently it will show notification if there is an update.
February 16, 2023 at 6:07 pm #99727MemberPPC
::My suggestion? For what you want to do, a tiny script with simple yad window, asking if the user wants to check for updates (yes: runs antiX-updater; no: exits) will sufice.
something like (adapting your original script):#!/bin/bash # Set this bash script with crontab to check and install updates export DISPLAY=:0.0 # Set X and Y where the massage will show on your screen X=1366 Y=768 yad \ --borders=20 \ --timeout=60 \ --title="Update Reminder" \ --text="Do you want to check for updates now?" \ --geometry=200x120+$X+$Y \ --button='OK:bash -c "/usr/local/bin/yad-updater"' \ --button="Cancel:1" fiIn case you find my idea of a script to remind users to check for updates only if they have not done so in x days, here is my script (you can select after how many days without updating the script should “act” in the variable “days_to_wait_before_warning”
#!/bin/bash #Non instrusive script to remind users to check for updates every X days_to_wait_before_warning, or always warn users, if there are updatable packages in the system. Works on Debian systems (but has to be adapted to run on an OS other than antiX). Originally concieved to be called from anacron, once a day. #By PPC, as part of the ft10-transformation package, full GPL license, 2/2/22 #This script is run under the name: /usr/local/bin/ft10-update-reminder.sh ### Localization ### TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=ft10-update-reminder #Allow only one instance of the script at a time: scriptname=ft10-update-reminder.sh for pid in $(pidof -x $scriptname); do if [ $pid != $$ ]; then exit 1 fi done ##Only run script if it was not already ran before on current day (check if file /tmp/ft10-update-reminder-ran exits with today's date) touch /tmp/ft10-update-reminder-ran last_check=$(cat /tmp/ft10-update-reminder-ran) today=$(date +%x) if [[ $today == $last_check ]]; then status="Already warned user to check for updates today" exit else echo $today > /tmp/ft10-update-reminder-ran #save date of check to a file and then run Main script: #Main script: days_to_wait_before_warning=8 date_of_last_update=$(stat -c %y /var/lib/apt/periodic/update-success-stamp| cut -d" " -f1) today=$(date +%Y-%m-%d) let DIFF=(<code>date +%s -d $today</code>-<code>date +%s -d $date_of_last_update</code>)/86400 test_for_available_updates=$(apt list --upgradable | wc | awk '{print $1;}') available_updates=$(expr $test_for_available_updates - 1) if [ "$available_updates" -gt "0" ]; then Warning=$" There are, at least $available_updates available updates "; fi if [ $DIFF -ge $days_to_wait_before_warning ]; then #check if a network connection is available, if no network is detected, exit network_check=$(ping -c 1 -q google.com >&/dev/null; echo $?) if [ "$network_check" -eq "0" ]; then status="You are connect to a network"; else status="No network available"; exit; fi yad --borders=10 --image="/usr/share/icons/papirus-antix/48x48/emblems/emblem-important.png" --undecorated --geometry=280x50-40-50 --window-icon="software-sources" --title="antix Updater" --text=$"It's been $DIFF days since you last checked for updates.You should check for updates now. $warning" --button="x" --button=$"Check for Updates":"bash -c 'kill $YAD_XID & gksudo ft10-yad-updater'" reminder-window-id=$YAD_XID else #Even if user ran "apt update" recently, always warn if there are upgrades available. reminder-window-id=$YAD_XID if [ "$available_updates" -gt "0" ]; then yad --borders=10 --image="/usr/share/icons/papirus-antix/48x48/emblems/emblem-important.png" --undecorated --geometry=280x50-40-50 --window-icon="software-sources" --title="antix Updater" --text="$Warning" --button=$"Update":"bash -c 'pkill yad & gksudo ft10-yad-updater'" --button="x" reminder-window-id=$YAD_XID fi exit fi kill $reminder-window-id #close if-fi loop from check if user was already warned today: fi- This reply was modified 2 months, 3 weeks ago by PPC.
- This reply was modified 2 months, 3 weeks ago by PPC.
- This reply was modified 2 months, 3 weeks ago by PPC.
February 16, 2023 at 6:26 pm #99731MemberLead Farmer
::My suggestion? For what you want to do, a tiny script with simple yad window, asking if the user wants to check for updates (yes: runs antiX-updater; no: exits) will sufice.
something like (adapting your original script):This is a good idea that I will do for now. although I don’t need scrip for that I can writ the yad in crontab as is.
Thanks
P.S I will try writing a the same scrip with “apt-cache policy” I thing it possible to check if all the packages are update, if not notify.
~> apt-cache policy gimp gimp: Installed: 2.10.32-0.1~mx21+1 Candidate: 2.10.32-0.1~mx21+1 Version table: *** 2.10.32-0.1~mx21+1 100 100 /var/lib/dpkg/status 2.10.22-4 500 500 http://ftp.de.debian.org/debian bullseye/main amd64 Packages- This reply was modified 2 months, 3 weeks ago by Lead Farmer.
- This reply was modified 2 months, 3 weeks ago by Lead Farmer.
- This reply was modified 2 months, 3 weeks ago by Lead Farmer.
February 16, 2023 at 6:53 pm #99736MemberPPC
::I will try writing a the same scrip with “apt-cache policy” I thing it possible to check if all the packages are update, if not notify.
You will probably have the same problem you had with your initial script- if you have not updated the list of packages available from the Repository (with apt update), it probably will only show the info related to the list of packages that you haven’t upgraded since you last ran apt update… I think you are mixing the upgrade and the update parts of apt…
P.
February 16, 2023 at 7:00 pm #99737MemberLead Farmer
::You will probably have the same problem you had with your initial script- if you have not updated the list of packages available from the Repository (with apt update), it probably will only show the info related to the list of packages that you haven’t upgraded since you last ran apt update… I think you are mixing the upgrade and the update parts of apt…
From I understand “apt-cache policy” search in the repository if a package exist, so it will show the latest version, no?
February 17, 2023 at 8:27 am #99793MemberRJP
::Actually my script is not update notifier, but it checks and install updates. The script need Xterm and zenity installed, and I have activated root account.
The script:
#!/bin/sh zenity --question --text "Would you like to check and install updates?" if [ $? = 0 ]; then xterm -e su -c 'xterm -e apt-get update && sleep 3 && apt-get -y upgrade' root && zenity --info --text "System Upgraded" else exit 0 fi- This reply was modified 2 months, 3 weeks ago by RJP.
- This reply was modified 2 months, 3 weeks ago by RJP.
Attachments:
February 17, 2023 at 9:40 am #99800MemberPPC
::From I understand “apt-cache policy” search in the repository
The command’s name referes to “cache”. Why do you assume it searches in the repository, and not in the “cache” of information (in your hard drive) about the packages available in the repository (that is updated every time you run “apt update”)?
I also had to learn stuff like that, when I began trying to do more with Linux other than simply using the tools that ere provided out of the box. Like in every new subject, we have to do our research and study…The script need Xterm and zenity installed, and I have activated root account.
Xterm can be replaced by the default terminal and “zenity” can be replaced with yad, if you wanted to avoid having those dependencies… And I hope that what you said does not mean that you always use the root account! That can be dangerous! Also the “-y” flag can be dangerous, that was vastly talked about in my “antiX-updater” thread…
In all, your script does more or less the same what antiX-updater does. so antiX already has a GUI tool to perform that task (the version I updated, that is still not in the repository even has the option to upgrade automatically without using the dangerous “-y” flag… For your system’s security, please do check out how it’s done and apply the same changes to your script…- This reply was modified 2 months, 3 weeks ago by PPC.
February 17, 2023 at 10:51 am #99815MemberLead Farmer
::One way to fix the problem is to use the apt-notifier updater to check for updates and then run the scrip.
#!/bin/bash # Set this bash scrip with crontab to check and install updates export DISPLAY=:0.0 $(/lib/apt-notifier/bin/updater_reload_run) UPGRADS_NUM=$(apt list --upgradable | wc -l) # Set X and Y where the massage will show on your screen X=1366 Y=768 if [[ $UPGRADS_NUM != 1 ]]; then yad \ --borders=20 \ --timeout=60 \ --title="Update Available" \ --text="You can update $(($UPGRADS_NUM-1)) packages" \ --geometry=200x120+$X+$Y \ --button='Install:bash -c "/usr/local/bin/yad-updater"' \ --button="Cancel:1" fi exit 0I didn’t been able to hide the apt-notifier updater when running the scrip
- This reply was modified 2 months, 3 weeks ago by Lead Farmer.
February 17, 2023 at 11:06 am #99817MemberPPC
::@Lead Farmer – keep testing and you’ll see if I was correct in what I told you: I have not testes this latest version of your script, but by reading it, it seems to only run “antiX-Updater” when “apt list” returns information that there are updates available. How does “apt list” get that information? I assume it checks the version number of all installed .deb packages on your system against the list of available packages and respective version numbers, that you got from the last time you run “apt update” (updating the list that your pc stores, in it’s hard drive, of available packages and their version numbers, that the Repository reports as being available).
The way to learn is by making mistakes – I learned a lot seeing what did not work and learning why it did not work… until I find out what works and why it works…
Edit: as far as I know, the only way to automatically update any Operaing System (Linux, Windows, Mac, Android, Ios, MacOs, whatever) is having a way to check regulary if there are updates available. There are several ways around that – the most common is having a process always running on the background, checking at a set interval, if there are any new updates. On my update remind script, I choose to go a lighter route, like you- have no process always running, but only summon it at set intervals, so it checks for updates (or in my case, in a less intrusive way, warns users that it’s been a long time since they last checked for updates and gives them the chance to do so. You can clean up my script and make it always run antiX-Updater, if you have not done so in x days (you can change it, for example, to once a day). But that is needless complicated- like I advised, just change your script so it always runs the updater when you call it from the cron job.- you can edit antiX-updater and create a different script that does not warn if there are no updates- that way, the user only has to do something (other than entering the password) if there are updates available… and there are ways to avoid having to enter the password, for programs that require it…
P.
- This reply was modified 2 months, 3 weeks ago by PPC.
February 17, 2023 at 11:21 am #99820MemberLead Farmer
::@Lead Farmer – keep testing and you’ll see if I was correct in what I told you: I have not testes this latest version of your script, but by reading it, it seems to only run “antiX-Updater” when “apt list” returns information that there are updates available. How does “apt list” get that information? I assume it checks the version number of all installed .deb packages on your system against the list of available packages and respective version numbers, that you got from the last time you run “apt update” (updating the list that your pc stores, in it’s hard drive, of available packages and their version numbers, that the Repository reports as being available).
The way to learn is by making mistakes – I learned a lot seeing what did not work and learning why it did not work… until I find out what works and why it works…
P.
It looks like apt-notifier updater dues the same thing as sudo apt update.
Any way I’m abandoning this scrip for now and use apt-notifier even if it takes +20MB of RAM
- This reply was modified 2 months, 3 weeks ago by Lead Farmer.
Attachments:
February 17, 2023 at 11:36 am #99823MemberRJP
::And I hope that what you said does not mean that you always use the root account!
No I do not. You can see from the script that regular user can run the script as root (
xterm -e su -c 'xterm -e the-script-here' root). If using sudo, the script is different and you need to write password twice.The script:
#!/bin/sh zenity --question --text "Would you like to check updates?" if [ $? = 0 ]; then xterm -e sudo apt-get update else exit 0 fi zenity --question --text "Would you like to install updates?" if [ $? = 0 ]; then xterm -e sudo apt-get upgrade && zenity --info --text "System Upgraded" fi exit 1- This reply was modified 2 months, 3 weeks ago by RJP.
- This reply was modified 2 months, 3 weeks ago by RJP.
February 17, 2023 at 11:43 am #99825MemberPPC
::It’s a nice idea, and I think you were almost there…
Because I did not run your script (I did run it now), I realize that performing the update by calling “apt-notifier” did not require entering a password… But also, this is a bit redudant – if you wanted to avoid using that tool in the first place, and end up writing a script that relies on it, right?
I would advise, replacing the line $(/lib/apt-notifier/bin/updater_reload_run)
for
apt updateFor this to work you have to make sure that “apt update” does not require you to enter a password (adapt what this page says:https://askubuntu.com/questions/74054/run-apt-get-without-sudo#74083 ) and apply it to “apt update”
February 17, 2023 at 2:18 pm #99840MemberLead Farmer
::@PPC At the end I decided not to mess with the sudo.
I did edit file /lib/apt-notifier/bin/updater_reload_run that it will not show the updater window but still run the updater check.
I changed the end toTITLE="${UPDATER}: $RELOAD" RUN=/usr/lib/apt-notifier/actions/updater_reload_action MSG="apt-get update" #updater_show "$MSG" "$RUN" "$TITLE" "$ICON" "$ICON_KDE" $RUN exitAnd run the script I post in #99815 once a day with crontab.
####
Edit:this don’t work see post #99916- This reply was modified 2 months, 2 weeks ago by Lead Farmer.
- This reply was modified 2 months, 2 weeks ago by Lead Farmer.
-
AuthorPosts
- You must be logged in to reply to this topic.





