[HOWTO] Self updating OSMC Distribution (Not recommended for inexperienced users)

Hi, its been awhile since ive done one of these with that said here is a small tutorial on how to get OSMC self-updating, this can cause breakage if a bad package is added to the repositories remember that so its a good idea to have some Linux skills if you want a self-updating OSMC installation.

DISCLAIMER
this might disqualify you from getting official support since this is not a supported way to getting updates. This is the official Debian way of getting automated updates but its not the official way for OSMC (Sam and the rest of the team recommends users to always use MyOSMC).

Pre-installation issues: Disable updates in MyOSMC so they dont fight over lock status in APT. With all of these fair warnings lets get to it first we need to install using these instructions.

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
sudo rm /etc/apt/apt.conf.d/50unattended-upgrades 
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

then add this content

Unattended-Upgrade::Origins-Pattern {
        "o=Debian,n=jessie";
        "o=Debian,n=jessie-updates";
        "o=Debian,n=jessie,l=jessie-Security";
        "o=OSMC,n=jessie,l=OSMC"                        
};

Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::MinimalSteps "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::SyslogEnable true;
Acquire::http::Dl-Limit "512";

These commands will update OSMC and Debian automatically every day if updates are found, it will also throttle downloads to 512kb/sec and it will fix interrupted installations if there are any it will also install using minimal steps in order to make it more safe. Also it will cleanup every 7th day and last but not least it will remove unnecessary packages.

Next up is to make this run periodically with the following command

sudo nano /etc/apt/apt.conf.d/20auto-upgrades

add this content to

APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";

to check if it work try this command

sudo unattended-upgrade --dry-run --debug

too add more repositories do

sudo apt-cache policy

from that command you can grab additional repositories that are not covered in this tutorial, for more information on unattended-upgrades check: UnattendedUpgrades - Debian Wiki

p.s there is ways to blacklist packages like kernel etc if you dont want that to update and even kodi just google unattended-upgrades blacklist, also you can setup mail whenever it runs and updates packages so you get a report on what was upgraded.

This file can give you a clue of something goes wrong

cat /var/log/unattended-upgrades/unattended-upgrades-dpkg.log

Target platform: All
Tested platform: RPI3, RPI2, RPI1

6 Likes

Secondary warning: this is advanced configuration so if you dont have much Linux experience please dont attempt this cause it will automated your installation and if something breaks and you dont know where to look it can get difficult for you.

Some continuation of this howto is to make the distribution reboot if kernel packages are installed or of Kodi is updated this is the next step is to take this to another level with automatic rebooting with a Kodi Notification :smiley:

#!/bin/bash

if [ -f /var/run/reboot-required ]
then kodi-send --action="Notification(Automated Restart,System will restart in 60 seconds due to updated system packages,30000)"; sleep 60 && sudo kodi-send --action=Reboot; exit 1; fi

save this file to: /usr/bin/unattended-reboot_check

make the file executable

 sudo chmod +x /usr/bin/unattended-reboot_check

we also need to create another file called 99-mediacenter-update-restart so perform this command

sudo nano /etc/apt/apt.conf.d/99-mediacenter-update-restart

and append this:

DPkg::Post-Invoke {"if systemctl is-enabled mediacenter.service >/dev/null 2>&1 && ! systemctl is-active mediacenter.service >/dev/null 2>&1; then systemctl restart mediacenter.service; fi; exit 0";};

along with this file 99-remove-unnessary-configs

sudo nano /etc/apt/apt.conf.d/99-remove-unnessary-configs

and append

DPkg::Post-Invoke {"/usr/bin/apt-get -qq -y purge $(/usr/bin/dpkg -l | /bin/grep "^rc"| /usr/bin/awk '{print $2}')";};

this will purge old configs if found and restart Kodi if its upgraded so it doesn’t get stuck at console

next up we are gonna schedule this to run as a cronjob so either install cron from appstore with the command:

sudo apt install -y cron-app-osmc
sudo crontab -e

then append this in cron

0 */1 * * * /usr/bin/unattended-reboot_check

This small script checks if reboot flag i present and reboots the system after it sends out notification to the user, it also checks the status of Kodi if its active and if it isn’t it boots it up.

1 Like

So time to continues this endeavor :slight_smile: this time around we can cover another fun addition to unattended-upgrades will skip the warning by this time around you already know about the hazards and the rewards for doing this.

now lets setup a mail notifications when we do this so start with this:

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

and append this:

Unattended-Upgrade::Mail "your@email.adress";

and replace your@email.adress with your real address obviously, next we need to install a mailer

sudo apt install -y heirloom-mailx -y

then we need to setup a mailing account this example uses gmail but it work with any service that supports smtp

sudo nano /root/.mailrc

Then add this content

set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=your@email.address
set smtp-auth-password=secret
set from=someone@gmail.com

next up setting right to root only for the mail account

sudo chmod 660 /root/.mailrc

and then for the obligatory testrun

cat .kodi/temp/kodi.log | sudo mailx -v -s "Kodi Log" your@mail.address

obviously replace your@mail.address with your mail :wink: to see if the mail is working as intended

now whenever your mediacenter updates you will receive a log of the update of the packages that was updated

There may be an obvious answer to this but why not simply add a cronjob to sudo apt-get update && sudo apt-get dist-upgrade?

Your stuff obviously does more stuff like sending notifications to Kodi but wondering if there are obvious downsides to keeping it simple.

sure you can do a cronjob with all of that but its not really the official Debian way.

thats why i did it this way cause it is the official Debian standard for having automated updates plus you can build on top of it with email notifications etc.

im gonna expand on this more in the near future for those that are interested in this.

1 Like

I’m a bit concerned about this. The reason we don’t support unattended upgrades currently is because they’re not reliable enough to work. Furthermore, a lot of people will say their device suddenly stopped working, when the actual issue is that their system was updated. This will confuse people.

It’s also worth mentioning that without disabling updates in My OSMC, both unattended upgrades and My OSMC will fight for the lock.

If logs show unattended-upgrades as installed and they post logs, we will only ask them to reinstall. I don’t plan to support this feature at this time, so won’t go to lengths to debug any issues caused by it.

This is not a good idea. I can see you’ve hardcoded the packages, but if we introduce new packages or other Debian packages signal that a reboot is required, there may be no prompt. Instead, you should simply check for the /var/run/reboot-required flag.

hehe i knew this would get a response still i did this for simple documentation reason and its clearly stated that its not for newbies and i support the statement about not giving support to users with this solution since its not for newbies, in order to run this way you really have to have a clear grasp on the system that is why im good with it

will use the reboot flag btw simple fixes thats why my second post is a WIP so thx for the hint about fixing it :slight_smile:

tnx @sam_nazarko updated the second post removed hardcorded packages so you can change as much as you want and im just checking for the reboot flag in the post now and as for the unattneded well imho its just as simple as doing as @jb2cool said creating a cronjob with apt but with my i can extend to do other things along with that.

But i will stay clear of hardcoded packages will only display examples with HUGE warning labels :slight_smile:

also included the MyOSMC disable advice in the first post.

Thanks for the explanation

1 Like

updated 3rd post with email example

@sam_nazarko is the reboot flag used for mediacenter package ? i know its used for kernel package

It’s not.

k then ill adjust my script above to check if mediacenter is dead and restart the service if so :slight_smile: tnx for the help again @sam_nazarko .

and ps. The case looks great :slight_smile:

updated post 2

Here is a little script can push notifications about what package was updated if your not a fan of emails to pushbullet or pushover or as a simple kodi notification

we need to save this to /usr/bin/unattended_push_notifications so perform this command

sudo nano /usr/bin/unattended_push_notifications

then append:

#!/bin/sh
use_pushbullet="disabled"                               # enabled / disabled (default: disabled)
use_pushover="disabled"                                 # enabled / disabled (default: disabled)
use_kodi="enabled"                                      # enabled / disabled (default: disabled)

#Pushbullet/Pushover settings
pushbullet_token=""                                     # Your access token here (https://docs.pushbullet.com/)
pushover_token=""                                       # Your access token here (https://pushover.net/api)
pushover_username=""                                    # Pushover User ID (the user/group key (not e-mail address often referred to as USER_KEY)

log="/var/log/unattended-upgrades/unattended-upgrades-dpkg.log"
check_package=$(cat $log | tail -4 | grep "Setting up")

pushover_message () {
curl -s \
  --form-string "token=$pushover_token" \
  --form-string "user=$pushover_username" \
  --form-string "message=Package updating: $check_package" \
  https://api.pushover.net/1/messages.json
}

pushbullet_message () {
message="$check_package"
title="Package updating:"
curl -u $pushbullet_token: https://api.pushbullet.com/v2/pushes -d type=note -d title="$title" -d body="$message"
}

kodi_message () {
kodi-send --action="Notification(Package updating:,$check_package,5000)"
}

     if [ $use_pushbullet = "enabled" ]; then
        pushbullet_message
     fi
     if [ $use_pushover = "enabled" ]; then
        pushover_message
     fi
     if [ $use_kodi = "enabled" ]; then
        kodi_message
     fi

then we need to make it executable with

 sudo chmod +x /usr/bin/unattended_push_notifications

then add a condition that make it run after its updates

 sudo nano /etc/apt/apt.conf.d/99-post-update

and append:

 Dpkg::Post-Invoke {"/usr/bin/unattended_push_notifications";};

Here is an image of how pushbullet messages look

Hi Toat

I’m having troubles with installing heirloom-mailx. I’m stuck at setting it up. Any suggestions?

Unpacking heirloom-mailx (14.8.16-1) over (14.8.16-1) ...
Setting up heirloom-mailx (14.8.16-1) ...
E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/cache/apt/archives/
E: Problem executing scripts DPkg::Post-Invoke '/usr/bin/apt-get -qq -y purge $(/usr/bin/dpkg -l | /bin/grep ^rc| /usr/bin/awk '{print $2}')'
E: Sub-process returned an error code

I’ve already tried to remove lock file. There is also no other apt-get running in the background