Skip to content

Commit

Permalink
make appimage work on any linux system
Browse files Browse the repository at this point in the history
made possible thanks to https://github.com/VHSgunzo/sharun
  • Loading branch information
Samueru-sama authored Oct 27, 2024
1 parent 7cef659 commit bca2191
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions android-tools-appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ APPDIR="$APP".AppDir
SITE="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
ICON="https://developer.android.com/static/images/brand/Android_Robot.png"
APPIMAGETOOL="https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage"
SHARUN="https://bin.ajam.dev/$(uname -m)/sharun"
LIB4BIN="https://raw.githubusercontent.com/VHSgunzo/sharun/refs/heads/main/lib4bin"

# CREATE DIRECTORIES AND DOWNLOAD THE ARCHIVE
[ -n "$APP" ] || exit 1
mkdir -p ./"$APP"/"$APPDIR"/usr && cd ./"$APP"/"$APPDIR"/usr || exit 1
mkdir -p ./"$APP"/"$APPDIR"/shared && cd ./"$APP"/"$APPDIR" || exit 1
wget "$SITE" && unzip -q *.zip && rm -f ./*.zip || exit 1
mv ./platform-* ./bin && cd .. || exit 1
mv ./platform-tools ./shared/bin || exit 1

# DESKTOP & ICON
cat >> ./Android-$APP.desktop << 'EOF'
Expand All @@ -25,20 +27,28 @@ Terminal=true
EOF
wget "$ICON" -O ./Android.png && ln -s ./Android.png ./.DirIcon

# BUNDLE ALL DEPENDENCIES
wget "$SHARUN" -O ./sharun || exit 1
wget "$LIB4BIN" -O ./lib4bin || exit 1
chmod +x ./sharun ./lib4bin

HARD_LINKS=1 ./lib4bin ./shared/bin/* && rm -f ./lib4bin || exit 1

# AppRun
cat >> ./AppRun << 'EOF'
#!/bin/sh
CURRENTDIR="$(dirname "$(readlink -f "$0")")"/usr/bin
CURRENTDIR="$(dirname "$(readlink -f "$0")")"
UDEVNOTICE='No android udev rules detected, use "--getudev" to install'
UDEVREPO="https://github.com/M0Rf30/android-udev-rules.git"
cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 && UDEVNOTICE=""
ARGV0="${ARGV0#./}"
export PATH="$CURRENTDIR:$PATH"
BIN="${ARGV0#./}"
unset ARGV0
export PATH="$CURRENTDIR/bin:$PATH"
_get_udev_rules() {
if cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1; then
echo "ERROR: udev rules are already installed!"
echo "Errors persisting with installed udev rules may be due to missing"
echo "Errors persisting with installed udev rules may be due to missing"
echo "udev rules for device or lack of permissions from device"
exit 1
fi
Expand Down Expand Up @@ -71,14 +81,15 @@ _get_udev_rules() {
_get_symlinks() {
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
links="adb etc1tool fastboot hprof-conv make_f2fs make_f2fs_casefold mke2fs sqlite3"
links="$(find "$CURRENTDIR"/shared/bin -maxdepth 1 -exec file {} \; \
| awk -F":" '/ELF/ {print $1}' | xargs -I {} basename {} 2>/dev/null)"
echo ""
echo "This function will make wrapper symlinks in $BINDIR"
echo "that will point to $APPIMAGE with the names:"
echo "$links" | tr ' ' '\n'
echo ""
echo "Make sure there are not existing files $BINDIR with those names"
printf '\n%s' "Proceed with the symlink creation? (Y/n): "
printf '\n%s' "Proceed with the symlink creation? (Y/n): "
read -r yn
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
echo "Aborting..."
Expand All @@ -92,46 +103,41 @@ _get_symlinks() {
}
# logic
case "$ARGV0" in
'adb'|'etc1tool'|'fastboot'|'hprof-conv'|\
'make_f2fs'|'make_f2fs_casefold'|'mke2fs'|'sqlite3')
"$CURRENTDIR/$ARGV0" "$@" || echo "$UDEVNOTICE"
if [ -n "$BIN" ] && [ -e "$CURRENTDIR/bin/$BIN" ]; then
"$CURRENTDIR/bin/$BIN" "$@" || echo "$UDEVNOTICE"
elif [ -n "$1" ] && [ -e "$CURRENTDIR/bin/$1" ]; then
option="$1"
shift
"$CURRENTDIR/bin/$option" "$@" || echo "$UDEVNOTICE"
else
case "$1" in
'--getudev')
_get_udev_rules
;;
'--getlinks')
_get_symlinks
;;
*)
case $1 in
'adb'|'etc1tool'|'fastboot'|'hprof-conv'|\
'make_f2fs'|'make_f2fs_casefold'|'mke2fs'|'sqlite3')
option="$1"
shift
"$CURRENTDIR/$option" "$@" || echo "$UDEVNOTICE"
;;
'--getudev')
_get_udev_rules
;;
'--getlinks')
_get_symlinks
;;
*)
echo ""
echo "USAGE: \"${APPIMAGE##*/} [ARGUMENT]\""
echo "EXAMPLE: \"${APPIMAGE##*/} adb shell\" to enter adb shell"
echo ""
echo "You can also make a symlink to $APPIMAGE named adb"
echo "and run the symlink to enter adb without typing ${APPIMAGE##*/}"
echo ""
echo 'use "--getlinks" if you want to make the symlinks automatically'
echo ""
exit 1
;;
esac
;;
esac
echo ""
echo "USAGE: \"${APPIMAGE##*/} [ARGUMENT]\""
echo "EXAMPLE: \"${APPIMAGE##*/} adb shell\" to enter adb shell"
echo ""
echo "You can also make a symlink to $APPIMAGE named adb"
echo "and run the symlink to enter adb without typing ${APPIMAGE##*/}"
echo ""
echo 'use "--getlinks" if you want to make the symlinks automatically'
echo ""
exit 1
;;
esac
fi
EOF
chmod a+x ./AppRun
export VERSION="$(awk -F"=" '/vision/ {print $2}' ./usr/bin/source.properties)"
export VERSION="$(awk -F"=" '/vision/ {print $2}' ./shared/bin/source.properties)"

# Do the thing!
cd .. && wget -q "$APPIMAGETOOL" -O appimagetool && chmod +x ./appimagetool
./appimagetool --comp zstd --mksquashfs-opt -Xcompression-level --mksquashfs-opt 22 ./"$APPDIR" || exit 1
./appimagetool --comp zstd \
--mksquashfs-opt -Xcompression-level --mksquashfs-opt 22 ./"$APPDIR" || exit 1
[ -n "$APP" ] && mv ./*.AppImage .. && cd .. && rm -rf "$APP" || exit 1
echo "All Done!"

0 comments on commit bca2191

Please sign in to comment.