Skip to content
Vincent Kodsi edited this page Dec 2, 2022 · 2 revisions

The script is in the testing phase:

#!/bin/bash

############################################################
# 'HyperHDR_update.sh' script to install/upgrade HyperHDR  #
#                                                          #
# v3 :                                                     #
#  - checking existing version works if none installed     #
#  - added "-f" param to force install of latest version   #
#                                                          #
############################################################

#Default params
FORCE_LATEST_INSTALL=0
VERBOSE_MODE=0

function readParams () {
  until (( $# == 0 )); do
    case $1 in
      "-f")
        FORCE_LATEST_INSTALL=1
        echo " Opt: forcing latest version installation"
        shift
        continue
        ;;
      "-v")
        VERBOSE_MODE=1
        echo " Opt: verbose mode"
        shift
        continue
        ;;
      *)
        echo " Opt: unknown '$1' parameter => ignored..."
        shift
        continue
        ;;
    esac
  done
}

#Is Curl installed ?
which curl 1>/dev/null
if [ $? != 0 ]; then
  sudo apt update && sudo apt install curl -y
fi

#Is GitHub CLI installed ?
which gh 1>/dev/null
if [ $? != 0 ]; then
  sudo curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt update && sudo apt install gh -y
fi

#Check parameters
readParams $*

if [ $FORCE_LATEST_INSTALL = 1 ]; then
  versionSelected=$(sudo gh release list -R awawa-dev/HyperHDR -L 2 | cut -d'v' -f2 | cut -f1 | awk '{print $1}' | head -1)
else  
  #Select version
  echo
  echo "Select version to install :"
  currentVersion=$(hyperhdr --version 2> /dev/null | head -2 | tail -1 | awk '{print $3}')
  if [ currentVersion = "" ]; then
    currentVersion="none"
  fi
  echo " (currently installed version = '${currentVersion}')"
  sudo gh release list -R awawa-dev/HyperHDR -L 2 | cut -d'v' -f2 | cut -f1 | awk '{print " ", NR, "->", $1}'
  echo "  (any other key to cancel...)"
  echo
  read versionNumber

  case "${versionNumber}" in
    1)
      #Get latest version
      versionSelected=$(sudo gh release list -R awawa-dev/HyperHDR -L 2 | cut -d'v' -f2 | cut -f1 | awk '{print $1}' | head -1)
      ;;
    2)
      #Get previous version
      versionSelected=$(sudo gh release list -R awawa-dev/HyperHDR -L 2 | cut -d'v' -f2 | cut -f1 | awk '{print $1}' | tail -1)
      ;;
    *)
      echo "Exiting..."
      exit 0
      ;;
  esac
fi

echo
cd /tmp
echo "#################################"
echo "Downloading ${versionSelected}..."
echo "#################################"
sudo wget https://github.com/awawa-dev/HyperHDR/releases/download/v${versionSelected}/HyperHDR-${versionSelected}-$(uname -s)-$(uname -m).deb
if [ $? != 0 ]; then
  echo "KO: impossible to download version ${versionSelected} !"
  sleep 2
  exit 1
fi

echo
echo "############################"
echo "Removing previous version..."
echo "############################"
sudo apt -y remove hyperhdr

echo
echo "##############################"
echo "Installing selected version..."
echo "##############################"
sudo apt -y install ./HyperHDR*.deb
sudo systemctl start [email protected]

echo
echo "########################"
echo "Post install cleaning..."
echo "########################"
sudo apt -y autoremove
sudo rm -f ./HyperHDR*.deb

echo
echo "#########################"
echo "Installation successful !"
echo "#########################"
exit 0