Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Android.png
Binary file not shown.
60 changes: 60 additions & 0 deletions AppDir/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

set -e

CURRENTDIR="$(cd "${0%/*}" && echo "$PWD")"
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
BIN="${ARGV0:-$0}"
BIN="${BIN##*/}"
unset ARGV0

_get_symlinks() {
set -- "$CURRENTDIR"/bin/*
echo ""
echo "This function will make wrapper symlinks in $BINDIR"
echo "that will point to ${APPIMAGE##*/}, this way when you run that"
echo "symlink it automatically runs that binary without extra arguments"
echo ""
printf '%s' "Proceed with the symlink creation? (Y/n): "; read -r yn
case "$yn" in
n*|N*) >&2 echo "Aborting..."; exit 1;;
esac
mkdir -p "$BINDIR"
for link do
case "$link" in
*xdg-open|*.hook|*.conf) continue;;
esac
link="${link##*/}"
ln -s "$APPIMAGE" "$BINDIR"/"$link" 2>/dev/null \
&& echo "'$link' successfully created in '$BINDIR'"
done
exit 0
}

# additional scripts can be placed in the top level bin dir
# those with a name that ends up .hook will be executed in teh current shell
# while those that end with bg.hook will be executed in the background
for hook in "$CURRENTDIR"/bin/*.hook; do
[ -x "$hook" ] || continue
case "$hook" in
*.bg.hook) "$hook" &;;
*.hook) "$hook" ;;
esac
done

if [ "$1" = '--getlinks' ]; then
_get_symlinks
fi

# Check if ARGV0 matches any bundled binary, fallback to $1, then main bin
if [ -f "$CURRENTDIR"/bin/"$BIN" ]; then
exec "$CURRENTDIR"/bin/"$BIN" "$@"
elif [ -f "$CURRENTDIR"/bin/"$1" ]; then
BIN="$1"
shift
exec "$CURRENTDIR"/bin/"$BIN" "$@"
else
>&2 echo "Using default binary adb..."
>&2 echo "Run ${APPIMAGE##*/} --getlinks for more info"
exec "$CURRENTDIR"/bin/adb "$@"
fi
8 changes: 8 additions & 0 deletions AppDir/android-tools.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Name=Android-platform-tools
Type=Application
Icon=android-tools
Exec=android-tools
Categories=Utility;
Terminal=true
Hidden=true
Binary file added AppDir/android-tools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 33 additions & 141 deletions android-tools-appimage.sh
Original file line number Diff line number Diff line change
@@ -1,155 +1,47 @@
#!/bin/sh

set -eu
set -eux

export ARCH="$(uname -m)"
APP=android-tools-appimage
SITE="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
ICON="https://github.com/pkgforge-dev/android-tools-AppImage/blob/main/Android.png?raw=true"
APPIMAGETOOL="https://github.com/pkgforge-dev/appimagetool-uruntime/releases/download/continuous/appimagetool-$ARCH.AppImage"
UPINFO="gh-releases-zsync|$(echo "$GITHUB_REPOSITORY" | tr '/' '|')|latest|*$ARCH.AppImage.zsync"
LIB4BIN="https://raw.githubusercontent.com/VHSgunzo/sharun/refs/heads/main/lib4bin"
ARCH="$(uname -m)"
URUNTIME="https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/useful-tools/uruntime2appimage.sh"
SHARUN="https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/useful-tools/quick-sharun.sh"
BINARY="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
UDEV="https://raw.githubusercontent.com/M0Rf30/android-udev-rules/refs/heads/main/51-android.rules"

# CREATE DIRECTORIES AND DOWNLOAD THE ARCHIVE
mkdir -p ./AppDir/shared
cd ./AppDir
wget "$SITE"
unzip -q *.zip
rm -f ./*.zip
mv -v ./platform-tools ./shared/bin

# DESKTOP & ICON
cat >> ./android-tools.desktop << 'EOF'
[Desktop Entry]
Name=Android-platform-tools
Type=Application
Icon=Android
Exec=android-tools
Categories=Utility;
Terminal=true
Hidden=true
EOF
wget "$ICON" -O ./Android.png
ln -s ./Android.png ./.DirIcon
export ADD_HOOKS="udev-installer.hook"
export UPINFO="gh-releases-zsync|${GITHUB_REPOSITORY%/*}|${GITHUB_REPOSITORY#*/}|latest|*$ARCH.AppImage.zsync"
export URUNTIME_PRELOAD=1 # really needed here

# BUNDLE ALL DEPENDENCIES
wget "$LIB4BIN" -O ./lib4bin
chmod +x ./lib4bin

./lib4bin -p -v -s -k ./shared/bin/*
# CREATE DIRECTORIES AND DOWNLOAD THE ARCHIVE
mkdir -p ./AppDir/shared/bin ./AppDir/bin ./AppDir/etc/udev/rules.d
wget --retry-connrefused --tries=30 "$BINARY" -O ./bin.zip
unzip -q ./bin.zip
rm -f ./bin.zip
cp -v ./platform-tools/mke2fs.conf ./AppDir/bin
mv -v ./platform-tools/* ./AppDir/shared/bin

# AppRun
cat >> ./AppRun << 'EOF'
#!/usr/bin/env sh
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=""
cat /usr/lib/udev/rules.d/*droid.rules >/dev/null 2>&1 && UDEVNOTICE=""
BIN="${ARGV0#./}"
unset ARGV0
export PATH="$CURRENTDIR/bin:$PATH"
VERSION="$(awk -F"=" '/Revision/{print $2; exit}' ./AppDir/shared/bin/source.properties)"
[ -n "$VERSION" ] && echo "$VERSION" > ~/version
export OUTNAME=Android_Tools-"$VERSION"-anylinux-"$ARCH".AppImage

_get_udev_rules() {
if cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 \
|| cat /usr/lib/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 "udev rules for device or lack of permissions from device"
exit 1
fi
if ! command -v git >/dev/null 2>&1; then
echo "ERROR: you need git to use this function"
exit 1
fi
if command -v sudo >/dev/null 2>&1; then
SUDOCMD="sudo"
elif command -v doas >/dev/null 2>&1; then
SUDOCMD="doas"
else
echo "ERROR: You need sudo or doas to use this function"
exit 1
fi
printf '%s' "udev rules installer from $UDEVREPO, run installer? (y/N): "
read -r yn
if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
tmpudev=".udev_rules_tmp.dir"
git clone "$UDEVREPO" "$tmpudev" && cd "$tmpudev" || exit 1
chmod +x ./install.sh && "$SUDOCMD" ./install.sh
cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 || exit 1
cd .. && rm -rf "$tmpudev" || exit 1
echo "udev rules installed successfully!"
else
echo "Aborting..."
exit 1
fi
}
# add udev rules
wget --retry-connrefused --tries=30 "$UDEV" -O ./AppDir/etc/udev/rules.d/51-android.rules

_get_symlinks() {
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
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): "
read -r yn
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
echo "Aborting..."
exit 1
fi
mkdir -p "$BINDIR" || exit 1
for link in $links; do
ln -s "$APPIMAGE" "$BINDIR/$link" 2>/dev/null \
&& echo "\"$link\" symlink successfully created in \"$BINDIR\""
done
}
# DEPLOY ALL LIBS
wget --retry-connrefused --tries=30 "$SHARUN" -O ./quick-sharun
chmod +x ./quick-sharun
./quick-sharun ./AppDir/shared/bin/*

# logic
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
;;
*)
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}' ./shared/bin/source.properties)"
echo "$VERSION" > ~/version
# We also need to be added to a group after installing udev rules
sed -i '/cp -v/a groupadd -f adbusers; usermod -a -G adbusers $(logname)' ./AppDir/bin/udev-installer.hook

# Do the thing!
cd ..
wget "$APPIMAGETOOL" -O appimagetool
chmod +x ./appimagetool
./appimagetool -n -u "$UPINFO" ./AppDir
# MAKE APPIMAGE WITH URUNTIME
wget --retry-connrefused --tries=30 "$URUNTIME" -O ./uruntime2appimage
chmod +x ./uruntime2appimage
./uruntime2appimage

UPINFO="$(echo "$UPINFO" | sed 's#.AppImage.zsync#*.AppBundle.zsync#g')"
wget -O ./pelf "https://github.com/xplshn/pelf/releases/latest/download/pelf_$ARCH"
wget -O ./pelf "https://github.com/xplshn/pelf/releases/latest/download/pelf_$ARCH"
chmod +x ./pelf
echo "Generating [dwfs]AppBundle..."
./pelf \
Expand All @@ -159,7 +51,7 @@ echo "Generating [dwfs]AppBundle..."
--add-updinfo "$UPINFO" \
--compression "-C zstd:level=22 -S26 -B8" \
--appbundle-id="android-tools#github.com/$GITHUB_REPOSITORY:$VERSION@$(date +%d_%m_%Y)" \
--output-to ./Android-platform-tools-"$VERSION"-"$ARCH".dwfs.AppBundle
--output-to ./Android_Tools-"$VERSION"-anylinux-"$ARCH".dwfs.AppBundle

echo "Generating zsync file..."
zsyncmake ./*.AppBundle -u ./*.AppBundle
Expand Down