AM-SAMPLE-pkg2appimage 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/sh
  2. set -u
  3. APP=SAMPLE
  4. # CREATE DIRECTORIES AND ADD REMOVER
  5. [ -n "$APP" ] && mkdir -p "/opt/$APP/tmp" "/opt/$APP/icons" && cd "/opt/$APP/tmp" || exit 1
  6. printf "#!/bin/sh\nset -e\nrm -f /usr/local/bin/$APP\nrm -R -f /opt/$APP" > "/opt/$APP/remove"
  7. printf '\n%s' "rm -f /usr/local/share/applications/$APP-AM.desktop" >> "/opt/$APP/remove"
  8. chmod a+x "/opt/$APP/remove"
  9. # DOWNLOADING THE DEPENDENCIES
  10. wget -q "$(curl -Ls https://api.github.com/repos/probonopd/go-appimage/releases | grep -v zsync | grep -i continuous | grep -i appimagetool | grep -i "$(uname -m)" | grep browser_download_url | cut -d '"' -f 4 | head -1)" -O appimagetool
  11. wget https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/tools/pkg2appimage
  12. chmod a+x ./appimagetool ./pkg2appimage
  13. # CREATING THE APPIMAGE
  14. echo "app: SAMPLE
  15. binpatch: true
  16. ingredients:
  17. dist: oldstable
  18. sources:
  19. - deb http://deb.debian.org/debian/ oldstable main contrib non-free
  20. - deb http://deb.debian.org/debian-security/ oldstable-security main contrib non-free
  21. - deb http://deb.debian.org/debian oldstable-updates main contrib non-free
  22. - deb http://deb.debian.org/debian oldstable-backports main contrib non-free
  23. packages:
  24. - SAMPLE" >> recipe.yml
  25. cp /opt/"$APP"/tmp/recipe.yml /opt/"$APP"/recipe.yml
  26. ./pkg2appimage ./recipe.yml
  27. # CLEAN METAINFO DIRECTORY
  28. metainfodir=$(find ./"$APP"/"$APP".AppDir -type d -name metainfo | grep "share/metainfo" | head -1)
  29. if [ -z "$metainfodir" ]; then
  30. return
  31. else
  32. cd "$metainfodir" || return
  33. rm -R -f ./*.xml
  34. cd - > /dev/null || return
  35. fi
  36. # ...EXPORT THE APPDIR TO AN APPIMAGE!
  37. ARCH=$(uname -m) VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./"$APP"/"$APP".AppDir
  38. underscore=_
  39. mkdir version
  40. mv ./"$APP"/"$APP""$underscore"*.deb ./version/
  41. version=$(ls /opt/"$APP"/tmp/version)
  42. echo "$version" >> /opt/"$APP"/version
  43. cd ..
  44. mv ./tmp/*.AppImage ./"$APP"
  45. chmod a+x ./"$APP"
  46. rm -R -f ./tmp
  47. # LINK
  48. ln -s /opt/"$APP"/"$APP" /usr/local/bin/"$APP"
  49. # SCRIPT TO UPDATE THE PROGRAM
  50. cat >> /opt/"$APP"/AM-updater << 'EOF'
  51. #!/bin/sh
  52. APP=SAMPLE
  53. initial=$(echo $APP | head -c 1)
  54. version0=$(cat /opt/"$APP"/version)
  55. url="http://http.us.debian.org/debian/pool/main/$initial/"$APP"/$version0"
  56. if curl --output /dev/null --silent --head --fail "$url"; then
  57. echo "Update not needed, exit!"
  58. else
  59. notify-send "A new version of $APP is available, please wait!"
  60. mkdir /opt/"$APP"/tmp
  61. cd /opt/"$APP"/tmp || exit 1
  62. wget -q $(curl -Ls https://api.github.com/repos/probonopd/go-appimage/releases | grep -v zsync | grep -i continuous | grep -i appimagetool | grep -i "$(uname -m)" | grep browser_download_url | cut -d '"' -f 4 | head -1) -O appimagetool
  63. wget https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/tools/pkg2appimage # 64 BIT ONLY (comment to disable)
  64. chmod a+x ./appimagetool ./pkg2appimage
  65. cp /opt/"$APP"/recipe.yml /opt/"$APP"/tmp/recipe.yml
  66. ./pkg2appimage ./recipe.yml
  67. metainfodir=$(find ./"$APP"/"$APP".AppDir -type d -name metainfo | grep "share/metainfo" | head -1)
  68. if [ -z "$metainfodir" ]; then
  69. return
  70. else
  71. cd "$metainfodir" || return
  72. rm -R -f ./*.xml
  73. cd - > /dev/null || return
  74. fi
  75. ARCH=$(uname -m) VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./"$APP"/"$APP".AppDir
  76. underscore=_
  77. mkdir version
  78. mv ./"$APP"/"$APP""$underscore"*.deb ./version/
  79. cd ..
  80. version=$(ls /opt/"$APP"/tmp/version)
  81. if test -f ./tmp/version/$version; then rm -R -f ./version
  82. fi
  83. echo "$version" >> /opt/"$APP"/version
  84. mv ./tmp/*.AppImage ./"$APP";
  85. chmod a+x ./"$APP"
  86. rm -R -f ./tmp
  87. notify-send "$APP is updated!"
  88. fi
  89. EOF
  90. chmod a+x /opt/"$APP"/AM-updater
  91. # LAUNCHER & ICON
  92. cd "/opt/$APP" || exit 1
  93. ./"$APP" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$APP".desktop
  94. ./"$APP" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
  95. COUNT=0
  96. while [ "$COUNT" -lt 10 ]; do # Tries to get the actual icon/desktop if it is a symlink to another symlink
  97. if [ -L ./"$APP".desktop ]; then
  98. LINKPATH=$(readlink ./"$APP".desktop)
  99. ./"$APP" --appimage-extract "$LINKPATH" && mv ./squashfs-root/"$LINKPATH" ./"$APP".desktop
  100. fi
  101. if [ -L ./DirIcon ]; then
  102. LINKPATH=$(readlink ./DirIcon)
  103. ./"$APP" --appimage-extract "$LINKPATH" && mv ./squashfs-root/"$LINKPATH" ./DirIcon
  104. fi
  105. [ ! -L ./"$APP".desktop ] && [ ! -L ./DirIcon ] && break
  106. COUNT=$((COUNT + 1))
  107. done
  108. sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
  109. mv ./"$APP".desktop /usr/local/share/applications/"$APP"-AM.desktop && mv ./DirIcon ./icons/"$APP" 1>/dev/null
  110. rm -R -f ./squashfs-root