Skip to content

Commit f0b303f

Browse files
authored
big refactor, use wrapper scripts and hooks from anylinux repo (#12)
1 parent c4865b9 commit f0b303f

File tree

5 files changed

+101
-141
lines changed

5 files changed

+101
-141
lines changed

Android.png

-37.9 KB
Binary file not shown.

AppDir/AppRun

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
CURRENTDIR="$(cd "${0%/*}" && echo "$PWD")"
6+
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
7+
BIN="${ARGV0:-$0}"
8+
BIN="${BIN##*/}"
9+
unset ARGV0
10+
11+
_get_symlinks() {
12+
set -- "$CURRENTDIR"/bin/*
13+
echo ""
14+
echo "This function will make wrapper symlinks in $BINDIR"
15+
echo "that will point to ${APPIMAGE##*/}, this way when you run that"
16+
echo "symlink it automatically runs that binary without extra arguments"
17+
echo ""
18+
printf '%s' "Proceed with the symlink creation? (Y/n): "; read -r yn
19+
case "$yn" in
20+
n*|N*) >&2 echo "Aborting..."; exit 1;;
21+
esac
22+
mkdir -p "$BINDIR"
23+
for link do
24+
case "$link" in
25+
*xdg-open|*.hook|*.conf) continue;;
26+
esac
27+
link="${link##*/}"
28+
ln -s "$APPIMAGE" "$BINDIR"/"$link" 2>/dev/null \
29+
&& echo "'$link' successfully created in '$BINDIR'"
30+
done
31+
exit 0
32+
}
33+
34+
# additional scripts can be placed in the top level bin dir
35+
# those with a name that ends up .hook will be executed in teh current shell
36+
# while those that end with bg.hook will be executed in the background
37+
for hook in "$CURRENTDIR"/bin/*.hook; do
38+
[ -x "$hook" ] || continue
39+
case "$hook" in
40+
*.bg.hook) "$hook" &;;
41+
*.hook) "$hook" ;;
42+
esac
43+
done
44+
45+
if [ "$1" = '--getlinks' ]; then
46+
_get_symlinks
47+
fi
48+
49+
# Check if ARGV0 matches any bundled binary, fallback to $1, then main bin
50+
if [ -f "$CURRENTDIR"/bin/"$BIN" ]; then
51+
exec "$CURRENTDIR"/bin/"$BIN" "$@"
52+
elif [ -f "$CURRENTDIR"/bin/"$1" ]; then
53+
BIN="$1"
54+
shift
55+
exec "$CURRENTDIR"/bin/"$BIN" "$@"
56+
else
57+
>&2 echo "Using default binary adb..."
58+
>&2 echo "Run ${APPIMAGE##*/} --getlinks for more info"
59+
exec "$CURRENTDIR"/bin/adb "$@"
60+
fi

AppDir/android-tools.desktop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Desktop Entry]
2+
Name=Android-platform-tools
3+
Type=Application
4+
Icon=android-tools
5+
Exec=android-tools
6+
Categories=Utility;
7+
Terminal=true
8+
Hidden=true

AppDir/android-tools.png

10.1 KB
Loading

android-tools-appimage.sh

Lines changed: 33 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,47 @@
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

15143
UPINFO="$(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"
15345
chmod +x ./pelf
15446
echo "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

16456
echo "Generating zsync file..."
16557
zsyncmake ./*.AppBundle -u ./*.AppBundle

0 commit comments

Comments
 (0)