topgrade 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. APP=topgrade
  3. REPO="topgrade-rs/topgrade"
  4. # CREATE THE FOLDER
  5. mkdir /opt/$APP
  6. cd /opt/$APP
  7. # ADD THE REMOVER
  8. echo '#!/bin/sh' >> /opt/$APP/remove
  9. echo "rm -R -f /usr/local/share/applications/$APP-AM.desktop /opt/$APP /usr/local/bin/$APP" >> /opt/$APP/remove
  10. chmod a+x /opt/$APP/remove
  11. # DOWNLOAD THE ARCHIVE
  12. mkdir tmp
  13. cd ./tmp
  14. version=$(curl -Ls https://api.github.com/repos/$REPO/releases | grep browser_download_url | grep -i "aarch64-unknown-linux-gnu.tar.gz " | cut -d '"' -f 4 | head -1)
  15. wget $version
  16. echo "$version" >> /opt/$APP/version
  17. cd ..
  18. tar fx ./tmp/*tar.gz
  19. rm -R -f ./tmp
  20. # LINK
  21. ln -s /opt/$APP/$APP /usr/local/bin/$APP
  22. # SCRIPT TO UPDATE THE PROGRAM
  23. cat >> /opt/$APP/AM-updater << 'EOF'
  24. #!/usr/bin/env bash
  25. APP=topgrade
  26. REPO="topgrade-rs/topgrade"
  27. version0=$(cat /opt/$APP/version)
  28. version=$(curl -Ls https://api.github.com/repos/$REPO/releases | grep browser_download_url | grep -i "aarch64-unknown-linux-gnu.tar.gz " | cut -d '"' -f 4 | head -1)
  29. if [ $version = $version0 ]; then
  30. echo "Update not needed!"
  31. else
  32. notify-send "A new version of $APP is available, please wait"
  33. mkdir /opt/$APP/tmp
  34. cd /opt/$APP/tmp
  35. wget $version
  36. cd ..
  37. tar fx ./tmp/*tar.gz
  38. rm ./version
  39. echo $version >> ./version
  40. rm -R -f ./tmp ./*~
  41. notify-send "$APP is updated!"
  42. fi
  43. EOF
  44. chmod a+x /opt/$APP/AM-updater