Auto Updates for Desktop Clients - HOWTO

Discussion topics related to mobile applications for ZoneMinder
jsylvia007
Posts: 51
Joined: Wed Mar 11, 2009 8:32 pm

Auto Updates for Desktop Clients - HOWTO

Postby jsylvia007 » Sun Feb 12, 2017 12:04 am

Howdy all!!

So I wanted a way to update zmNinja automatically without having to visit the web.

Nothing in the below is complicated, but sometimes it's nice to put the pieces together.

I used "download-github-release" from here: https://www.npmjs.com/package/download-github-release

This works on both Windows and Linux.

On linux (using Ubuntu as a sample here), issue:

Code: Select all

sudo apt install nodejs nodejs-legacy npm


Once that's all installed, issue:

Code: Select all

sudo npm install -g download-github-release


Once download-github-release is installed, you'd run it this way:

download-github-release -s linux64bit pliablepixels zmNinja /PATH/TO/WHERE/YOU/WANT

That's it! It will automatically download and unpackage it in a folder called "zmNinja-linux64bit" inside the above path. Just point your shortcut to the zmNinja executable in this place, and you're all set.

I then created a cron job to run the above command daily at 3am, but also put a shortcut to it on my desktop next to the app,

For Windows, you'll need to download Node.js from here: http://blog.teamtreehouse.com/install-n ... pm-windows

Once it's downloaded, run the executable to install Node.js.

Once installed, issue the same npm install command from above (this time without the sudo):

Code: Select all

npm install -g download-github-release


Once that's installed, you'd use this syntax:

Code: Select all

C:\Users\YOUR_USERNAME\AppData\Roaming\npm\download-github-release.cmd -s win64 pliablepixels zmNinja C:\Users\YOUR_USERNAME\Documents


Anyway, hope this helps someone. I've been tinkering around with trying to get the "latest" release from Github, and it looks like this does the job perfectly so I thought I'd share with the community.

asker
Posts: 761
Joined: Sun Mar 01, 2015 12:12 pm

Re: Auto Updates for Desktop Clients - HOWTO

Postby asker » Sun Feb 12, 2017 12:12 pm

Thanks for your contribution - looks interesting. One tweak you might consider is not to download it if the version is the same. I suppose I could add some command line parameters to zmninja which lets you check that easily. I'll work on it.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

jsylvia007
Posts: 51
Joined: Wed Mar 11, 2009 8:32 pm

Re: Auto Updates for Desktop Clients - HOWTO

Postby jsylvia007 » Sun Feb 12, 2017 2:48 pm

asker wrote:Thanks for your contribution - looks interesting. One tweak you might consider is not to download it if the version is the same. I suppose I could add some command line parameters to zmninja which lets you check that easily. I'll work on it.


Interesting concept! I don't know much about git, but I'm sure that there's a way for me to check what the "release" version is...

asker
Posts: 761
Joined: Sun Mar 01, 2015 12:12 pm

Re: Auto Updates for Desktop Clients - HOWTO

Postby asker » Sun Feb 12, 2017 4:49 pm

Yes, you can easily get the latest release # using

Code: Select all

https://api.github.com/repos/pliablepixels/zmNinja/releases/latest


And then read the "tag_name" parameter

You will however have to figure out which version you currently have, programatically. Probably just write a "version" file each time you download and install, till I add a command line parameter to query zmninja itself
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

jsylvia007
Posts: 51
Joined: Wed Mar 11, 2009 8:32 pm

Re: Auto Updates for Desktop Clients - HOWTO

Postby jsylvia007 » Sun Feb 12, 2017 7:13 pm

So... Here is a linux script updated that will create a version file based on the version it downloads. This means it will download at least one time, but won't continue to re-download.

I will work on a Windows one... but I'm not so good with PowerShell, and it looks like that might be required.

We'll see!

Code: Select all

#!/bin/bash

if [ "$#" -gt 1 ]; then
    echo "This Script only takes '-q' as an argument, should you not want any output."
    exit 0
fi


##below function comes from here: http://ask.xmodulo.com/compare-two-version-numbers.html
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
   
DEST_DIR=$HOME/Documents/
DEST_VERSION="zmNinja-linux64bit"
INSTALL_DIR=$DEST_DIR$DEST_VERSION

if [ -f $INSTALL_DIR/version.txt ]; then
   INSTALLED_VERSION=`cat $INSTALL_DIR/version.txt`
else
   INSTALLED_VERSION=0
fi

LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/pliablepixels/zmNinja/releases/latest)
LATEST_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\(.*\)".*/\1/')
LATEST_VERSION=$(echo $LATEST_VERSION | sed 's/["].*$//')
LATEST_VERSION=${LATEST_VERSION#?}

if [ "$1" != "-q" ]; then

   echo $DEST_DIR
   echo $DEST_VERSION
   echo $INSTALL_DIR
   echo $INSTALLED_VERSION
   echo $LATEST_VERSION
fi

if version_gt $LATEST_VERSION $INSTALLED_VERSION; then
   

   if [ "$1" != "-q" ]; then
      echo "Update Required, Updating..."
   fi
   
   download-github-release -s $DEST_VERSION pliablepixels zmNinja $DEST_DIR
   echo "$LATEST_VERSION" > $INSTALL_DIR/version.txt
   
   if [ "$1" != "-q" ]; then
      echo "Update Completed."
   fi
else
   if [ "$1" != "-q" ]; then
      echo "No Update is Required."
   fi
fi

asker
Posts: 761
Joined: Sun Mar 01, 2015 12:12 pm

Re: Auto Updates for Desktop Clients - HOWTO

Postby asker » Mon Feb 13, 2017 2:34 pm

nice!
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts


Return to “Mobile Apps”

Who is online

Users browsing this forum: SteveGilvarry and 1 guest