#!/bin/bash
echo '--------------------  Frontend Updater  ---------------------'
set -e
if [ "$EUID" -ne 0 ]; then
  echo "please run as root"
  exit
fi
if [ -z $1 ]; then
  echo 'empty version'
  exit 1
fi
echo "starting update to version: $1"

echo '--->>  Downloading'
wget "https://vps.abarobotics.com/ota-update/nba-frontend/$1/nba-frontend-update" -O 'nba-frontend-update'
wget "https://vps.abarobotics.com/ota-update/nba-frontend/$1/SHA256SUMS" -O 'SHA256SUMS'

echo '--->>  Checksum'
sha256sum -c SHA256SUMS

echo '--->>  Updating'
read -p "Do you want to proceed? (y/N) " yn
case $yn in
  y )
    mv nba-frontend-update nba-frontend;;
  * )
    echo exiting...
    exit;;
esac

echo '--->>  Set permission'
chmod +x nba-frontend

echo '--->>  Restart service'
systemctl restart frontend.service

echo '--->>  Frontend Updated'
