MODDIR=${0%/*}

# Alias for Curl
alias curl='$MODDIR/bin/curl --dns-servers 1.1.1.1,1.0.0.1'

# Variables
ARCH=$(getprop ro.product.cpu.abi)
Latest32=$(curl -s https://codeberg.org/AXP-OS/app_aosmium/releases | grep webview32-signed.apk | grep -m 1 -o https://codeberg.org/AXP-OS/app_aosmium/releases/download/.*.apk)
Latest64=$(curl -s https://codeberg.org/AXP-OS/app_aosmium/releases | grep webview64-signed.apk | grep -m 1 -o https://codeberg.org/AXP-OS/app_aosmium/releases/download/.*.apk)

# Updater
if [[ "$ARCH" = "armeabi-v7a" ]]; then
	echo "Downloading Update..."
	curl -o /data/local/tmp/AosmiumWebView.apk $Latest32
	sleep 1
	echo "Installing Update..."
	su -c pm install --install-location 1 /data/local/tmp/AosmiumWebView.apk
	sleep 1
	echo "Cleaning Up..."
	su -c rm -rf /data/local/tmp/AosmiumWebView.apk
	sleep 1
	echo "Update Done!"
else
	echo "Downloading Update..."
	curl -o /data/local/tmp/AosmiumWebView.apk $Latest64
	sleep 1
	echo "Installing Update..."
	su -c pm install --install-location 1 /data/local/tmp/AosmiumWebView.apk
	sleep 1
	echo "Cleaning Up..."
	su -c rm -rf /data/local/tmp/AosmiumWebView.apk
	sleep 1
	echo "Update Done!"
fi
