AM-SAMPLE-RunImage 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. # AM INSTALL SCRIPT VERSION 3.5
  3. set -u
  4. APP=SAMPLE
  5. SITE="REPLACETHIS"
  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=$(FUNCTION)
  13. wget "$version" || exit 1
  14. # Keep this space in sync with other installation scripts
  15. # Use tar fx ./*tar* here for example in this line in case a compressed file is downloaded.
  16. cd ..
  17. mv ./tmp/* ./"$APP"
  18. # Keep this space in sync with other installation scripts
  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=SAMPLE
  29. SITE="REPLACETHIS"
  30. version0=$(cat "/opt/$APP/version")
  31. version=$(FUNCTION)
  32. [ -n "$version" ] || { echo "Error getting link"; exit 1; }
  33. if [ "$version" != "$version0" ]; then
  34. mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
  35. notify-send "A new version of $APP is available, please wait"
  36. 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 --backup=t ./tmp/*pp*undle ./"$APP"
  40. chmod a+x ./"$APP" || exit 1
  41. echo "$version" > ./version
  42. rm -R -f ./*zs-old ./*.part ./tmp ./*~
  43. notify-send "$APP is updated!"
  44. else
  45. echo "Update not needed!"
  46. fi
  47. EOF
  48. chmod a+x ./AM-updater || exit 1
  49. # LAUNCHER & ICON\n
  50. ./"$APP" --runtime-extract
  51. desktop_files=$(find ./RunDir -type f -wholename *applications*.desktop)
  52. for d in $desktop_files; do grep -q "^Exec=.*$APP" "$d" && mv "$d" ./"$APP".desktop; done
  53. if [ -f ./"$APP".desktop ]; then
  54. icon_file=$(grep "^Icon=" ./*.desktop | head -1 | cut -c 6-)
  55. mv "$(find ./RunDir -name "$icon_file.*png" -exec ls -S {} + | head -1)" ./icons/"$APP" || mv "$(find ./RunDir -name "$icon_file.*svg" -exec ls -S {} + | head -1)" ./icons/"$APP"
  56. sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
  57. mv ./"$APP".desktop /usr/local/share/applications/"$APP"-AM.desktop
  58. fi
  59. rm -Rf ./RunDir