AM-SAMPLE-AppImage.GitHub.io 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. APP=SAMPLE
  3. APPNAME=APPIMAGENAME
  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=$(curl -L -s https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/$APPNAME.md | grep -A1 "type: GitHub" | sed -n 2p | cut -c 10-)
  7. USER=$(echo $REPO | sed 's:/[^/]*$::')
  8. REPO2=$(echo $REPO | sed 's:.*/::')
  9. FILENAMEEXTENTION="/.*/.*.*mage"
  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/share/applications/AM-$APP.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. download=$(wget -q https://api.github.com/repos/$REPO/releases/latest -O - | grep -E browser_download_url | awk -F '[""]' '{print $4}' | grep -w -v i386 | grep -w -v i686 | grep -w -v arm64 | grep -w -v armv7l | egrep ''$FILENAMEEXTENTION'' -o | head -1);
  23. wget https:$download
  24. version=$(wget -q https://api.github.com/repos/$REPO/releases/latest -O - | grep -E tag_name | awk -F '[""]' '{print $4}')
  25. echo "$version" >> /opt/$APP/version
  26. cd ..
  27. mv ./tmp/*mage ./$APP
  28. chmod a+x /opt/$APP/$APP
  29. rmdir ./tmp
  30. # LINK
  31. ln -s /opt/$APP/$APP /usr/local/bin/$APP
  32. # SCRIPT TO UPDATE THE PROGRAM
  33. cat >> /opt/$APP/AM-updater << 'EOF'
  34. #!/usr/bin/env bash
  35. APP=SAMPLE
  36. APPNAME=APPIMAGENAME
  37. REPO=$(curl -L -s https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/$APPNAME.md | grep -A1 "type: GitHub" | sed -n 2p | cut -c 10-)
  38. version0=$(cat /opt/$APP/version)
  39. url=https://github.com/FUNCTION2/FUNCTION3/releases/latest
  40. if curl -L -s $url | grep -ioF "$version0"; then
  41. echo "Update not needed!"
  42. else
  43. notify-send "A new version of $APP is available, please wait"
  44. mkdir /opt/$APP/tmp
  45. cd /opt/$APP/tmp
  46. URL=https://github.com/FUNCTION2/FUNCTION3/releases/latest
  47. wget https://github.com/$(wget https://github.com/FUNCTION2/FUNCTION3/releases/latest -O - | grep -w -v i386 | grep -w -v i686 | grep -w -v arm64 | grep -w -v armv7l | egrep ''FUNCTION4'' -o | head -1);
  48. wget https:$download
  49. version=$(wget -q https://api.github.com/repos/FUNCTION2/FUNCTION3/releases/latest -O - | grep -E tag_name | awk -F '[""]' '{print $4}')
  50. cd ..
  51. if test -f ./tmp/*mage; then rm ./version
  52. fi
  53. echo $version >> ./version
  54. mv --backup=t ./tmp/*mage ./$APP
  55. chmod a+x /opt/$APP/$APP
  56. rm -R -f ./tmp ./*~
  57. notify-send "$APP is updated!"
  58. fi
  59. EOF
  60. sed -i s/FUNCTION2/$USER/g /opt/$APP/AM-updater
  61. sed -i s/FUNCTION3/$REPO2/g /opt/$APP/AM-updater
  62. sed -i s/FUNCTION4/$FILENAMEEXTENTION/g /opt/$APP/AM-updater
  63. chmod a+x /opt/$APP/AM-updater
  64. # LAUNCHER
  65. rm /usr/share/applications/AM-$APP.desktop
  66. wget $(wget -q https://api.github.com/repos/AppImage/appimage.github.io/contents/database/$APPNAME/ -O - | grep download_url | head -1 | cut -c 22- | rev | cut -c 3- | rev) -O $APP.desktopapp=$(echo $APP | cut -c -3)
  67. CHANGEEXEC=$(cat ./$APP.desktop | grep Exec= | tr ' ' '\n' | tr '=' '\n' | tr '/' '\n' | grep $app | head -1)
  68. sed -i "s#$CHANGEEXEC#$APP#g" ./$APP.desktop
  69. sed -i "s#AppRun#$APP#g" ./$APP.desktop
  70. sed -i "s#Exec=/bin/#Exec=#g" ./$APP.desktop
  71. sed -i "s#Exec=/usr/bin/#Exec=#g" ./$APP.desktop
  72. CHANGEICON=$(cat ./$APP.desktop | grep Icon= | head -1)
  73. sed -i "s#$CHANGEICON#Icon=/opt/$APP/icons/$APP#g" ./$APP.desktop
  74. mv ./$APP.desktop /usr/share/applications/AM-$APP.desktop
  75. # ICON
  76. mkdir ./icons
  77. wget $ICONURL -O /opt/$APP/icons/$APP
  78. # CHANGE THE PERMISSIONS
  79. currentuser=$(who | awk '{print $1}')
  80. chown -R $currentuser /opt/$APP
  81. # MESSAGE
  82. echo '
  83. '$APPNAME' is provided by https://github.com/'$REPO'
  84. '