Skip to content

Commit

Permalink
Compatibility for latest whatsmeow versions (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterXProgrammer authored Apr 15, 2024
1 parent 549778b commit ba85b26
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 120 deletions.
42 changes: 14 additions & 28 deletions .github/workflows/build_mdtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Get Commit Hash
id: get-commit-hash
run: |
git clone https://github.com/tulir/whatsmeow
git clone --depth 1 https://github.com/tulir/whatsmeow
cd whatsmeow
echo "commit_hash=$(git show HEAD | grep -Eo '^commit [0-9a-f]{40}' | awk '{print $2}')" >> "$GITHUB_OUTPUT"
Expand All @@ -32,53 +32,39 @@ jobs:
platform: [arm, aarch64, i686, x86_64]

steps:
- name: Install Docker
run: |
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=\"$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- name: Set Build Architecture
run: |
if [ "${{ matrix.platform }}" = "aarch64" ]; then
echo "arch_name=arm64" >> $GITHUB_ENV
echo "ARCH_NAME=arm64" >> $GITHUB_ENV
elif [ "${{ matrix.platform }}" = "i686" ]; then
echo "arch_name=x86" >> $GITHUB_ENV
echo "ARCH_NAME=x86" >> $GITHUB_ENV
else
echo "arch_name=${{ matrix.platform }}" >> $GITHUB_ENV
echo "ARCH_NAME=${{ matrix.platform }}" >> $GITHUB_ENV
fi
- name: Build Mdtest
run: |
mkdir -p build
# Support for ARM and AARCH64
if [[ "${{ matrix.platform }}" == "arm" || "${{ matrix.platform }}" == "aarch64" ]]; then
docker pull aptman/qus
docker run --rm --privileged aptman/qus -s -- -p arm aarch64
fi
docker pull termux/termux-docker:${{ matrix.platform }}
docker run --privileged --name mdtest-${{ matrix.platform }} termux/termux-docker:${{ matrix.platform }} bash -c "yes | pkg upgrade -y && pkg install -y git && git clone https://github.com/HunterXProgrammer/Tasker-MdtestV5 --depth 1 repo && cd repo && bash build_whatsmeow5.sh"
docker cp mdtest-${{ matrix.platform }}:/data/data/com.termux/files/home/repo/build/mdtest.zip build/mdtest-${{ env.arch_name }}.zip
docker run --privileged --name "mdtest-${{ env.ARCH_NAME }}" "termux/termux-docker:${{ matrix.platform }}" bash -c "
while true; do yes | pkg upgrade -y && break; done && \
pkg install -y git && \
git clone --depth 1 'https://github.com/${{ env.GITHUB_REPOSITORY }}' repo && \
cd repo && \
bash build_whatsmeow5.sh \
"
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: mdtest-${{ env.arch_name }}
path: build/mdtest-${{ env.arch_name }}.zip
docker cp "mdtest-${{ env.ARCH_NAME }}":/data/data/com.termux/files/home/repo/build/mdtest.zip .
- name: Upload Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/mdtest-${{ env.arch_name }}.zip
asset_name: mdtest-${{ env.arch_name }}.zip
file: mdtest.zip
asset_name: "mdtest-${{ env.ARCH_NAME }}.zip"
tag: "MdtestV5-Assets"
release_name: "Assets for Project MdtestV5"
body: "This release of MdtestV5 uses whatsmeow repo commit hash: ${{needs.get_commit_hash.outputs.commit-hash}}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- name: Get Commit Hash
run: |
git clone https://github.com/tulir/whatsmeow target-repo
git clone --depth 1 https://github.com/tulir/whatsmeow target-repo
cd target-repo
echo "commit_hash=$(git show HEAD | grep -Eo '^commit [0-9a-f]{40}' | awk '{print $2}')" >> $GITHUB_ENV
Expand Down
76 changes: 35 additions & 41 deletions build_whatsmeow5.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
#!/usr/bin/bash

if [ -n $TERMUX_VERSION ]; then
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 "The script should run on Termux"
echo "This script should run on Termux"
exit 1
fi

current_dir="$(pwd)"
tmpdir="$(mktemp -d)"
CURRENT_DIR="$(pwd)"
TMP_DIR="$(mktemp -d)"

cd $tmpdir
cd "$TMP_DIR"

git clone https://github.com/tulir/whatsmeow
git clone --depth 1 https://github.com/tulir/whatsmeow

if [ -n $TERM ]; then
clear
fi
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"
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
if [ -n $TERMUX_VERSION ]; then
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
fi
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
Expand All @@ -40,62 +37,59 @@ mdtest_script='#!/system/bin/sh
dir="$(cd "$(dirname "$0")"; pwd)"
bin_name="$(basename "$0")"
chmod 744 "$0" &>/dev/null
chmod 744 "$dir/${bin_name}.bin" &>/dev/null
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
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" "$@"
exec "$dir/${bin_name}.bin" "$@"
fi'

go build -ldflags="-extldflags -s" -o mdtest.bin

#echo "$TMP_DIR"
#exit 0

if [ $? -eq 0 ]; then
if [ -n $TERMUX_VERSION ]; then
termux-elf-cleaner ${tmpdir}/whatsmeow/mdtest/mdtest.bin &>/dev/null
fi
cd $current_dir
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 ${tmpdir}/whatsmeow/mdtest/mdtest.bin .
cp "$TMP_DIR/whatsmeow/mdtest/mdtest.bin" .
if [ $? -ne 0 ]; then
rm -rf $tmpdir &>/dev/null
rm -rf "$TMP_DIR" &>/dev/null
echo "Error occured, exiting..."
exit 1
exit 1
fi
echo "$mdtest_script" > mdtest
chmod 744 mdtest mdtest.bin
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 $tmpdir &>/dev/null
rm -rf "$TMP_DIR" &>/dev/null
echo "Error occured, exiting..."
exit 1
fi

rm -rf $tmpdir &>/dev/null
#echo $tmpdir
#exit 0
rm -rf "$TMP_DIR" &>/dev/null

#go clean -cache

echo -e "\nSuccessfuly built Mdtest. Adding media support\nusing ffmpeg...\n"

cd $current_dir
cd "$CURRENT_DIR"

bash res/build_dynamic.sh ffmpeg

if [ -n $TERMUX_VERSION ]; then
pkg clean
fi
pkg clean

chmod 744 build/ffmpeg build/ffmpeg.bin
chmod 755 build/ffmpeg build/ffmpeg.bin

rm -rf ffmpeg &>/dev/null

Expand All @@ -121,6 +115,6 @@ mkdir -p ~/whatsmeow5/mdtest

7z x -aoa mdtest.zip -o$HOME/whatsmeow5/mdtest &>/dev/null

chmod 744 ~/whatsmeow5/mdtest/mdtest
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"
1 change: 1 addition & 0 deletions res/1) Correcting imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ code_body='
_ "image/png"
"os/exec"
"sync"
"go.mau.fi/util/random"
//stop
'

Expand Down
2 changes: 1 addition & 1 deletion res/5) Add args support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ code_body='
//stop
'

sed -i -e "$(($(grep -nm 1 -F 'c := make(chan os.Signal)' whatsmeow/mdtest/main.go | sed 's/:.*//')-1))r /dev/stdin" whatsmeow/mdtest/main.go <<< $code_body
sed -i -e "$(($(grep -nm 1 -F 'c := make(chan os.Signal, 1)' whatsmeow/mdtest/main.go | sed 's/:.*//')-1))r /dev/stdin" whatsmeow/mdtest/main.go <<< $code_body
8 changes: 8 additions & 0 deletions res/7) Trim and fix code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ step_name="$(basename "$0" | sed -E 's/^[0-9]+\) //' | sed -E 's/\.sh$//')"
step_number="$(basename "$0" | grep -Eo '^[0-9]+')"
echo "$step_number) $step_name"

code_body='
//start
"sync/atomic"
//stop
'

sed -i -e "$(grep -nm 1 -F '"errors"' whatsmeow/message.go | sed 's/:.*//')r /dev/stdin" whatsmeow/message.go <<< $code_body

code_body='
//start
var greatestChunkOrder uint32 = 0
Expand Down
Loading

0 comments on commit ba85b26

Please sign in to comment.