11#! /bin/sh
22
3- set -eu
3+ set -eux
44
5- export ARCH=" $( uname -m) "
6- APP=android-tools-appimage
7- SITE=" https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
8- ICON=" https://github.com/pkgforge-dev/android-tools-AppImage/blob/main/Android.png?raw=true"
9- APPIMAGETOOL=" https://github.com/pkgforge-dev/appimagetool-uruntime/releases/download/continuous/appimagetool-$ARCH .AppImage"
10- UPINFO=" gh-releases-zsync|$( echo " $GITHUB_REPOSITORY " | tr ' /' ' |' ) |latest|*$ARCH .AppImage.zsync"
11- LIB4BIN=" https://raw.githubusercontent.com/VHSgunzo/sharun/refs/heads/main/lib4bin"
5+ ARCH=" $( uname -m) "
6+ URUNTIME=" https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/useful-tools/uruntime2appimage.sh"
7+ SHARUN=" https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/useful-tools/quick-sharun.sh"
8+ BINARY=" https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
9+ UDEV=" https://raw.githubusercontent.com/M0Rf30/android-udev-rules/refs/heads/main/51-android.rules"
1210
13- # CREATE DIRECTORIES AND DOWNLOAD THE ARCHIVE
14- mkdir -p ./AppDir/shared
15- cd ./AppDir
16- wget " $SITE "
17- unzip -q * .zip
18- rm -f ./* .zip
19- mv -v ./platform-tools ./shared/bin
20-
21- # DESKTOP & ICON
22- cat >> ./android-tools.desktop << 'EOF '
23- [Desktop Entry]
24- Name=Android-platform-tools
25- Type=Application
26- Icon=Android
27- Exec=android-tools
28- Categories=Utility;
29- Terminal=true
30- Hidden=true
31- EOF
32- wget " $ICON " -O ./Android.png
33- ln -s ./Android.png ./.DirIcon
11+ export ADD_HOOKS=" udev-installer.hook"
12+ export UPINFO=" gh-releases-zsync|${GITHUB_REPOSITORY%/* } |${GITHUB_REPOSITORY#*/ } |latest|*$ARCH .AppImage.zsync"
13+ export URUNTIME_PRELOAD=1 # really needed here
3414
35- # BUNDLE ALL DEPENDENCIES
36- wget " $LIB4BIN " -O ./lib4bin
37- chmod +x ./lib4bin
38-
39- ./lib4bin -p -v -s -k ./shared/bin/*
15+ # CREATE DIRECTORIES AND DOWNLOAD THE ARCHIVE
16+ mkdir -p ./AppDir/shared/bin ./AppDir/bin ./AppDir/etc/udev/rules.d
17+ wget --retry-connrefused --tries=30 " $BINARY " -O ./bin.zip
18+ unzip -q ./bin.zip
19+ rm -f ./bin.zip
20+ cp -v ./platform-tools/mke2fs.conf ./AppDir/bin
21+ mv -v ./platform-tools/* ./AppDir/shared/bin
4022
41- # AppRun
42- cat >> ./AppRun << 'EOF '
43- #!/usr/bin/env sh
44- CURRENTDIR="$(dirname "$(readlink -f "$0")")"
45- UDEVNOTICE='No android udev rules detected, use "--getudev" to install'
46- UDEVREPO="https://github.com/M0Rf30/android-udev-rules.git"
47- cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 && UDEVNOTICE=""
48- cat /usr/lib/udev/rules.d/*droid.rules >/dev/null 2>&1 && UDEVNOTICE=""
49- BIN="${ARGV0#./}"
50- unset ARGV0
51- export PATH="$CURRENTDIR/bin:$PATH"
23+ VERSION=" $( awk -F" =" ' /Revision/{print $2; exit}' ./AppDir/shared/bin/source.properties) "
24+ [ -n " $VERSION " ] && echo " $VERSION " > ~ /version
25+ export OUTNAME=Android_Tools-" $VERSION " -anylinux-" $ARCH " .AppImage
5226
53- _get_udev_rules() {
54- if cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 \
55- || cat /usr/lib/udev/rules.d/*droid.rules >/dev/null 2>&1; then
56- echo "ERROR: udev rules are already installed!"
57- echo "Errors persisting with installed udev rules may be due to missing"
58- echo "udev rules for device or lack of permissions from device"
59- exit 1
60- fi
61- if ! command -v git >/dev/null 2>&1; then
62- echo "ERROR: you need git to use this function"
63- exit 1
64- fi
65- if command -v sudo >/dev/null 2>&1; then
66- SUDOCMD="sudo"
67- elif command -v doas >/dev/null 2>&1; then
68- SUDOCMD="doas"
69- else
70- echo "ERROR: You need sudo or doas to use this function"
71- exit 1
72- fi
73- printf '%s' "udev rules installer from $UDEVREPO, run installer? (y/N): "
74- read -r yn
75- if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
76- tmpudev=".udev_rules_tmp.dir"
77- git clone "$UDEVREPO" "$tmpudev" && cd "$tmpudev" || exit 1
78- chmod +x ./install.sh && "$SUDOCMD" ./install.sh
79- cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 || exit 1
80- cd .. && rm -rf "$tmpudev" || exit 1
81- echo "udev rules installed successfully!"
82- else
83- echo "Aborting..."
84- exit 1
85- fi
86- }
27+ # add udev rules
28+ wget --retry-connrefused --tries=30 " $UDEV " -O ./AppDir/etc/udev/rules.d/51-android.rules
8729
88- _get_symlinks() {
89- BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
90- links="$(find "$CURRENTDIR"/shared/bin -maxdepth 1 -exec file {} \; \
91- | awk -F":" '/ELF/ {print $1}' | xargs -I {} basename {} 2>/dev/null)"
92- echo ""
93- echo "This function will make wrapper symlinks in $BINDIR"
94- echo "that will point to $APPIMAGE with the names:"
95- echo "$links" | tr ' ' '\n'
96- echo ""
97- echo "Make sure there are not existing files $BINDIR with those names"
98- printf '\n%s' "Proceed with the symlink creation? (Y/n): "
99- read -r yn
100- if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
101- echo "Aborting..."
102- exit 1
103- fi
104- mkdir -p "$BINDIR" || exit 1
105- for link in $links; do
106- ln -s "$APPIMAGE" "$BINDIR/$link" 2>/dev/null \
107- && echo "\"$link\" symlink successfully created in \"$BINDIR\""
108- done
109- }
30+ # DEPLOY ALL LIBS
31+ wget --retry-connrefused --tries=30 " $SHARUN " -O ./quick-sharun
32+ chmod +x ./quick-sharun
33+ ./quick-sharun ./AppDir/shared/bin/*
11034
111- # logic
112- if [ -n "$BIN" ] && [ -e "$CURRENTDIR/bin/$BIN" ]; then
113- "$CURRENTDIR/bin/$BIN" "$@" || echo "$UDEVNOTICE"
114- elif [ -n "$1" ] && [ -e "$CURRENTDIR/bin/$1" ]; then
115- option="$1"
116- shift
117- "$CURRENTDIR/bin/$option" "$@" || echo "$UDEVNOTICE"
118- else
119- case "$1" in
120- '--getudev')
121- _get_udev_rules
122- ;;
123- '--getlinks')
124- _get_symlinks
125- ;;
126- *)
127- echo ""
128- echo "USAGE: \"${APPIMAGE##*/} [ARGUMENT]\""
129- echo "EXAMPLE: \"${APPIMAGE##*/} adb shell\" to enter adb shell"
130- echo ""
131- echo "You can also make a symlink to $APPIMAGE named adb"
132- echo "and run the symlink to enter adb without typing ${APPIMAGE##*/}"
133- echo ""
134- echo 'use "--getlinks" if you want to make the symlinks automatically'
135- echo ""
136- exit 1
137- ;;
138- esac
139- fi
140- EOF
141- chmod a+x ./AppRun
142- export VERSION=" $( awk -F" =" ' /vision/ {print $2}' ./shared/bin/source.properties) "
143- echo " $VERSION " > ~ /version
35+ # We also need to be added to a group after installing udev rules
36+ sed -i ' /cp -v/a groupadd -f adbusers; usermod -a -G adbusers $(logname)' ./AppDir/bin/udev-installer.hook
14437
145- # Do the thing!
146- cd ..
147- wget " $APPIMAGETOOL " -O appimagetool
148- chmod +x ./appimagetool
149- ./appimagetool -n -u " $UPINFO " ./AppDir
38+ # MAKE APPIMAGE WITH URUNTIME
39+ wget --retry-connrefused --tries=30 " $URUNTIME " -O ./uruntime2appimage
40+ chmod +x ./uruntime2appimage
41+ ./uruntime2appimage
15042
15143UPINFO=" $( echo " $UPINFO " | sed ' s#.AppImage.zsync#*.AppBundle.zsync#g' ) "
152- wget -O ./pelf " https://github.com/xplshn/pelf/releases/latest/download/pelf_$ARCH "
44+ wget -O ./pelf " https://github.com/xplshn/pelf/releases/latest/download/pelf_$ARCH "
15345chmod +x ./pelf
15446echo " Generating [dwfs]AppBundle..."
15547./pelf \
@@ -159,7 +51,7 @@ echo "Generating [dwfs]AppBundle..."
15951 --add-updinfo " $UPINFO " \
16052 --compression " -C zstd:level=22 -S26 -B8" \
16153 --appbundle-id=" android-tools#github.com/$GITHUB_REPOSITORY :$VERSION @$( date +%d_%m_%Y) " \
162- --output-to ./Android-platform-tools- " $VERSION " -" $ARCH " .dwfs.AppBundle
54+ --output-to ./Android_Tools- " $VERSION " -anylinux -" $ARCH " .dwfs.AppBundle
16355
16456echo " Generating zsync file..."
16557zsyncmake ./* .AppBundle -u ./* .AppBundle
0 commit comments