Page 1 of 1

automatic update with mintupdate-tool and systemd timer unit

Posted: Sat Sep 30, 2017 6:33 pm
by belanthor
although the graphical mintupdate is for me the best update tool for several reasons there are still some situations you want to get it more "running automatically in the background"

the new CLI mintupdate-tool does exactly this, combines the functionality of the mintupdate with levels and settings combined with the possibility to run it with cron or in scripts

i decided to start it with the systemd timer, which gives me some more flexibility in configuration

but first the mintupdate-tool:

the help of mintupdate-tool gives the following:

Code: Select all

usage: mintupdate-tool [-h] [-k | -nk] [-s] [-r] [-d] [-y]
                       [--install-recommends] [-l LEVELS]
positional arguments:
  command               a command
optional arguments:
  -h, --help            show this help message and exit
  -k, --kernel          ignore settings and include all kernel updates
  -nk, --no-kernel      ignore settings and exclude all kernel updates
  -s, --security        ignore settings and include all security updates
  -r, --refresh-cache   refresh the APT cache
  -d, --dry-run         simulation mode, don't upgrade anything
  -y, --yes             automatically answer yes to all questions
  --install-recommends  install recommended packages (use with caution)
  -l LEVELS, --levels LEVELS
                        ignore settings and restrict to this list of levels
the possible commands are list and upgrade, which at the moment is not in the help text yet

i wanted just to automatically run the level 1 and 2 updates plus security updates and to refresh the cache, so in my case the full command is

Code: Select all

mintupdate-tool -nk -s -r -y -l 12 upgrade
adding >> logfile.log to write the output to a log file to see what it did (and if it works at all :) )

1. the script itself in this example named

Code: Select all

#add the date to the logfile
d="-------------------------------------------------------------------------------\n $(date +%Y-%m-%d) $(date +%H:%M:%S)\n-------------------------------------------------------------------------------"
echo -e $d >> /path/to/your/logfile.log
#to check if the pc is online
echo -e "GET HTTP/1.0\n\n" | nc 80 > /dev/null 2>&1
if [ $? -eq 0 ]; then
#the actual update
mintupdate-tool -nk -s -r -y -l 12 upgrade &>> path/to/your/logfile.log
echo "Offline" >> /path/to/your/logfile.log

ok for the systemd timer there are several tutorials and wiki pages on the net for further information, therefore here just the timer and service files to put in the /etc/systemd/system folder with root rights

2. the timer file (here autoupdt.timer)

Code: Select all

# file /etc/systemd/system/autoupdt.timer

Description=automatic update

# to start the timer 10 minutes after booting
# to restart the timer 24 hours after the last run

3. the service file (here autoupdt.service)

Code: Select all

# file /etc/systemd/system/autoupdt.service
Description=automatic update

ExecStart=/bin/sh /home/torsten/kiste/bin/
after putting the files to the right place we're ready to start the timer with the following command in terminal

Code: Select all

systemctl enable --now autoupdt.timer
the --now includes the start for the timer

restart the system (and wait 10 mins) to see if it works

i hope i could help a bit these guys who might need something like this and i'm thankful for any recommendations and improvements

Re: automatic update with mintupdate-tool and systemd timer unit

Posted: Sat Sep 30, 2017 8:04 pm
by richyrich
Instead of posting this on the USER forums, why don't you post this at the Mint Github developer site ?