-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preinstall.sh
84 lines (82 loc) · 2.98 KB
/
preinstall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
chmod -R 0755 $TMPDIR/addon/Volume-Key-Selector/tools
export PATH=$TMPDIR/addon/Volume-Key-Selector/tools/$ARCH32:$PATH
keytest() {
ui_print " "
ui_print "
░██████╗░░██████╗
██╔════╝░██╔════╝
██║░░██╗░╚█████╗░
██║░░╚██╗░╚═══██╗
╚██████╔╝██████╔╝
░╚═════╝░╚═════╝░
███████╗██████╗░░█████╗░███╗░░░███╗
╚════██║██╔══██╗██╔══██╗████╗░████║
░░███╔═╝██████╔╝███████║██╔████╔██║
██╔══╝░░██╔══██╗██╔══██║██║╚██╔╝██║
███████╗██║░░██║██║░░██║██║░╚═╝░██║
╚══════╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░░░░╚═╝
"
sleep 3
ui_print " "
ui_print " PRESS ANY VOLUME KEY "
if (timeout 7 /system/bin/getevent -lc 1 2>&1 | /system/bin/grep VOLUME | /system/bin/grep " DOWN" > $TMPDIR/events); then
return 0
else
ui_print " Please Try again "
timeout 7 keycheck
local SEL=$?
[ $SEL -eq 143 ] && abort " Key Not Detected" || return 1
fi
}
chooseport() {
# Original idea by chainfire @xda-developers, improved on by ianmacd @xda-developers
#note from chainfire @xda-developers: getevent behaves weird when piped, and busybox grep likes that even less than toolbox/toybox grep
while true; do
/system/bin/getevent -lc 1 2>&1 | /system/bin/grep VOLUME | /system/bin/grep " DOWN" > $TMPDIR/events
if (`cat $TMPDIR/events 2>/dev/null | /system/bin/grep VOLUME >/dev/null`); then
break
fi
done
if (`cat $TMPDIR/events 2>/dev/null | /system/bin/grep VOLUMEUP >/dev/null`); then
return 0
else
return 1
fi
}
chooseportold() {
# Keycheck binary by someone755 @Github, idea for code below by Zappo @xda-developers
# Calling it first time detects previous input. Calling it second time will do what we want
while true; do
keycheck
keycheck
local SEL=$?
if [ "$1" == "UP" ]; then
UP=$SEL
break
elif [ "$1" == "DOWN" ]; then
DOWN=$SEL
break
elif [ $SEL -eq $UP ]; then
return 0
elif [ $SEL -eq $DOWN ]; then
return 1
fi
done
}
OIFS=$IFS; IFS=\|; MID=false; NEW=false
case $(echo $(basename $ZIPFILE) | tr '[:upper:]' '[:lower:]') in
*novk*) ui_print "- Skipping Vol Keys -";;
*) if keytest; then
VKSEL=chooseport
else
VKSEL=chooseportold
ui_print " ! Legacy device detected! Using old keycheck method"
ui_print " "
ui_print " Volume key check "
ui_print " Press Volume Up "
$VKSEL "UP"
ui_print " Press Volume Down "
$VKSEL "DOWN"
fi;;
esac
IFS=$OIFS