Skip to content

Commit 7a4240f

Browse files
authored
Major refactor to AppRun
Now wrapper symlinks can be made to avoid having to type the name of appimage before each binary
1 parent 1a8b62e commit 7a4240f

File tree

1 file changed

+91
-35
lines changed

1 file changed

+91
-35
lines changed

android-tools-appimage.sh

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,102 @@ ln -s ./Android.png ./.DirIcon
3232
cat >> ./AppRun << 'EOF'
3333
#!/bin/sh
3434
CURRENTDIR="$(dirname "$(readlink -f "$0")")"/usr/bin
35-
UDEVNOTICE="If you get errors it might be because of missing android udev rules, use --getudev to install them"
36-
ARGS="$(echo "$@" | cut -f2- -d ' ')"
35+
UDEVNOTICE='No android udev rules detected, use "--getude" to install'
36+
UDEVREPO="https://github.com/M0Rf30/android-udev-rules.git"
3737
export PATH="$CURRENTDIR:$PATH"
38-
if [ "$1" = "adb" ]; then
39-
"$CURRENTDIR"/adb $ARGS || echo "$UDEVNOTICE"
40-
elif [ "$1" = "etc1tool" ]; then
41-
"$CURRENTDIR"/etc1tool $ARGS || echo "$UDEVNOTICE"
42-
elif [ "$1" = "fastboot" ]; then
43-
"$CURRENTDIR"/fastboot $ARGS || echo "$UDEVNOTICE"
44-
elif [ "$1" = "make_f2fs" ]; then
45-
"$CURRENTDIR"/make_f2fs $ARGS || echo "$UDEVNOTICE"
46-
elif [ "$1" = "make_f2fs_casefold" ]; then
47-
"$CURRENTDIR"/make_f2fs_casefold $ARGS || echo "$UDEVNOTICE"
48-
elif [ "$1" = "mke2fs" ]; then
49-
"$CURRENTDIR"/mke2fs $ARGS || echo "$UDEVNOTICE"
50-
elif [ "$1" = "sqlite3" ]; then
51-
"$CURRENTDIR"/sqlite3 $ARGS || echo "$UDEVNOTICE"
52-
elif [ "$1" = "--getudev" ]; then
53-
if cat /etc/udev/rules.d/*droid.rules > /dev/null; then
54-
echo "udev rules already installed"
55-
echo "Errors persisting with installed udev rules may be due to specific phone missing from the rules or insufficient permissions on the phone"
38+
39+
_get_udev_rules() {
40+
if cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1; then
41+
echo "udev rules already installed!"
42+
echo "Errors persisting with installed udev rules may be due to missing"
43+
echo "udev rules for device or lack of permissions from device"
44+
exit 1
45+
fi
46+
if ! command -v git >/dev/null 2>&1; then
47+
echo "ERROR: you need git to use this function"
48+
exit 1
49+
fi
50+
if command -v sudo >/dev/null 2>&1; then
51+
SUDOCMD="sudo"
52+
elif command -v doas >/dev/null 2>&1; then
53+
SUDOCMD="doas"
5654
else
57-
UDEVREPO="https://github.com/M0Rf30/android-udev-rules.git"
58-
git clone "$UDEVREPO"
59-
cd android-udev-rules || exit 1
60-
chmod a+x ./install.sh
61-
echo "udev rules installer from $UDEVREPO"
62-
sudo ./install.sh
63-
cd .. && cat /etc/udev/rules.d/*droid.rules > /dev/null && rm -rf "./android-udev-rules"
55+
echo "ERROR: You need sudo or doas to use this function"
56+
exit 1
6457
fi
65-
else
66-
echo "Error: No command specified, try \"./*tools.AppImage adb shell\" for example"
67-
echo "You can also use aliases or wrapper scripts to not write ./*tools.AppImage every time"
68-
echo "$UDEVNOTICE"
69-
echo "Falling back to example adb shell:"
70-
read -p "Do you wan to run adb shell? (y/n): " yn
58+
printf '%s' "udev rules installer from $UDEVREPO, run installer? (y/N): "
59+
read -r yn
7160
if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
72-
"$CURRENTDIR"/adb shell
61+
tmpudev=".udev_rules_tmp.dir"
62+
git clone "$UDEVREPO" "$tmpudev" && cd "$tmpudev" || exit 1
63+
chmod +x ./install.sh && "$SUDOCMD" ./install.sh
64+
cat /etc/udev/rules.d/*droid.rules >/dev/null 2>&1 || exit 1
65+
cd .. && rm -rf "$tmpudev" || exit 1
66+
echo "udev rules installed successfully!"
67+
else
68+
echo "Aborting..."
69+
exit 1
7370
fi
74-
fi
71+
}
72+
73+
_get_symlinks() {
74+
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
75+
links="adb etc1tool fastboot make_f2fs make_f2fs_casefold mke2fs sqlite3"
76+
echo ""
77+
echo "This function will make wrapper symlinks in $BINDIR"
78+
echo "that will point to $APPIMAGE"
79+
echo ""
80+
echo "with the names: \"$links\""
81+
echo ""
82+
echo "Make sure there are not existing files $BINDIR with those names"
83+
printf '\n%s' "Proceed with the symlink creation? (Y/n): "
84+
read -r yn
85+
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
86+
echo "Aborting..."
87+
exit 1
88+
fi
89+
mkdir -p "$BINDIR" || exit 1
90+
for link in $links; do
91+
ln -s "$APPIMAGE" "$BINDIR/$link" 2>/dev/null \
92+
&& echo "\"$link\" symlink successfully created in \"$BINDIR\""
93+
done
94+
}
95+
96+
# logic
97+
case $ARGV0 in
98+
'adb'|'etc1tool'|'fastboot'|'make_f2fs'|\
99+
'make_f2fs_casefold'|'mke2fs'|'sqlite3')
100+
"$CURRENTDIR/$ARGV0" "$@" || echo "$UDEVNOTICE"
101+
;;
102+
*)
103+
case $1 in
104+
'adb'|'etc1tool'|'fastboot'|'make_f2fs'|\
105+
'make_f2fs_casefold'|'mke2fs'|'sqlite3')
106+
option="$1"
107+
shift
108+
"$CURRENTDIR/$option" "$@" || echo "$UDEVNOTICE"
109+
;;
110+
'--getudev')
111+
_get_udev_rules
112+
;;
113+
'--getlinks')
114+
_get_symlinks
115+
;;
116+
*)
117+
echo ""
118+
echo "USAGE: \"${APPIMAGE##*/} [ARGUMENT]\""
119+
echo "EXAMPLE: \"${APPIMAGE##*/} adb shell\" to enter adb shell"
120+
echo ""
121+
echo "You can also make a symlink to $APPIMAGE named adb"
122+
echo "and run the symlink to enter adb without typing ${APPIMAGE##*/}"
123+
echo ""
124+
echo 'use "--getlinks" if you want to make the symlinks automatically'
125+
echo ""
126+
exit 1
127+
;;
128+
esac
129+
;;
130+
esac
75131
EOF
76132
chmod a+x ./AppRun
77133
APPVERSION=$(awk -F = '/Revision/ {print $2; exit}' ./usr/bin/source.properties)

0 commit comments

Comments
 (0)