chore: rewrite directory name & feat: add lol sulaunchhelper2.sh

This commit is contained in:
2022-05-30 20:12:39 +07:00
parent a5abc5f35c
commit ec2fa3d16d
18 changed files with 327 additions and 0 deletions

View File

@ -0,0 +1,103 @@
#!/bin/bash
declare -a deps=("curl" "unzip" "rm" "7z" "python3")
declare -a patchfiles=("chrome_elf.dll" "config.ini")
if (( $EUID == 0 )); then
echo "Do not run this script as root."
exit
fi
adPatchScript=$(cat << EOF
#!/usr/bin/python3
import re
from pathlib import Path
print("Patching xpui.js...")
xpui = Path("./xpui/xpui.js")
xpui_content = xpui.read_text(encoding="utf-8")
replace_ad = re.sub(r"(\.ads\.leaderboard\.isEnabled)(}|\))", r"\1&&false\2", xpui_content)
replace_upgrade = re.sub(r"\.createElement\([^.,{]+,{onClick:[^.,]+,className:[^.]+\.[^.]+\.UpgradeButton}\),[^.(]+\(\)", "", replace_ad)
xpui.write_text(replace_upgrade, encoding="utf-8")
EOF
)
[[ -z "${WINEPREFIX}" ]] && WINEPREFIX="$HOME/.wine" || WINEPREFIX="${WINEPREFIX}"
SPOTIFY="$WINEPREFIX/drive_c/users/$(whoami)/AppData/Roaming/Spotify/"
SPOTIFY_APPS="$SPOTIFY/Apps/"
xpuiBundlePath="$SPOTIFY_APPS/xpui.spa"
xpuiUnpackedPath="$SPOTIFY_APPS/xpui/xpui.js"
echo "BlockTheSpot install script for Spotify (Wine version)"
echo "BlockTheSpot: https://github.com/mrpond/BlockTheSpot/"
echo "Current Wineprefix: $WINEPREFIX"
TMPDIR=$(mktemp -d)
cd $TMPDIR
for v in "${deps[@]}"
do
if ! [ -x /usr/bin/$v ]; then
echo "Dependency '$v' not found"
exit
fi
done
if ! [ -d "$SPOTIFY" ]; then
echo "Spotify not found, make sure you're using correct wineprefix..."
exit
fi
if [ "$1" == "uninstall" ]; then
if [ -f "$SPOTIFY/chrome_elf_bak.dll" ]; then
echo "Uninstalling BlockTheSpot..."
for v in "${patchfiles[@]}"
do
rm "$SPOTIFY/$v"
done
mv "$SPOTIFY/chrome_elf_bak.dll" "$SPOTIFY/chrome_elf.dll"
echo "Uninstalling xpui patch if found..."
mv "$xpuiBundlePath.bak" "$xpuiBundlePath"
fi
echo "Uninstalling BlockTheSpot (IF INSTALLED) completed."
exit
fi
echo "Downloading BlockTheSpot..."
curl -OL "https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome_elf.zip"
echo "Extracting BlockTheSpot..."
unzip -d chrome_elf chrome_elf.zip
if [ -f "$SPOTIFY/chrome_elf.dll" ] && ! [ -f "$SPOTIFY/chrome_elf_bak.dll" ]; then
echo "Backuping files..."
mv "$SPOTIFY/chrome_elf.dll" "$SPOTIFY/chrome_elf_bak.dll"
fi
WINEPREFIX=$WINEPREFIX wineserver -k
echo "Patching Spotify..."
for v in "${patchfiles[@]}"
do
cp "./chrome_elf/$v" "$SPOTIFY/$v"
done
read -p "Do you want to remove ad placeholder and upgrade button? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [ -f "$xpuiBundlePath" ]; then
echo "Patching xpui.spa..."
if ! [ -f "$xpuiBundlePath.bak" ]; then
mv "$xpuiBundlePath" "$xpuiBundlePath.bak"
fi
unzip -d xpui "$xpuiBundlePath.bak"
fi
echo "$adPatchScript" > "./patch.py"
python3 ./patch.py
7z a xpui.zip "./xpui/*"
mv xpui.zip $xpuiBundlePath
fi
echo "Patching completed, open Spotify and enjoy :D"
echo "Temporary directory used $TMPDIR"

View File

@ -0,0 +1,14 @@
#!/bin/bash
echo "Installing dependencies..."
pkg install aria2 termux-x11
termux-setup-storage
mkdir -p ./tmp/
echo "Downloading Termux-x11..."
aria2c -d ./tmp/ https://nightly.link/termux/termux-x11/workflows/debug_build/master/termux-x11.zip
unzip ./tmp/termux-x11.zip -d ./tmp/
rm termux-x11.zip
echo "Installing..."
apt install ./tmp/termux-x11.deb
mv ./tmp/app-debug.apk ~/storage/shared/Downloads/
echo "NOW PLEASE GO TO YOUR DOWNLOAD FOLDER AND INSTALL TERMUX-X11 MANUALLY."

View File

@ -0,0 +1,20 @@
#!/usr/bin/bash
AUTHOR="tretrauit"
FAKE_APPRUN_SCRIPT='#!/usr/bin/bash
echo "Starting Yuzu..."
"$APPDIR"/usr/bin/yuzu'
echo "pinEApple/Yuzu EA AppImage portable mode launcher by $AUTHOR"
echo "Removing old yuzu folder..."
rm -rf ./squashfs-root
echo "Extracting AppImage..."
./yuzu-x86_64.AppImage --appimage-extract
cd ./squashfs-root/
echo "Patching..."
ln -sf ../user/ ./user
mv ./AppRun-patched ./AppRun-patched.bak
echo "$FAKE_APPRUN_SCRIPT" > ./AppRun-patched
chmod +x ./AppRun-patched
echo "Launching yuzu..."
APPDIR=./ ./AppRun

View File

@ -0,0 +1,87 @@
#!/bin/bash
function check_android () {
if $(uname -o) -ne "Android"
then
return false
fi
return true
}
function proot_install_dependencies () {
apt update -y
apt install git chromium nodejs npm -y
npm install -g --silent yarn
}
function proot_install_proxytext () {
echo "Installing proxytext."
git clone https://gitlab.com/tretrauit/proxytext.git
cd proxytext
yarn install
}
function proot_launch_proxytext () {
echo "Launching proxytext."
cd proxytext
git pull
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium yarn start
}
function install_dependencies () {
echo "Checking dependencies."
declare -a dependencies=("proot-distro")
for i in "${dependencies[@]}"
do
if ! [ -x "$(command -v \"$i\")" ]; then
echo "Installing $i..."
pkg install $i
fi
done
}
function install_dependencies_debian () {
echo "Installing dependencies in Debian proot."
proot-distro login debian --termux-home -- bash ./proxytext-wrapper.sh --proot --install-dependencies
echo "Done."
}
function install_debian() {
echo "Installing Debian proot."
proot-distro install debian
}
function install_proxytext () {
proot-distro login debian --termux-home -- bash ./proxytext-wrapper.sh --proot --install
}
function start_proxytext () {
proot-distro login debian --termux-home -- bash ./proxytext-wrapper.sh --proot --launch
}
if [[ "$1" = "--proot" ]]
then
if [[ "$2" = "--launch" ]]
then
proot_launch_proxytext
elif [[ "$2" = "--install" ]]
then
proot_install_proxytext
elif [[ "$2" = "--install-dependencies" ]]
then
proot_install_dependencies
fi
exit 0
fi
if [[ check_android = false ]];
then
echo "This script only supports Android using Termux."
exit 1
fi
install_dependencies
install_debian
install_dependencies_debian
[ ! -d "./proxytext" ] && install_proxytext
start_proxytext

View File

@ -0,0 +1,16 @@
#!/usr/bin/bash
RCLONE_REMOTE="<remote name>"
# Rclone remote will be mounted to /mnt/runtime/write/emulated/0/ which is equal to /sdcard in File Explorer (aka your home directory) and equal to ~/storage/shared in Termux
ROOT_HOME_DIR="/mnt/runtime/write/emulated/0/"
RCLONE_MOUNT_DIR="<mount directory>"
FINAL_DIR="$ROOT_HOME_DIR$RCLONE_MOUNT_DIR"
if [ "$1" = "unmount" ]; then
sudo pkill -f "rclone --vfs-cache-mode writes -v mount \"$RCLONE_REMOTE\": \"$FINAL_DIR\" --gid 9997 --dir-perms 0771 --file-perms 0660 --umask=0 --allow-other"
sudo fusermount -u "$FINAL_DIR"
echo "$RCLONE_REMOTE should be unmounted now, if fusermount raises Invalid option then that's OK."
else
sudo mkdir -p "$FINAL_DIR"
sudo nohup rclone --vfs-cache-mode writes -v mount "$RCLONE_REMOTE": "$FINAL_DIR" --gid 9997 --dir-perms 0771 --file-perms 0660 --umask=0 --allow-other &
echo "$RCLONE_REMOTE should be mounted now, check $RCLONE_MOUNT_DIR"
fi

View File

@ -0,0 +1,36 @@
#!/bin/bash
RCLONE_PATH="./.rclone-files/"
ARCH=$(uname -m)
RCLONE_URL=""
FUSERMOUNT_URL=""
if [ "$ARCH" == "armv7l" ];then
RCLONE_URL="https://beta.rclone.org/test/testbuilds-latest/rclone-android-16-armv7a.gz"
FUSERMOUNT_URL="https://github.com/Magisk-Modules-Repo/com.piyushgarg.rclone/raw/master/binary/fusermount-arm"
elif [ "$ARCH" == "aarch64" ];then
RCLONE_URL="https://beta.rclone.org/test/testbuilds-latest/rclone-android-21-armv8a.gz"
FUSERMOUNT_URL="https://github.com/Magisk-Modules-Repo/com.piyushgarg.rclone/raw/master/binary/fusermount-arm64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
echo "!!! YOU NEED ROOT TO RUN THIS SCRIPT !!!"
echo "This script was made before I discovered that Termux Rclone can work perfectly too if you mount to /mnt/runtime/write/emulated/0/, using this script may lead to unwanted change in your phone."
read -p "Do you want to continue (Y/n)? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
echo "Installing dependencies..."
pkg install root-repo tsu wget
echo "Setting up Termux shared storage..."
termux-setup-storage
echo "Downloading rclone..."
mkdir -p $RCLONE_PATH
wget -O - $RCLONE_URL | gunzip -c > "$RCLONE_PATH/rclone"
echo "Downloading fusermount..."
wget -O "$RCLONE_PATH/fusermount" $FUSERMOUNT_URL
sudo chmod -R 0755 ./.rclone-files/
echo "Setup completed, you MUST execute ./rclone-shell before using rclone."

45
apps/ws-scrcpy/README.md Normal file
View File

@ -0,0 +1,45 @@
# ws-scrcpy scripts
## ws-scrcpy-launcher.py for Termux
### Notes
+ **YOU NEED TO HAVE WS-SCRCPY INSTALLED, ALONG WITH ROOT ACCESS AND DEPENDENCIES**
+ ~~YOU ALSO NEED TO OPEN ADB WIRELESS IN DEVELOPER SETTINGS FOR THIS TO WORK~~ (The script can use `su` to start ADB wireless now)
+ You need to grant Termux:API full Location permission and set to "Always" (Foreground mode will not work correctly)
+ Rootless mode is available, although it **will not** work in most cases.
+ Dependencies: `root-repo` `tsu` `moreutils` `build-essential` `nodejs` `python3` `android-tools` `git` `termux-api`
> Or execute `pkg install root-repo tsu moreutils build-essential nodejs python3 android-tools git termux-api`
+ You also need to downgrade npm to version 6 to fix Termux problem: `npm install -g npm@6`
> Please ignore the vulnerability message, if you care about it then please don't use this script.
+ Download ws-scrcpy-launcher.py:
```bash
curl -OL https://gitlab.com/tretrauit/scripts/-/raw/main/Apps/ws-scrcpy/ws-scrcpy-launcher.py
chmod +x ws-scrcpy-launcher.py
```
> Execute `./ws-scrcpy-launcher.py` to launch ws-scrcpy with scrcpy server for local device.
+ Full script for lazy people (including install ws-scrcpy steps):
```bash
pkg update
pkg install root-repo moreutils build-essential nodejs python3 android-tools git
pkg install tsu
npm install -g npm@6
cd ~
git clone https://github.com/NetrisTV/ws-scrcpy
cd ./ws-scrcpy
npm install
curl -OL https://gitlab.com/tretrauit/scripts/-/raw/main/Apps/ws-scrcpy/ws-scrcpy-launcher.py
chmod +x ws-scrcpy-launcher.py
```
+ The script will tell you to wait for ws-scrcpy to start, and when it starts it'll show the started message with the ip address and the port to access using browsers
> You need to use `adb pair` to pair termux with your device adb server, then you can launch ws-scrcpy as explained above.

View File

@ -0,0 +1,256 @@
#!/usr/bin/python3
# Rewrite
import sys
import subprocess
import json
import time
import threading
import random
from pathlib import Path
from shutil import which
APP_UUID="a6db95c2-27db-4b88-a687-c8107d1bc9d6"
def Popen(args: list | str, root=False, shell=False, cwd=Path.cwd()):
if root:
if shell:
args = "sudo " + args
else:
args = ["sudo"] + args
result = subprocess.Popen(args, shell=shell, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return result
def run(args: list | str, root=False, shell=False, cwd=Path.cwd()):
if root:
if shell:
args = "sudo " + args
else:
args = ["sudo"] + args
result = subprocess.run(args, shell=shell, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result.check_returncode()
return result
def show_toast(message):
run(["termux-toast", f'{message}'])
def show_notification(title, message=None, vibration: list[int] | str=None, sound=False, ongoing=True, buttons: list[dict] = None):
if not which("termux-notification"):
raise FileNotFoundError("termux-notification not found, please install termux-api package and Termux:API app.")
args = ["termux-notification", "-i", APP_UUID, "--priority", "max", "-t", f'{title}']
if message:
args += ["-c", f'{message}']
if vibration:
args += ["--vibrate", ",".join(str(x) for x in vibration) if isinstance(vibration, list) else vibration]
if sound:
args += ["--sound"]
if ongoing:
args += ["--ongoing"]
if buttons:
count = 1
for btn in buttons:
args += [f"--button{count}", f'{btn["label"]}', f"--button{count}-action", f'{btn["action"]}']
if count >= 3:
break
count += 1
run(args)
def get_wifi():
if not which("termux-wifi-connectioninfo"):
raise FileNotFoundError("termux-wifi-connectioninfo not found, please install termux-api package and Termux:API app.")
return json.loads(subprocess.check_output(["termux-wifi-connectioninfo"]).decode("utf-8"))
def get_wifi_name():
return get_wifi()["ssid"]
def get_device_private_ip():
# We don't use info from get_wifi() because Termux:API may not work if user doesn't grant it all permissions.
return subprocess.check_output(['ifdata', '-pa', 'wlan0']).decode("utf-8").strip()
def get_port_from_process_name(name: str, state: str="LISTEN"):
lsof_output = subprocess.check_output(["sudo", "lsof", "-i", "-P", "-n"]).decode("utf-8")
for line in lsof_output.split("\n"):
if name in line and f"({state})" in line:
line = ' '.join(line.split())
return int(line.strip().split(" ")[8].split(":")[1])
return None
def get_pid_from_port(port: int, state: str="LISTEN"):
lsof_output = subprocess.check_output(["sudo", "lsof", "-i", "-P", "-n"]).decode("utf-8")
for line in lsof_output.split("\n"):
if str(port) in line and f"({state})" in line:
line = ' '.join(line.split())
return line.strip().split(" ")[1]
return None
def start_adbd():
free_port = random.randint(0, 65535)
while get_pid_from_port(free_port):
free_port = random.randint(0, 65535)
print("Starting adbd on port " + str(free_port))
show_notification("Starting adbd", "Starting adbd on port " + str(free_port))
try:
run(["setprop", "service.adb.tcp.port", str(free_port)], root=True)
except subprocess.CalledProcessError:
print("Failed to set adb port")
show_notification("Failed to set adb port to " + str(free_port), "You'll need to start adb manually through Developer Settings", ongoing=False)
return
try:
run(["stop", "adbd"], root=True)
except subprocess.CalledProcessError:
print("Failed to stop adbd, maybe adbd was not running?")
try:
run(["start", "adbd"], root=True)
except subprocess.CalledProcessError:
print("Failed to start adbd")
show_notification("Failed to start adbd", "You'll need to start adb manually through Developer Settings", ongoing=False)
return
return free_port
def connect_adb(ip, port):
run(["adb", "connect", f"{ip}:{port}"])
def main():
print("ws-scrcpy launcher for Termux")
print("Checking for ws-scrcpy...")
if not Path("./ws-scrcpy").exists():
print("ws-scrcpy not found, please install ws-scrcpy.")
return
print("Checking for current adb port...")
show_notification("Checking for current adb port...")
adb_port = None
try:
adb_port = get_port_from_process_name("adbd")
except:
pass
if adb_port is None:
print("Failed to get adb port, starting new adbd...")
adb_port = start_adbd()
if adb_port is None:
print("Failed to start adbd...")
return
device_ip = get_device_private_ip()
wifi_ssid = get_wifi_name()
print("Adb server port:", adb_port)
print("Device IP:", device_ip)
print("Connecting to device through adb...")
show_notification("Connecting to device through adb...", "This may take a while...")
try:
connect_adb(device_ip, adb_port)
except subprocess.CalledProcessError:
print("Failed to connect to device through adb")
show_notification("Failed to connect to device through adb", "You'll need to connect manually in Termux.", ongoing=False)
return
print("Starting ws-scrcpy server...")
show_notification("Starting ws-scrcpy server...", "You may need to wait for 5 minutes for ws-scrcpy to start.")
ws_scrcpy = Popen(["npm", "start"], cwd="./ws-scrcpy")
def print_ws_scrcpy():
for line in ws_scrcpy.stdout:
if line.decode("utf-8").strip() == None:
continue
if "Listening on:" in line.decode("utf-8").strip():
device_ip = get_device_private_ip()
wifi_ssid = get_wifi_name()
print("=========================================")
print(f"ws-scrcpy started on {device_ip}:8000 on {wifi_ssid}")
print("=========================================")
show_toast(f"ws-scrcpy: {device_ip}:8000 on {wifi_ssid}")
show_notification(f"ws-scrcpy: {device_ip}:8000",
f"Wifi: {wifi_ssid}, access {device_ip}:8000 in browser to control the device.",
[2000, 1000, 500], True,
buttons = [
{
"label": "Open in browser",
"action": f"termux-open-url http://{device_ip}:8000"
},
{
"label": "Stop",
"action": f"kill -15 {ws_scrcpy.pid}"
}
])
print("[ws-scrcpy]:", line.decode("utf-8").strip())
ws_scrcpy_thread = threading.Thread(target=print_ws_scrcpy)
ws_scrcpy_thread.daemon = True
ws_scrcpy_thread.start()
print("PLEASE WAIT UNTIL WS-SCRCPY FULLY STARTS (ABOUT 5 MINS), IT TAKES A WHILE TO START THE SERVER.")
try:
while True and ws_scrcpy.poll() is None:
time.sleep(2.5)
curr_ip = get_device_private_ip()
# print("ip:", curr_ip)
curr_ssid = get_wifi_name()
# print("ssid:", curr_ssid)
if curr_ip != device_ip:
print("Device IP changed, reconnecting adb...")
show_notification("Reconnecting adb...", "This may take a while, take a cup of coffee.")
try:
connect_adb(curr_ip, adb_port)
except subprocess.CalledProcessError:
print("Failed to connect to device through adb")
show_notification("Failed to connect to device through adb", "ws-scrcpy will be stopped.")
break
device_ip = curr_ip
print("=========================================")
print(f"ws-scrcpy IP changed to {device_ip}:8000 on {wifi_ssid}")
print("=========================================")
show_toast(f"ws-scrcpy: {device_ip}:8000 on {wifi_ssid}")
show_notification(f"ws-scrcpy: {device_ip}:8000",
f"Wifi: {wifi_ssid}, access {device_ip}:8000 in browser to control the device.",
[2000, 1000, 500], True,
buttons = [
{
"label": "Open in browser",
"action": f"termux-open-url http://{device_ip}:8000"
},
{
"label": "Stop",
"action": f"kill -15 {ws_scrcpy.pid}"
}
])
if curr_ssid != wifi_ssid and curr_ssid not in "<unknown ssid>": # Do not set current ssid to unknown ssid.
print("Wifi ssid changed, changing ssid in notification...")
wifi_ssid = curr_ssid
print("=========================================")
print(f"ws-scrcpy IP changed to {device_ip}:8000 on {wifi_ssid}")
print("=========================================")
show_toast(f"ws-scrcpy: {device_ip}:8000 on {wifi_ssid}")
show_notification(f"ws-scrcpy: {device_ip}:8000",
f"Wifi: {wifi_ssid}, access {device_ip}:8000 in browser to control the device.",
buttons = [
{
"label": "Open in browser",
"action": f"termux-open-url http://{device_ip}:8000"
},
{
"label": "Stop",
"action": f"kill -15 {ws_scrcpy.pid}"
}
])
except:
pass
if ws_scrcpy.poll() == None:
print("Stopping ws-scrcpy server...")
show_notification("Stopping ws-scrcpy server...")
ws_scrcpy.terminate()
try:
# if this returns, the process completed
ws_scrcpy.wait(timeout=15)
except subprocess.TimeoutExpired:
print("ws_scrcpy doesn't exit after 15 seconds, killing process...")
ws_scrcpy.kill()
print("ws-scrcpy has been stopped.")
show_notification("ws-scrcpy has been stopped.", "You may start again by clicking the restart button.", buttons=[
{
"label": "Restart",
"action": f"{sys.executable} {__file__}",
}
], ongoing=False)
if __name__ == '__main__':
main()