Skip to content

Step 5: the "AM updater" script

iVAN edited this page Mar 16, 2022 · 2 revisions

AM-updater is a script needed by the -u option to update in bulk all the programs (am -u) or one by one (am -u $your-app), and substantially it is the "copy" of the STEP 3 of this guide (in the case of non-updatable programs) but with instructions to check a new version of a program. To made your main script creating the AM-script, replace the word UPDATER from ONLY ONE of the following functions:

echo 'UPDATER'' >> /opt/$APP/AM-updater
chmod a+x /opt/$APP/AM-updater

or

cat > /opt/$APP/AM-updater <<\EOF
UPDATER
EOF
chmod a+x /opt/$APP/AM-updater

Here are some examples.

Example1, check version from a binary (Brave Browser)

In this script we have to compare the version of the binary (line 1) fith the one available on a website (line 2 and 3):

#!/bin/sh
version=$(exec /opt/'$APP'/brave --version | grep -Eo "[+-]?[0-9]+([.][0-9]+)?+[+-]?[0-9]+([.][0-9]+)?")
url="https://brave.updatestar.com/"
if curl -L -s $url | grep -ioF "$version" 1>/dev/null; then
  echo "Update not needed, exit!"
else
  notify-send "A new version of '$APP' is available, please wait!"
  mkdir /opt/'$APP'/tmp
  cd /opt/'$APP'/tmp
  wget https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/tools/pkg2appimage
  chmod a+x ./pkg2appimage
  echo "app: brave
ingredients:
  package: brave-browser
  dist: stable
  sources: 
    - deb https://brave-browser-apt-release.s3.brave.com stable main" >> recipe.yml;
  ./pkg2appimage ./recipe.yml
  cd ..
  mv --backup=t ./tmp/brave/brave.AppDir/opt/brave.com/brave/* ./
  rm -R -f ./tmp ./*~
fi

Example2, version from a file (Inkscape)

In this example, the version was previously printed in a /opt/$APP/version file we have created in the STEP 4 (line 2), it will be compared with the one available on the main site of the project (lines 3 and 4):

#!/bin/sh
version0=$(cat /opt/inkscape/version)
url='curl -fsJL https://inkscape.org/release/  | grep "<title>" | grep -o -e "[0-9.]*'
if curl -L -s $url | grep -ioF "$version0"; then
  echo "Update not needed, exit!"
else
  notify-send "A new version of inkscape is available, please wait!"
  mkdir /opt/inkscape/tmp
  cd /opt/inkscape/tmp
  downloadURL="https://inkscape.org$(curl -fs https://inkscape.org$(curl -fsJL https://inkscape.org/release/  | grep "/release/" | grep en | head -n 1 | cut -d '"' -f 6)gnulinux/appimage/dl/ | grep "click here" | cut -d '"' -f 2)"
  wget $downloadURL
  cd ..
  if test -f ./tmp/*mage; then rm ./version
  fi
  version=$(curl -fsJL https://inkscape.org/release/  | grep "<title>" | grep -o -e "[0-9.]*")
  echo "$version" >> /opt/inkscape/version
  mv ./tmp/*mage ./inkscape
  chmod a+x /opt/inkscape/inkscape
  rmdir ./tmp
fi

I have chosen "Inkscape" for this example, but there are a lot of projects that have an easier and more human-readable AM-updater script that works the same way, for example LibreOffice Daily:

#!/bin/sh
version0=$(cat /opt/'$APP'/version)
url="https://libreoffice.soluzioniopen.com/daily/86/"
if curl -L -s "$url" | grep -ioF $version0 ; then
  echo "Update not needed, exit!"
else
  notify-send "A new version of '$APP' is available, please wait!"
  mkdir /opt/'$APP'/tmp
  cd /opt/'$APP'/tmp
  wget -r -erobots=off -l1 -np -A LibreOfficeDev-*0*.standard.help-x86_64.AppImage -nd https://libreoffice.soluzioniopen.com/daily/86
  cd ..
  version=$(ls /opt/'$APP'/tmp)
  if test -f ./tmp/*mage; then rm ./version
  fi
  echo "$version" >> ./version
  mv ./tmp/*.AppImage ./'$APP'
  chmod a+x ./'$APP'
  rm -R -f ./tmp
fi

DISCLAIMER, I know that LibreOffice Daily has its own .zsync file, but this was the faster way I've found when the main server had problems.

Example3, AppImages with zsync

In this example, I have to download a more recent version of the *.zsync file available (line 5) to update, this will be moved to the main directory (line 7) and will be executed (9) near the AppImage (named only $APP, I don't use the .AppImage extension to made them more similar to a binary), any eventually generated "zs-old" or ".part" file will be removed (line 10):

#!/bin/sh
cd /opt/$APP
mkdir tmp
cd ./tmp
wget $URL2.zsync;
cd ..
mv ./tmp/*mage.zsync ./$APP.zsync
rmdir ./tmp
zsync /opt/$APP/$APP.zsync
rm -R -f /opt/$APP/*zs-old /opt/$APP/*.part
chmod a+x /opt/$APP/$APP

Example4, appimageupdatetool to update AppImages (Audacity)

In this example we have our custom appimageupdatetool renamed updater that uses the -O option to update the program (line 3), this will generate eventually a *.part or *.zs-old file that will be removed at the end of the process (line 5), while the new one must be made executable (line 4).

#!/bin/sh
cd /opt/audacity
./updater -O ./audacity
chmod a+x /opt/audacity/audacity
rm -R -f /opt/audacity/*zs-old && rm -R -f /opt/audacity/*.part