Involves 4-5 files, first open your file manager of choice with privileges or otherwise navigate to the following location /usr/local/bin and create two scripts, named mine autoup.sh and am using the terminator terminal emulator in it. Here's the contents.
Code: Select all
#!/bin/bash
CHK=$(apt list --upgradable | wc -l)
sudo apt update
if [ "$CHK" -gt "1" ]; then # If there's more than 1 line returned by apt list, there are upgrades available.
terminator -e "bash -c 'sudo /usr/local/bin/autoup2.sh'"
fi
If the value of the CHK variable is -gt (greater than) 1 terminator opens and -e runs bash, which itself runs a command -c (the script.) It runs the other script we need to create here, named the one I used autoup2.sh and here's its contents.
Code: Select all
#!/bin/bash
echo
echo "* SYSTEM UPDATE: The following packages have upgrades available. *"
echo
apt list --upgradable
echo
echo
read -n1 -p " * To proceed with the system upgrade now ... Press 1. " UP
echo
if [[ $UP =~ ^[1]$ ]]; then
sudo apt -y upgrade -s
else
exit 0
fi
# Of course also remove the -s(simulated switch from the apt cmd above. So it actually does the upgrade.
Okay next up it's time to add one of those, (the 1st script) to a file in sudoers.d, if you don't have one ... GOOGLE DAMMIT, ... it is a good idea to do a bit of research about sudoers.d for real, I created a file here named myrules it's located in the following directory /etc/sudoers.d and just to be excruciatingly anal ... Here's the contents of it, various stuff and scripts I've added to it, so that I can run sudo commands without having to enter a password. You of course don't need much of that ... Sheesh, some I don't use anymore ... anyway.
Code: Select all
# Adding some sudo commands I don't need passwd for.
your-user-name-here ALL=(ALL) NOPASSWD: /usr/sbin/pm-suspend, /usr/bin/renice, /sbin/iw, /sbin/iwlist, /sbin/iwconfig, /usr/bin/systemd-analyze, /sbin/reboot, /sbin/poweroff, /usr/bin/smem, /usr/local/bin/backup.sh, /usr/local/bin/pgov.sh, /usr/sbin/iftop, /usr/bin/eject, /usr/local/bin/rootfm.sh, /usr/local/bin/logout.sh, /usr/local/bin/autoup.sh
Whew, we're getting there ... Next up ... Time to make more files at the following location /etc/systemd/system. Create two files here, one ending with .timer the other .service and name them the same thing. In my case that ended up being update.timer and here's the contents.
Code: Select all
[Unit]
Description=Timer to help update junk.
Requires=update.service
[Timer]
OnCalendar=*-*-* 18,22:30:00
Persistent=true
[Install]
WantedBy=timers.target
Code: Select all
[Unit]
Description=auto updates via script
After=graphical.target
Wants=network-online.target update.timer
[Service]
Type=simple
User=your-user-name-here
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/your-user-name-here/.Xauthority
ExecStart=/bin/bash -c 'sudo /usr/local/bin/autoup.sh'
[Install]
WantedBy=graphical.target
OnCalendar=*-*-* 18,22:30:00
00:00:00 is midnight = otherwise it's just military time, 12:00:00 is noon, 18:30:00hrs = 6:30pm. Clearly you can set them to run more than once by separating in this case, the hour field with comma's.
Was pretty weird at first and will help a person to keep fiddling with the timer units time settings, then "systemctl daemon-reload" and checking the changes as to when the timer unit is next going to be run with "systemctl status update.timer" Will use that to track them for awhile and make sure they're functioning properly. Running on schedule and successfully completing. As of yet, it's only ran a couple times but appears to be doing fine.Clarification: This 18,22:30:00 ... 22:30:00 = 10:30pm, then the next one as shown, add a ,(comma) and 18:30:00 there = 6:30pm
Another handy command seems to be "systemctl list-timers" will display all timer units active on the system. As will "systemctl status *.timer" Shows the active timer units and when they're sched to run. Also it's good to know you can check your service unit, by running it manually at any time "sudo systemctl start update.service". At some point will get around to setting it to only 2-3dys per wk, as twice daily and at system start is kind of overkill for Debian stable. Plenty of info about what the different time fields in a systemd timer mean and timer units overall. Though am still nowhere near a guru about any of it. Got a helluva headache by this point but shared.
None of this comes with express/implied warranty of course. Took pains here but there you have it. Hopefully helps people out, at least and gives them a good trick or 3. That's a wrap.