appimagelauncher 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. # AM INSTALL SCRIPT VERSION 3.5
  3. set -u
  4. APP=appimagelauncher
  5. SITE="TheAssassin/AppImageLauncher"
  6. # CREATE DIRECTORIES AND ADD REMOVER
  7. [ -n "$APP" ] && mkdir -p "/opt/$APP/tmp" "/opt/$APP/icons" && cd "/opt/$APP/tmp" || exit 1
  8. printf "#!/bin/sh\nset -e\nrm -f /usr/local/bin/$APP\nrm -R -f /opt/$APP" > ../remove
  9. printf '\n%s' "rm -f /usr/local/share/applications/$APP-AM.desktop" >> ../remove
  10. chmod a+x ../remove || exit 1
  11. # DOWNLOAD AND PREPARE THE APP, $version is also used for updates
  12. version=$(curl -Ls https://api.github.com/repos/TheAssassin/AppImageLauncher/releases | sed 's/[()",{} ]/\n/g' | grep -oi "https.*mage$" | grep -i "i386" | head -1)
  13. wget "$version" || exit 1
  14. #wget "$version.zsync" 2> /dev/null # Comment out this line if you want to use zsync
  15. # Use tar fx ./*tar* here for example in this line in case a compressed file is downloaded.
  16. cd ..
  17. mv ./tmp/*mage ./"$APP"
  18. mv ./tmp/*.zsync ./"$APP".zsync 2>/dev/null
  19. rm -R -f ./tmp || exit 1
  20. echo "$version" > ./version
  21. chmod a+x ./"$APP" || exit 1
  22. # LINK TO PATH
  23. ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP"
  24. # SCRIPT TO UPDATE THE PROGRAM
  25. cat >> ./AM-updater << 'EOF'
  26. #!/bin/sh
  27. set -u
  28. APP=appimagelauncher
  29. SITE="TheAssassin/AppImageLauncher"
  30. version0=$(cat "/opt/$APP/version")
  31. version=$(curl -Ls https://api.github.com/repos/TheAssassin/AppImageLauncher/releases | sed 's/[()",{} ]/\n/g' | grep -oi "https.*mage$" | grep -i "i386" | head -1)
  32. [ -n "$version" ] || { echo "Error getting link"; exit 1; }
  33. if [ "$version" != "$version0" ] || [ -e /opt/"$APP"/*.zsync ]; then
  34. mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
  35. [ -e ../*.zsync ] || notify-send "A new version of $APP is available, please wait"
  36. [ -e ../*.zsync ] && wget "$version.zsync" 2>/dev/null || { wget "$version" || exit 1; }
  37. # Use tar fx ./*tar* here for example in this line in case a compressed file is downloaded.
  38. cd ..
  39. mv ./tmp/*.zsync ./"$APP".zsync 2>/dev/null || mv --backup=t ./tmp/*mage ./"$APP"
  40. [ -e ./*.zsync ] && { zsync ./"$APP".zsync || notify-send -u critical "zsync failed to update $APP"; }
  41. chmod a+x ./"$APP" || exit 1
  42. echo "$version" > ./version
  43. rm -R -f ./*zs-old ./*.part ./tmp ./*~
  44. notify-send "$APP is updated!"
  45. else
  46. echo "Update not needed!"
  47. fi
  48. EOF
  49. chmod a+x ./AM-updater || exit 1
  50. # LAUNCHER & ICON
  51. ./"$APP" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$APP".desktop
  52. ./"$APP" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
  53. COUNT=0
  54. while [ "$COUNT" -lt 10 ]; do # Tries to get the actual icon/desktop if it is a symlink to another symlink
  55. if [ -L ./"$APP".desktop ]; then
  56. LINKPATH="$(readlink ./"$APP".desktop | sed 's|^\./||' 2>/dev/null)"
  57. ./"$APP" --appimage-extract "$LINKPATH" 1>/dev/null && mv ./squashfs-root/"$LINKPATH" ./"$APP".desktop
  58. fi
  59. if [ -L ./DirIcon ]; then
  60. LINKPATH="$(readlink ./DirIcon | sed 's|^\./||' 2>/dev/null)"
  61. ./"$APP" --appimage-extract "$LINKPATH" 1>/dev/null && mv ./squashfs-root/"$LINKPATH" ./DirIcon
  62. fi
  63. [ ! -L ./"$APP".desktop ] && [ ! -L ./DirIcon ] && break
  64. COUNT=$((COUNT + 1))
  65. done
  66. sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
  67. mv ./"$APP".desktop /usr/local/share/applications/"$APP"-AM.desktop && mv ./DirIcon ./icons/"$APP" 1>/dev/null
  68. rm -R -f ./squashfs-root