zmninja 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. APP=zmninja
  3. APPNAME=zmNinja
  4. CATEGORIES=$(curl -L -s https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/$APPNAME.md | grep -E -i categories | cut -c 17-)
  5. ICONURL="https://appimage.github.io/database/$(curl -L -s https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/$APPNAME.md | grep -E -i icons | sed -n 2p | cut -c 5-)"
  6. REPO="ZoneMinder/zmNinja"
  7. USER=$(echo $REPO | sed 's:/[^/]*$::')
  8. REPO2=$(echo $REPO | sed 's:.*/::')
  9. FILENAMEEXTENTION="arm64.AppImage"
  10. URL=https://github.com/$REPO/releases/latest
  11. COMMENT=$(curl -L -s https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/$APPNAME.md | grep "Comment:" | cut -c 14-)
  12. # CREATE THE FOLDER
  13. mkdir /opt/$APP
  14. cd /opt/$APP
  15. # ADD THE REMOVER
  16. echo '#!/bin/sh' >> /opt/$APP/remove
  17. echo "rm -R -f /usr/local/share/applications/$APP-AM.desktop /opt/$APP /usr/local/bin/$APP" >> /opt/$APP/remove
  18. chmod a+x /opt/$APP/remove
  19. # DOWNLOAD THE APPIMAGE
  20. mkdir tmp
  21. cd ./tmp
  22. wget https://github.com/$(wget https://github.com/$REPO/releases/latest | grep -E '/.*/.*'$FILENAMEEXTENTION'' -o);
  23. version=$(curl -Ls https://api.github.com/repos/$REPO/releases/latest | grep -E tag_name | awk -F '[""]' '{print $4}')
  24. echo "$version" >> /opt/$APP/version
  25. cd ..
  26. mv ./tmp/*mage ./$APP
  27. chmod a+x /opt/$APP/$APP
  28. rmdir ./tmp
  29. # LINK
  30. ln -s /opt/$APP/$APP /usr/local/bin/$APP
  31. # SCRIPT TO UPDATE THE PROGRAM
  32. cat >> /opt/$APP/AM-updater << 'EOF'
  33. #!/usr/bin/env bash
  34. APP=zmninja
  35. version0=$(cat /opt/$APP/version)
  36. url=https://github.com/FUNCTION2/FUNCTION3/releases/latest
  37. if curl -L -s $url | grep -ioF "$version0"; then
  38. echo "Update not needed!"
  39. else
  40. notify-send "A new version of $APP is available, please wait"
  41. mkdir /opt/$APP/tmp
  42. cd /opt/$APP/tmp
  43. URL=https://github.com/FUNCTION2/FUNCTION3/releases/latest
  44. wget https://github.com/$(wget https://github.com/FUNCTION2/FUNCTION3/releases/latest | grep -E '/.*/.*'FUNCTION4'' -o);
  45. version=$(curl -Ls https://api.github.com/repos/FUNCTION2/FUNCTION3/releases/latest | grep -E tag_name | awk -F '[""]' '{print $4}')
  46. cd ..
  47. if test -f ./tmp/*mage; then rm ./version
  48. fi
  49. echo $version >> ./version
  50. mv --backup=t ./tmp/*mage ./$APP
  51. chmod a+x /opt/$APP/$APP
  52. rm -R -f ./tmp ./*~
  53. fi
  54. EOF
  55. sed -i s/FUNCTION2/$USER/g /opt/$APP/AM-updater
  56. sed -i s/FUNCTION3/$REPO2/g /opt/$APP/AM-updater
  57. sed -i s/FUNCTION4/$FILENAMEEXTENTION/g /opt/$APP/AM-updater
  58. chmod a+x /opt/$APP/AM-updater
  59. # LAUNCHER
  60. rm -f /usr/local/share/applications/$APP-AM.desktop
  61. echo "[Desktop Entry]
  62. Name=$APPNAME
  63. Exec=$APP
  64. Icon=/opt/$APP/icons/$APP
  65. Type=Application
  66. Terminal=false
  67. Categories=$CATEGORIES;
  68. Comment=$COMMENT" >> /usr/local/share/applications/$APP-AM.desktop
  69. # ICON
  70. mkdir ./icons
  71. wget $ICONURL -O /opt/$APP/icons/$APP