Skip to content

Commit 6a47b5f

Browse files
authored
refactor
1 parent c4865b9 commit 6a47b5f

File tree

4 files changed

+142
-145
lines changed

4 files changed

+142
-145
lines changed

AppDir/AppRun

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env sh
2+
CURRENTDIR="$(dirname "$(readlink -f "$0")")"
3+
UDEVNOTICE='No android udev rules detected, use "--getudev" to install'
4+
UDEVREPO="https://github.com/M0Rf30/android-udev-rules.git"
5+
cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 && UDEVNOTICE=""
6+
cat /usr/lib/udev/rules.d/*droid.rules >/dev/null 2>&1 && UDEVNOTICE=""
7+
BIN="${ARGV0#./}"
8+
unset ARGV0
9+
export PATH="$CURRENTDIR/bin:$PATH"
10+
11+
_get_udev_rules() {
12+
if cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 \
13+
|| cat /usr/lib/udev/rules.d/*droid.rules >/dev/null 2>&1; then
14+
echo "ERROR: udev rules are already installed!"
15+
echo "Errors persisting with installed udev rules may be due to missing"
16+
echo "udev rules for device or lack of permissions from device"
17+
exit 1
18+
fi
19+
if ! command -v git >/dev/null 2>&1; then
20+
echo "ERROR: you need git to use this function"
21+
exit 1
22+
fi
23+
if command -v sudo >/dev/null 2>&1; then
24+
SUDOCMD="sudo"
25+
elif command -v doas >/dev/null 2>&1; then
26+
SUDOCMD="doas"
27+
else
28+
echo "ERROR: You need sudo or doas to use this function"
29+
exit 1
30+
fi
31+
printf '%s' "udev rules installer from $UDEVREPO, run installer? (y/N): "
32+
read -r yn
33+
if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
34+
tmpudev=".udev_rules_tmp.dir"
35+
git clone "$UDEVREPO" "$tmpudev" && cd "$tmpudev" || exit 1
36+
chmod +x ./install.sh && "$SUDOCMD" ./install.sh
37+
cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 || exit 1
38+
cd .. && rm -rf "$tmpudev" || exit 1
39+
echo "udev rules installed successfully!"
40+
else
41+
echo "Aborting..."
42+
exit 1
43+
fi
44+
}
45+
46+
_get_symlinks() {
47+
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
48+
links="$(find "$CURRENTDIR"/shared/bin -maxdepth 1 -exec file {} \; \
49+
| awk -F":" '/ELF/ {print $1}' | xargs -I {} basename {} 2>/dev/null)"
50+
echo ""
51+
echo "This function will make wrapper symlinks in $BINDIR"
52+
echo "that will point to $APPIMAGE with the names:"
53+
echo "$links" | tr ' ' '\n'
54+
echo ""
55+
echo "Make sure there are not existing files $BINDIR with those names"
56+
printf '\n%s' "Proceed with the symlink creation? (Y/n): "
57+
read -r yn
58+
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
59+
echo "Aborting..."
60+
exit 1
61+
fi
62+
mkdir -p "$BINDIR" || exit 1
63+
for link in $links; do
64+
ln -s "$APPIMAGE" "$BINDIR/$link" 2>/dev/null \
65+
&& echo "\"$link\" symlink successfully created in \"$BINDIR\""
66+
done
67+
}
68+
69+
# logic
70+
if [ -n "$BIN" ] && [ -e "$CURRENTDIR/bin/$BIN" ]; then
71+
"$CURRENTDIR/bin/$BIN" "$@" || echo "$UDEVNOTICE"
72+
elif [ -n "$1" ] && [ -e "$CURRENTDIR/bin/$1" ]; then
73+
option="$1"
74+
shift
75+
"$CURRENTDIR/bin/$option" "$@" || echo "$UDEVNOTICE"
76+
else
77+
case "$1" in
78+
'--getudev')
79+
_get_udev_rules
80+
;;
81+
'--getlinks')
82+
_get_symlinks
83+
;;
84+
*)
85+
echo ""
86+
echo "USAGE: \"${APPIMAGE##*/} [ARGUMENT]\""
87+
echo "EXAMPLE: \"${APPIMAGE##*/} adb shell\" to enter adb shell"
88+
echo ""
89+
echo "You can also make a symlink to $APPIMAGE named adb"
90+
echo "and run the symlink to enter adb without typing ${APPIMAGE##*/}"
91+
echo ""
92+
echo 'use "--getlinks" if you want to make the symlinks automatically'
93+
echo ""
94+
exit 1
95+
;;
96+
esac
97+
fi

AppDir/android-tools.desktop

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

AppDir/android-tools.png

10.1 KB
Loading

android-tools-appimage.sh

Lines changed: 36 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,46 @@
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"
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"
89
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"
10+
UDEV="https://raw.githubusercontent.com/M0Rf30/android-udev-rules/refs/heads/main/51-android.rules"
1211

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
34-
35-
# BUNDLE ALL DEPENDENCIES
36-
wget "$LIB4BIN" -O ./lib4bin
37-
chmod +x ./lib4bin
38-
39-
./lib4bin -p -v -s -k ./shared/bin/*
40-
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"
12+
export ADD_HOOKS="udev-installer.hook"
13+
export UPINFO="gh-releases-zsync|${GITHUB_REPOSITORY%/*}|${GITHUB_REPOSITORY#*/}|latest|*$ARCH.AppImage.zsync"
14+
export URUNTIME_PRELOAD=1 # really needed here
5215

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-
}
87-
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-
}
110-
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
144-
145-
# Do the thing!
146-
cd ..
147-
wget "$APPIMAGETOOL" -O appimagetool
148-
chmod +x ./appimagetool
149-
./appimagetool -n -u "$UPINFO" ./AppDir
16+
# CREATE DIRECTORIES AND DOWNLOAD THE ARCHIVE
17+
mkdir -p ./AppDir/shared/bin ./AppDir/bin ./AppDir/etc/udev/rules.d
18+
wget "$BINARY" -O ./bin.zip
19+
unzip -q ./bin.zip
20+
rm -f ./bin.zip
21+
cp -v ./platform-tools/lib64 ./AppDir/bin
22+
cp -v ./platform-tools/mke2fs.conf ./AppDir/bin
23+
mv -v ./platform-tools/* ./AppDir/shared/bin
24+
25+
VERSION="$(awk -F"=" '/Revision/{print $2; exit}' ./AppDir/shared/bin/source.properties)"
26+
[ -n "$VERSION" ] && "$VERSION" > ~/version
27+
export OUTNAME=Android_Tools-"$VERSION"-anylinux-"$ARCH".AppImage
28+
29+
# add udev rules
30+
wget --retry-connrefused --tries=30 "$UDEV" -O ./AppDir/etc/udev/rules.d
31+
32+
# DEPLOY ALL LIBS
33+
wget --retry-connrefused --tries=30 "$SHARUN" -O ./quick-sharun
34+
chmod +x ./quick-sharun
35+
./quick-sharun ./AppDir/shared/bin/*
36+
37+
# MAKE APPIMAGE WITH URUNTIME
38+
wget --retry-connrefused --tries=30 "$URUNTIME" -O ./uruntime2appimage
39+
chmod +x ./uruntime2appimage
40+
./uruntime2appimage
15041

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

16455
echo "Generating zsync file..."
16556
zsyncmake ./*.AppBundle -u ./*.AppBundle

0 commit comments

Comments
 (0)