Thursday, May 2, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 7688  / 2 Years ago, thu, march 17, 2022, 7:54:09

I've been curious if there is a way to make it so that the Update Manager can check for updates say every few hours rather than daily. Now, I know that I can run sudo apt-get update to check, but it would be nice to have it show it to me more often...I love having the most up to date system that I can.


More From » update-manager

 Answers
3

I use two scripts, one that runs in the background whenever I am logged in, and one that is allowed through sudo without a password to apt-get update and additionally download packages.



You can download the two scripts I wrote here, or copy and paste them into gedit from below:
http://ubuntuone.com/0tNctmQnF2peAsUmaqtyo3



These are the two scripts I wrote:

The first should be called 'background-runner':



#! /bin/bash

# This will connect and download any new packages every two hours.
# Ideal for use on the development release to save time.
# Downloads almost all packages, not just security releases.
sleep 10m

while true; do
sudo /usr/local/bin/package-downloader update
sleep 120m
done


And the second should be called 'package-downloader':



#! /bin/bash
# This runs as root and is allowed through sudo to only download packages.

if [ $1 = 'update' ]; then
apt-get update
fi

if [ $1 = 'download' ]; then
apt-get update
apt-get --yes --download-only upgrade
fi


To set this up, download or copy and paste the files into gedit and save the files with the names noted above. cd to their location in the terminal and run the following commands:



sudo cp package-downloader background-runner /usr/local/bin
sudo chmod +x /usr/local/bin/package-downloader /usr/local/bin/background-runner


Now we have to allow the package-downloader script through sudo.
Open a terminal and type



sudo visudo


at the bottom of the file add the following line replacing MYUSER with the username you run as, and then hit ctrl+x and then enter to save.



 MYUSER ALL=(root) NOPASSWD: /usr/local/bin/package-downloader


Now navigate to 'Startup Applications.' Click add. Name it whatever you like, and enter /usr/local/bin/background-runner for the command. Save this and exit out.
enter image description here



Having logged out and logged back in, the scripts will perform an apt-get update every two hours. You might want to disable the automatic check for updates through the Update Manager's Software Sources dialogue, which you can reach by clicking settings in the bottom left corner. This way update-manager will not check for updates when the script is already doing so more frequently.
enter image description here



The scripts linked here will just do apt-get update by default. If you would like them to also download any packages, you simply need to edit the line in background-runner that says:



 sudo /usr/local/bin/package-downloader update


and have it say



 sudo /usr/local/bin/package-downloader download


The same can be done for changing the amount of time in between updates and downloads, just change 120m in



 sleep 120m


to your desired amount of time in minutes (m) hours (h) seconds (s).



FYI: This could potentially be a security risk if the permissions to /usr/local/bin have been changed. Because package-downloader is a script, and allowed through sudo, BE SURE ONLY ROOT CAN WRITE TO IT!


[#39092] Friday, March 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rhaeams

Total Points: 115
Total Questions: 111
Total Answers: 103

Location: Burundi
Member since Wed, Nov 25, 2020
4 Years ago
rhaeams questions
;