-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild_whatsmeow5.sh
executable file
·120 lines (84 loc) · 3.16 KB
/
build_whatsmeow5.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/bash
if [ -n "$TERMUX_VERSION" ]; then
apt update
yes | pkg install -y git golang ffmpeg termux-elf-cleaner p7zip 2>/dev/null | grep -E '(Need to get |Get:|Unpacking |Setting up )'
else
echo "This script should run on Termux"
exit 1
fi
CURRENT_DIR="$(pwd)"
TMP_DIR="$(mktemp -d)"
cd "$TMP_DIR"
git clone --depth 1 https://github.com/tulir/whatsmeow
clear 2>/dev/null
# Add extended support
echo -e "\n------------------------\n\nAdding extended support:-\n"
find "$CURRENT_DIR/res" -maxdepth 1 -type f -name "*)*" -regex ".*/[0-9]+) .*" | sort -V | while read -r i; do
echo -n " "
bash "$i"
done
echo -e "\nDone adding extended support\n\n------------------------\n"
# fix Termux permissions
value="true"; key="allow-external-apps"; file="/data/data/com.termux/files/home/.termux/termux.properties"; mkdir -p "$(dirname "$file")"; chmod 700 "$(dirname "$file")"; if ! grep -E '^'"$key"'=.*' $file &>/dev/null; then [[ -s "$file" && ! -z "$(tail -c 1 "$file")" ]] && newline=$'\n' || newline=""; echo "$newline$key=$value" >> "$file"; else sed -i'' -E 's/^'"$key"'=.*/'"$key=$value"'/' $file; fi
cd whatsmeow/mdtest
go mod tidy
echo -e "\nFinal step, building mdtest binary. Takes about 10s~1min"
mdtest_script='#!/system/bin/sh
dir="$(cd "$(dirname "$0")"; pwd)"
bin_name="$(basename "$0")"
chmod 755 "$0" "$dir/${bin_name}.bin" 2>/dev/null >/dev/null
if [ $(getprop ro.build.version.sdk) -gt 28 ]; then
if getprop ro.product.cpu.abilist | grep -q "64"
then
exec /system/bin/linker64 "$dir/${bin_name}.bin" "$@"
else
exec /system/bin/linker "$dir/${bin_name}.bin" "$@"
fi
else
exec "$dir/${bin_name}.bin" "$@"
fi'
go build -ldflags="-extldflags -s" -o mdtest.bin
#echo "$TMP_DIR"
#exit 0
if [ $? -eq 0 ]; then
termux-elf-cleaner "$TMP_DIR/whatsmeow/mdtest/mdtest.bin" &>/dev/null
cd "$CURRENT_DIR"
rm -rf build/mdtest.zip build/mdtest build/mdtest.bin &>/dev/null
mkdir -p build
cd build
cp "$TMP_DIR/whatsmeow/mdtest/mdtest.bin" .
if [ $? -ne 0 ]; then
rm -rf "$TMP_DIR" &>/dev/null
echo "Error occured, exiting..."
exit 1
fi
echo "$mdtest_script" > mdtest
chmod 755 mdtest mdtest.bin
7z a -tzip -mx=9 -bd -bso0 mdtest.zip mdtest mdtest.bin
rm -rf mdtest mdtest.bin &>/dev/null
else
rm -rf "$TMP_DIR" &>/dev/null
echo "Error occured, exiting..."
exit 1
fi
rm -rf "$TMP_DIR" &>/dev/null
#go clean -cache
echo -e "\nSuccessfuly built Mdtest. Adding media support\nusing ffmpeg...\n"
cd "$CURRENT_DIR"
bash res/build_dynamic.sh ffmpeg
pkg clean
chmod 755 build/ffmpeg build/ffmpeg.bin
rm -rf ffmpeg &>/dev/null
mkdir -p ffmpeg &>/dev/null
mv build/ffmpeg ffmpeg &>/dev/null
mv build/ffmpeg.bin ffmpeg &>/dev/null
mv build/lib-ffmpeg ffmpeg &>/dev/null
mv ffmpeg build &>/dev/null
cd build
echo -e "Adding ffmpeg to mdtest.zip...\n"
7z a -tzip -mx=9 -bd -bso0 mdtest.zip ffmpeg
rm -rf ffmpeg &>/dev/null
mkdir -p ~/whatsmeow5/mdtest
7z x -aoa mdtest.zip -o$HOME/whatsmeow5/mdtest &>/dev/null
chmod 755 ~/whatsmeow5/mdtest/mdtest
echo -e "All done! You can type this -\n \n\" cd ~/whatsmeow5/mdtest; ./mdtest \"\n\nType without quotes to run Mdtest\n"