Linux Mint release checker script

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
it-place
Level 3
Level 3
Posts: 187
Joined: Thu Jul 05, 2018 4:42 am

Linux Mint release checker script

Post by it-place »

Hi all!

While waiting for the next Linux Mint release 20.1 I wrote a little shell-script. I'm starting this script on logon using Startup Applications so I'll be informed when the release is ready to download. Perhaps someone of you will find this useful. :)

All you have to do is setting _version to the wanted release version, e.g.:
_version=20.1
Best Regards - Olli

Code: Select all

#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin
LANG=C
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus
export DISPLAY=:0

_version=20.1
_log=$HOME/.check_release

_result=$(curl -s https://www.linuxmint.com/download.php | grep "<h1>Download Linux Mint")
if [ "$_result" == "" ]; then
  notify-send "Check Release" "Warning! Release check failed."
else
  _goal=$(echo $_result | grep $_version)
  if [ "$_goal" != "" ]; then
    notify-send "Check Release" "Linux Mint $_version released."
  fi
fi

echo $_result > $_log
# EOF
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Linux Mint release checker script

Post by Termy »

Nice idea for a script. Here's some food for thought:

Here's a more efficient way in which to grab the version, without resorting to external tools other than cURL:

Code: Select all

while read; do
    if [[ $REPLY == *'<h1>Download Linux Mint'* ]]; then
        read -a VerArr <<< "$REPLY"
        printf '%s\n' "${VerArr[3]}"
        break
    fi  
done <<< "$(curl -s 'https://www.linuxmint.com/download.php')"
It'd be nice to support WGet as well, so this might be nice:

Code: Select all

if type -P curl &> /dev/null; then
    Bin='curl -s'
elif type -P wget &> /dev/null; then
    Bin='wget -qO -'
fi

while read; do
    if [[ $REPLY == *'<h1>Download Linux Mint'* ]]; then
        read -a VerArr <<< "$REPLY"
        printf '%s\n' "${VerArr[3]}"
        break
    fi
done <<< "$($Bin 'https://www.linuxmint.com/download.php')"
Regarding all the exports and what-not: why? Are you exporting DISPLAY to avoid notifications displaying on X monitor(s)? I'm also curious as to why you're doing the dbus stuff as well. In my experience, notify-send doesn't need any of that stuff, but we probably have very different setups.

Instead of using a version file, you're probably better off comparing the remote version to the version the user is currently running, by parsing '/etc/os-release' or using something like lsb_release(1); this is at least viable in Ubuntu and would be my approach. I would parse 'os-release' with something like:

Code: Select all

while IFS='=' read -a KeyVal; do
    if [ "${KeyVal[0]}" == 'VERSION_ID' ]; then
        Current=${KeyVal[1]//\"}
        break
    fi
done < '/etc/os-release'
So that I could access Current later on. Clean and efficient.

If you have any Qs, I'm all eyes.
I'm also Terminalforlife on GitHub.
User avatar
it-place
Level 3
Level 3
Posts: 187
Joined: Thu Jul 05, 2018 4:42 am

Re: Linux Mint release checker script

Post by it-place »

Hi Termy,

thank you for these helpful ideas! In fact you don't need these two lines in my script:

Code: Select all

export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus
export DISPLAY=:0
I remember that these lines are only necessary if you are running a shell script via cronjob. Without these two lines notify-send wouldn't show any message. :wink:

Regards - Olli
User avatar
Termy
Level 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Linux Mint release checker script

Post by Termy »

No-no, thank you, as I was wondering how to get notifications to display from a cron job and similar environments. :lol: In retrospect, it makes a lot of sense. :roll:
I'm also Terminalforlife on GitHub.
Locked

Return to “Scripts & Bash”