AM-SAMPLE-AppImage-from-GitLab 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/sh
  2. APP=SAMPLE
  3. REPOID="REPLACETHIS"
  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/share/applications/AM-$APP.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=$(wget -q https://gitlab.com/api/v4/projects/$REPOID/releases/ -O - | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i .appimage | head -1 | sed 's#/file/#/raw/#')
  15. wget $version
  16. echo "$version" >> /opt/$APP/version
  17. cd ..
  18. mv ./tmp/*mage ./$APP
  19. chmod a+x /opt/$APP/$APP
  20. rmdir ./tmp
  21. # LINK
  22. ln -s /opt/$APP/$APP /usr/local/bin/$APP
  23. # SCRIPT TO UPDATE THE PROGRAM
  24. cat >> /opt/$APP/AM-updater << 'EOF'
  25. #!/usr/bin/env bash
  26. APP=SAMPLE
  27. REPOID="REPLACETHIS"
  28. version0=$(cat /opt/$APP/version)
  29. version=$(wget -q https://gitlab.com/api/v4/projects/$REPOID/releases/ -O - | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i .appimage | head -1 | sed 's#/file/#/raw/#')
  30. if [ $version = $version0 ]; then
  31. echo "Update not needed!"
  32. else
  33. notify-send "A new version of $APP is available, please wait"
  34. mkdir /opt/$APP/tmp
  35. cd /opt/$APP/tmp
  36. wget $version
  37. if ls . | grep mage; then
  38. cd ..
  39. if test -f ./tmp/*mage; then rm ./version
  40. fi
  41. echo $version >> ./version
  42. mv --backup=t ./tmp/*mage ./$APP
  43. chmod a+x /opt/$APP/$APP
  44. rm -R -f ./tmp ./*~
  45. fi
  46. notify-send "$APP is updated!"
  47. fi
  48. EOF
  49. chmod a+x /opt/$APP/AM-updater
  50. # LAUNCHER & ICON
  51. app=$(echo $APP | cut -c -3)
  52. cd /opt/$APP
  53. ./$APP --appimage-extract *.desktop 1>/dev/null
  54. ./$APP --appimage-extract share/applications/*.desktop 1>/dev/null
  55. ./$APP --appimage-extract usr/share/applications/*.desktop 1>/dev/null
  56. mv squashfs-root/*.desktop ./$APP.desktop
  57. mv squashfs-root/share/applications/*.desktop ./$APP.desktop
  58. mv squashfs-root/usr/share/applications/*.desktop ./$APP.desktop
  59. if [ ! -e ./$APP.desktop ]; then
  60. rm ./$APP.desktop; ./$APP --appimage-extract usr/share/applications/*$app*.desktop
  61. mv squashfs-root/usr/share/applications/*.desktop ./$APP.desktop
  62. fi
  63. if [ ! -e ./$APP.desktop ]; then
  64. rm ./$APP.desktop; ./$APP --appimage-extract share/applications/*$app*.desktop 1>/dev/null
  65. mv squashfs-root/share/applications/*.desktop ./$APP.desktop
  66. fi
  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. mkdir icons
  75. mv $(./$APP --appimage-extract *.png) ./icons/$APP 2>/dev/null
  76. mv $(./$APP --appimage-extract *.svg) ./icons/$APP 2>/dev/null
  77. ./$APP --appimage-extract share/icons/*/*/* 1>/dev/null
  78. ./$APP --appimage-extract usr/share/icons/*/*/* 1>/dev/null
  79. ./$APP --appimage-extract share/icons/*/*/*/* 1>/dev/null
  80. ./$APP --appimage-extract usr/share/icons/*/*/*/* 1>/dev/null
  81. mv ./squashfs-root/share/icons/hicolor/22x22/apps/*$app* ./icons/$APP 2>/dev/null
  82. mv ./squashfs-root/share/icons/hicolor/24x24/apps/*$app* ./icons/$APP 2>/dev/null
  83. mv ./squashfs-root/share/icons/hicolor/32x32/apps/*$app* ./icons/$APP 2>/dev/null
  84. mv ./squashfs-root/share/icons/hicolor/48x48/apps/*$app* ./icons/$APP 2>/dev/null
  85. mv ./squashfs-root/share/icons/hicolor/64x64/apps/*$app* ./icons/$APP 2>/dev/null
  86. mv ./squashfs-root/share/icons/hicolor/128x128/apps/*$app* ./icons/$APP 2>/dev/null
  87. mv ./squashfs-root/share/icons/hicolor/256x256/apps/*$app* ./icons/$APP 2>/dev/null
  88. mv ./squashfs-root/share/icons/hicolor/512x512/apps/*$app* ./icons/$APP 2>/dev/null
  89. mv ./squashfs-root/share/icons/hicolor/scalable/apps/*$app* ./icons/$APP 2>/dev/null
  90. mv ./squashfs-root/usr/share/icons/hicolor/22x22/apps/*$app* ./icons/$APP 2>/dev/null
  91. mv ./squashfs-root/usr/share/icons/hicolor/24x24/apps/*$app* ./icons/$APP 2>/dev/null
  92. mv ./squashfs-root/usr/share/icons/hicolor/32x32/apps/*$app* ./icons/$APP 2>/dev/null
  93. mv ./squashfs-root/usr/share/icons/hicolor/48x48/apps/*$app* ./icons/$APP 2>/dev/null
  94. mv ./squashfs-root/usr/share/icons/hicolor/64x64/apps/*$app* ./icons/$APP 2>/dev/null
  95. mv ./squashfs-root/usr/share/icons/hicolor/128x128/apps/*$app* ./icons/$APP 2>/dev/null
  96. mv ./squashfs-root/usr/share/icons/hicolor/256x256/apps/*$app* ./icons/$APP 2>/dev/null
  97. mv ./squashfs-root/usr/share/icons/hicolor/512x512/apps/*$app* ./icons/$APP 2>/dev/null
  98. mv ./squashfs-root/usr/share/icons/hicolor/scalable/apps/*$app* ./icons/$APP 2>/dev/null
  99. rm -R -f /opt/$APP/squashfs-root
  100. mv ./$APP.desktop /usr/share/applications/AM-$APP.desktop
  101. # CHANGE THE PERMISSIONS
  102. currentuser=$(who | awk '{print $1}')
  103. chown -R $currentuser /opt/$APP
  104. # MESSAGE
  105. echo "
  106. $APP is provided by https://github.com/$(echo $REPO | sed 's:/[^/]*$::')
  107. "