AM-SAMPLE-pkg2appimage-custom 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: APPDIR FROM A RECIPE...
  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. # ...DOWNLOADING LIBUNIONPRELOAD...
  28. #wget https://github.com/project-portable/libunionpreload/releases/download/amd64/libunionpreload.so
  29. #chmod a+x libunionpreload.so
  30. #mv ./libunionpreload.so ./$APP/$APP.AppDir/
  31. # ...REPLACING THE EXISTING APPRUN WITH A CUSTOM ONE...
  32. rm -R -f ./"$APP"/"$APP".AppDir/AppRun
  33. cat > AppRun << 'EOF'
  34. #!/bin/sh
  35. APP=SAMPLE
  36. HERE="$(dirname "$(readlink -f "${0}")")"
  37. export UNION_PRELOAD="${HERE}"
  38. #export LD_PRELOAD="${HERE}/libunionpreload.so"
  39. export PATH="${HERE}"/usr/bin/:"${HERE}"/usr/sbin/:"${HERE}"/usr/games/:"${HERE}"/bin/:"${HERE}"/sbin/:"${PATH}"
  40. ##export LD_LIBRARY_PATH="${HERE}"/usr/lib/:"${HERE}"/usr/lib/i386-linux-gnu/:"${HERE}"/usr/lib/x86_64-linux-gnu/:"${HERE}"/lib/:"${HERE}"/lib/i386-linux-gnu/:"${HERE}"/lib/x86_64-linux-gnu/:"${LD_LIBRARY_PATH}"
  41. #export LD_LIBRARY_PATH=/lib/:/lib64/:/lib/x86_64-linux-gnu/:/usr/lib/:"${HERE}"/usr/lib/:"${HERE}"/usr/lib/i386-linux-gnu/:"${HERE}"/usr/lib/x86_64-linux-gnu/:"${HERE}"/lib/:"${HERE}"/lib/i386-linux-gnu/:"${HERE}"/lib/x86_64-linux-gnu/:"${LD_LIBRARY_PATH}"
  42. export PYTHONPATH="${HERE}"/usr/share/pyshared/:"${PYTHONPATH}"
  43. export PYTHONHOME="${HERE}"/usr/
  44. export XDG_DATA_DIRS="${HERE}"/usr/share/:"${XDG_DATA_DIRS}"
  45. export PERLLIB="${HERE}"/usr/share/perl5/:"${HERE}"/usr/lib/perl5/:"${PERLLIB}"
  46. export GSETTINGS_SCHEMA_DIR="${HERE}"/usr/share/glib-2.0/schemas/:"${GSETTINGS_SCHEMA_DIR}"
  47. export QT_PLUGIN_PATH="${HERE}"/usr/lib/qt4/plugins/:"${HERE}"/usr/lib/i386-linux-gnu/qt4/plugins/:"${HERE}"/usr/lib/x86_64-linux-gnu/qt4/plugins/:"${HERE}"/usr/lib32/qt4/plugins/:"${HERE}"/usr/lib64/qt4/plugins/:"${HERE}"/usr/lib/qt5/plugins/:"${HERE}"/usr/lib/i386-linux-gnu/qt5/plugins/:"${HERE}"/usr/lib/x86_64-linux-gnu/qt5/plugins/:"${HERE}"/usr/lib32/qt5/plugins/:"${HERE}"/usr/lib64/qt5/plugins/:"${QT_PLUGIN_PATH}"
  48. EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2- | sed -e 's|%.||g')
  49. ##exec ${EXEC} "$@"
  50. #exec "${HERE}"CUSTOMPATH "$@"
  51. EOF
  52. chmod a+x AppRun
  53. cp ./AppRun /opt/"$APP"/
  54. mv ./AppRun ./"$APP"/"$APP".AppDir
  55. # IMPORT THE LAUNCHER AND THE ICON TO THE APPDIR IF THEY NOT EXIST
  56. if test -f ./"$APP"/"$APP".AppDir/*.desktop; then
  57. echo "The desktop file exists"
  58. else
  59. echo "Trying to get the .desktop file"
  60. cp ./"$APP"/"$APP".AppDir/usr/share/applications/*"$(ls . | grep -i "$APP" | cut -c -4)"*desktop ./"$APP"/"$APP".AppDir/ 2>/dev/null
  61. fi
  62. ICONNAME=$(cat ./"$APP"/"$APP".AppDir/*desktop | grep "Icon=" | head -1 | cut -c 6-)
  63. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/22x22/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  64. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/24x24/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  65. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/32x32/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  66. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/48x48/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  67. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/64x64/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  68. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/128x128/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  69. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/256x256/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  70. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/512x512/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  71. cp ./"$APP"/"$APP".AppDir/usr/share/icons/hicolor/scalable/apps/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  72. cp ./"$APP"/"$APP".AppDir/usr/share/applications/*"$ICONNAME"* ./"$APP"/"$APP".AppDir/ 2>/dev/null
  73. # CLEAN METAINFO DIRECTORY
  74. metainfodir=$(find ./"$APP"/"$APP".AppDir -type d -name metainfo | grep "share/metainfo" | head -1)
  75. if [ -z "$metainfodir" ]; then
  76. return
  77. else
  78. cd "$metainfodir" || return
  79. rm -R -f ./*.xml
  80. cd - > /dev/null || return
  81. fi
  82. # ...EXPORT THE APPDIR TO AN APPIMAGE!
  83. ARCH=$(uname -m) VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./"$APP"/"$APP".AppDir
  84. underscore=_
  85. mkdir version
  86. mv ./"$APP"/"$APP""$underscore"*.deb ./version/
  87. version=$(ls /opt/"$APP"/tmp/version)
  88. echo "$version" >> /opt/"$APP"/version
  89. cd ..
  90. mv ./tmp/*.AppImage ./"$APP"
  91. chmod a+x ./"$APP"
  92. rm -R -f ./tmp
  93. # LINK
  94. ln -s /opt/"$APP"/"$APP" /usr/local/bin/"$APP"
  95. # SCRIPT TO UPDATE THE PROGRAM
  96. cat >> /opt/"$APP"/AM-updater << 'EOF'
  97. #!/bin/sh
  98. APP=SAMPLE
  99. initial=$(echo $APP | head -c 1)
  100. version0=$(cat /opt/"$APP"/version)
  101. url="http://http.us.debian.org/debian/pool/main/$initial/"$APP"/$version0"
  102. if curl --output /dev/null --silent --head --fail "$url"; then
  103. echo "Update not needed, exit!"
  104. else
  105. notify-send "A new version of $APP is available, please wait!"
  106. mkdir /opt/"$APP"/tmp
  107. cd /opt/"$APP"/tmp || exit 1
  108. 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
  109. wget https://raw.githubusercontent.com/ivan-hc/AM-application-manager/main/tools/pkg2appimage # 64 BIT ONLY (comment to disable)
  110. chmod a+x ./appimagetool ./pkg2appimage
  111. cp /opt/"$APP"/recipe.yml /opt/"$APP"/tmp/recipe.yml
  112. ./pkg2appimage ./recipe.yml
  113. #wget https://github.com/project-portable/libunionpreload/releases/download/amd64/libunionpreload.so
  114. #chmod a+x libunionpreload.so
  115. #mv ./libunionpreload.so ./"$APP"/"$APP".AppDir/
  116. rm -R -f ./"$APP"/"$APP".AppDir/AppRun
  117. cp /opt/"$APP"/AppRun ./"$APP"/"$APP".AppDir/
  118. metainfodir=$(find ./"$APP"/"$APP".AppDir -type d -name metainfo | grep "share/metainfo" | head -1)
  119. if [ -z "$metainfodir" ]; then
  120. return
  121. else
  122. cd "$metainfodir" || return
  123. rm -R -f ./*.xml
  124. cd - > /dev/null || return
  125. fi
  126. ARCH=$(uname -m) VERSION=$(./appimagetool -v | grep -o '[[:digit:]]*') ./appimagetool -s ./"$APP"/"$APP".AppDir
  127. underscore=_
  128. mkdir version
  129. mv ./"$APP"/"$APP""$underscore"*.deb ./version/
  130. cd ..
  131. version=$(ls /opt/"$APP"/tmp/version)
  132. if test -f ./tmp/version/$version; then rm -R -f ./version
  133. fi
  134. echo "$version" >> /opt/"$APP"/version
  135. mv ./tmp/*.AppImage ./"$APP"
  136. chmod a+x ./"$APP"
  137. rm -R -f ./tmp
  138. notify-send "$APP is updated!"
  139. fi
  140. EOF
  141. chmod a+x /opt/"$APP"/AM-updater
  142. # LAUNCHER & ICON
  143. cd "/opt/$APP" || exit 1
  144. ./"$APP" --appimage-extract *.desktop 1>/dev/null && mv ./squashfs-root/*.desktop ./"$APP".desktop
  145. ./"$APP" --appimage-extract .DirIcon 1>/dev/null && mv ./squashfs-root/.DirIcon ./DirIcon
  146. COUNT=0
  147. while [ "$COUNT" -lt 10 ]; do # Tries to get the actual icon/desktop if it is a symlink to another symlink
  148. if [ -L ./"$APP".desktop ]; then
  149. LINKPATH=$(readlink ./"$APP".desktop)
  150. ./"$APP" --appimage-extract "$LINKPATH" && mv ./squashfs-root/"$LINKPATH" ./"$APP".desktop
  151. fi
  152. if [ -L ./DirIcon ]; then
  153. LINKPATH=$(readlink ./DirIcon)
  154. ./"$APP" --appimage-extract "$LINKPATH" && mv ./squashfs-root/"$LINKPATH" ./DirIcon
  155. fi
  156. [ ! -L ./"$APP".desktop ] && [ ! -L ./DirIcon ] && break
  157. COUNT=$((COUNT + 1))
  158. done
  159. sed -i "s#Exec=[^ ]*#Exec=$APP#g; s#Icon=.*#Icon=/opt/$APP/icons/$APP#g" ./"$APP".desktop
  160. mv ./"$APP".desktop /usr/local/share/applications/"$APP"-AM.desktop && mv ./DirIcon ./icons/"$APP" 1>/dev/null
  161. rm -R -f ./squashfs-root