automatic update with mintupdate-tool and systemd timer unit

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
belanthor
Level 1
Level 1
Posts: 2
Joined: Sat Sep 30, 2017 6:21 pm

automatic update with mintupdate-tool and systemd timer unit

Post 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]
                       command
 
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 autoupdt.sh

Code: Select all

#!/bin/bash
 
#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://google.com HTTP/1.0\n\n" | nc google.com 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
else
echo "Offline" >> /path/to/your/logfile.log
fi

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

[Unit]
Description=automatic update

[Timer]
OnBootSec=10min
# to start the timer 10 minutes after booting
OnUnitActiveSec=24h
# to restart the timer 24 hours after the last run

[Install]
WantedBy=multi-user.target
3. the service file (here autoupdt.service)

Code: Select all

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

[Service]
ExecStart=/bin/sh /home/torsten/kiste/bin/autoupdt.sh
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
richyrich

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

Post by richyrich »

Instead of posting this on the USER forums, why don't you post this at the Mint Github developer site ?
Post Reply

Return to “Tutorials”