AM-SAMPLE-AppImage 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. APP=SAMPLE
  3. SITE="REPLACETHIS"
  4. # CREATE DIRECTORIES
  5. if [ -z "$APP" ]; then exit 1; fi
  6. mkdir -p "/opt/$APP/tmp" "/opt/$APP/icons" && cd "/opt/$APP/tmp" || exit 1
  7. # ADD THE REMOVER
  8. echo "#!/bin/sh
  9. rm -f /usr/share/applications/AM-$APP.desktop /usr/local/bin/$APP
  10. rm -R -f /opt/$APP" >> "/opt/$APP/remove"
  11. chmod a+x "/opt/$APP/remove"
  12. # DOWNLOAD AND PREPARE THE APP
  13. # $version is also used for updates
  14. version=$(FUNCTION)
  15. wget "$version"
  16. wget "$version.zsync" 2> /dev/null
  17. echo "$version" >> /opt/$APP/version
  18. # Use tar fx ./*tar* for example in this line in case a compressed file is downloaded.
  19. cd ..
  20. mv ./tmp/*mage ./"$APP"
  21. mv ./tmp/*.zsync ./"$APP".zsync 2> /dev/null
  22. chmod a+x "/opt/$APP/$APP"
  23. rm -R -f ./tmp
  24. # LINK
  25. ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP"
  26. # SCRIPT TO UPDATE THE PROGRAM
  27. cat >> "/opt/$APP/AM-updater" << 'EOF'
  28. #!/bin/sh
  29. APP=SAMPLE
  30. SITE="REPLACETHIS"
  31. if [ -z "$APP" ]; then exit 1; fi
  32. version0=$(cat "/opt/$APP/version")
  33. version=$(FUNCTION)
  34. if test -f "/opt/$APP/*.zsync"; then
  35. mkdir "/opt/$APP/tmp"
  36. cd "/opt/$APP/tmp" || exit 1
  37. wget "$version.zsync" 2> /dev/null
  38. cd ..
  39. mv ./tmp/*.zsync ./"$APP".zsync
  40. rm -R -f ./tmp
  41. zsync "/opt/$APP/$APP.zsync"
  42. rm -R -f "/opt/$APP/*zs-old" "/opt/$APP/*.part"
  43. chmod a+x /opt/$APP/$APP
  44. if [ "$version" != "$version0" ]; then
  45. rm -f /opt/$APP/version
  46. echo "$version" >> /opt/$APP/version
  47. fi
  48. else
  49. if [ "$version" = "$version0" ]; then
  50. echo "Update not needed!" && exit 0
  51. else
  52. notify-send "A new version of $APP is available, please wait"
  53. mkdir "/opt/$APP/tmp"
  54. cd "/opt/$APP/tmp" || exit 1
  55. wget $version
  56. if ls . | grep mage; then
  57. cd ..
  58. if test -f ./tmp/*mage; then rm ./version
  59. fi
  60. echo "$version" >> ./version
  61. mv --backup=t ./tmp/* ./"$APP"
  62. chmod a+x "/opt/$APP/$APP"
  63. rm -R -f ./tmp ./*~
  64. fi
  65. notify-send "$APP is updated!"
  66. fi
  67. fi
  68. EOF
  69. chmod a+x "/opt/$APP/AM-updater"
  70. # LAUNCHER & ICON
  71. cd "/opt/$APP" || exit 1
  72. ./"$APP" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
  73. ./"$APP" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$APP".desktop
  74. ./"$APP" --appimage-extract share/applications/*.desktop 1>/dev/null && mv ./squashfs-root/share/applications/*.desktop ./"$APP".desktop
  75. ./"$APP" --appimage-extract usr/share/applications/*.desktop 1>/dev/null && mv ./squashfs-root/usr/share/applications/*.desktop ./"$APP".desktop
  76. if [ -L ./DirIcon ]; then
  77. LINKPATH=$(readlink ./DirIcon)
  78. ./"$APP" --appimage-extract "$LINKPATH" && mv ./squashfs-root/"$LINKPATH" ./DirIcon
  79. fi
  80. sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
  81. mv ./"$APP".desktop /usr/share/applications/AM-"$APP".desktop && mv ./DirIcon ./icons/"$APP" 2>/dev/null
  82. rm -R -f ./squashfs-root
  83. # CHANGE THE PERMISSIONS
  84. currentuser=$(who | awk '{print $1}')
  85. chown -R "$currentuser" "/opt/$APP"