158 lines
5.4 KiB
Bash
158 lines
5.4 KiB
Bash
#!/usr/bin/env bash
|
|
# scripts/install-playwright.sh - SAFE REWRITE
|
|
# Replaces: curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
|
|
#
|
|
# What it does (safe version):
|
|
# 1. Sets up NodeSource repo MANUALLY (no curl|bash pipe)
|
|
# 2. Installs nodejs via apt
|
|
# 3. Installs playwright via npm globally
|
|
# 4. Runs playwright install --with-deps chromium
|
|
set -euo pipefail
|
|
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
CYAN='\033[0;36m'
|
|
BOLD='\033[1m'
|
|
NC='\033[0m'
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
fail_warn() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
exit 0
|
|
}
|
|
|
|
echo "=== RTX⚡3 — Installing Playwright Suite (Safe, no curl|bash) ==="
|
|
echo ""
|
|
|
|
if [ -z "${PREFIX:-}" ]; then
|
|
fail_warn "Not running in Termux (\$PREFIX not set)"
|
|
fi
|
|
|
|
ROOTFS="$PREFIX/var/lib/proot-distro/installed-rootfs/debian"
|
|
if [ ! -d "$ROOTFS" ]; then
|
|
echo -e "${YELLOW}[INFO]${NC} Base Debian container not found. Initializing..."
|
|
bash "$SCRIPT_DIR/install-homebrew.sh" || { echo "Failed to init container"; exit 0; }
|
|
fi
|
|
|
|
# ── The dangerous part: nodesource setup is now replaced ──
|
|
# Instead of: curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
|
|
# We do it manually, step by step
|
|
|
|
echo -e "${BOLD}[1/3] Setting up NodeSource repo (manual, no curl|bash)${NC}"
|
|
echo "----------------------------------------"
|
|
|
|
export PROOT_NO_SECCOMP=1
|
|
proot-distro login debian --shared-tmp --bind "$PREFIX:/termux" --user root -- bash -c '
|
|
set -euo pipefail
|
|
|
|
ARCH=$(dpkg --print-architecture)
|
|
echo "[INFO] Architecture: $ARCH"
|
|
|
|
# Install prerequisites
|
|
apt-get update -qq
|
|
apt-get install -y apt-transport-https ca-certificates curl gnupg
|
|
|
|
# Download and import GPG key (no pipe to bash!)
|
|
GPG_KEY_FILE="/tmp/nodesource.gpg.key"
|
|
curl -fsSL "https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key" -o "$GPG_KEY_FILE"
|
|
gpg --dearmor -o "/usr/share/keyrings/nodesource.gpg" "$GPG_KEY_FILE"
|
|
chmod 644 /usr/share/keyrings/nodesource.gpg
|
|
rm -f "$GPG_KEY_FILE"
|
|
echo "[OK] GPG key imported"
|
|
|
|
# Create apt sources file (not curl|bash, just cat redirection)
|
|
cat > /etc/apt/sources.list.d/nodesource.sources << 'NODESOURCES'
|
|
Types: deb
|
|
URIs: https://deb.nodesource.com/node_22.x
|
|
Suites: nodistro
|
|
Architectures: ARCH_PLACEHOLDER
|
|
Signed-By: /usr/share/keyrings/nodesource.gpg
|
|
NODESOURCES
|
|
sed -i "s/ARCH_PLACEHOLDER/$ARCH/" /etc/apt/sources.list.d/nodesource.sources
|
|
echo "[OK] apt sources created"
|
|
cat /etc/apt/sources.list.d/nodesource.sources
|
|
|
|
# apt update and install nodejs
|
|
apt-get update -qq
|
|
apt-get install -y nodejs
|
|
|
|
NODE_VER=$(node --version 2>/dev/null)
|
|
NPM_VER=$(npm --version 2>/dev/null)
|
|
echo "[OK] Node.js $NODE_VER / npm $NPM_VER installed"
|
|
'
|
|
|
|
echo ""
|
|
echo -e "${BOLD}[2/3] Installing Playwright + browsers inside Debian${NC}"
|
|
echo "----------------------------------------"
|
|
|
|
# Install playwright and browsers
|
|
proot-distro login debian --shared-tmp --bind "$PREFIX:/termux" --user root -- bash -c '
|
|
set -euo pipefail
|
|
|
|
# Install system dependencies for Playwright Chromium
|
|
apt-get install -yq libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
|
|
libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \
|
|
libxfixes3 libxrandr2 libgbm1 libasound2 xvfb 2>/dev/null || true
|
|
|
|
# Install playwright via npm (no curl|bash involved)
|
|
npm install -g playwright 2>&1 | tail -3
|
|
|
|
# Install Chromium browser with dependencies
|
|
npx playwright install --with-deps chromium 2>&1 | tail -5
|
|
'
|
|
|
|
echo ""
|
|
echo -e "${BOLD}[3/3] Creating Dual-Engine Playwright wrapper${NC}"
|
|
echo "----------------------------------------"
|
|
|
|
WRAPPER="$PREFIX/bin/playwright-node"
|
|
cat > "$WRAPPER" << 'EOF'
|
|
#!/usr/bin/env bash
|
|
ROOTFS="$PREFIX/var/lib/proot-distro/installed-rootfs/debian"
|
|
IS_ROOTED=false
|
|
if command -v su >/dev/null 2>&1 && su -c true >/dev/null 2>&1; then
|
|
IS_ROOTED=true
|
|
fi
|
|
|
|
args_escaped=()
|
|
for arg in "$@"; do
|
|
args_escaped+=("$(printf '%q' "$arg")")
|
|
done
|
|
|
|
SCRIPT_CMD="xvfb-run -a node ${args_escaped[*]}"
|
|
|
|
if [ "$IS_ROOTED" = true ]; then
|
|
su -c "
|
|
if ! mountpoint -q \"$ROOTFS/proc\"; then mount -t proc proc \"$ROOTFS/proc\"; fi
|
|
if ! mountpoint -q \"$ROOTFS/sys\"; then mount -t sysfs sysfs \"$ROOTFS/sys\"; fi
|
|
if ! mountpoint -q \"$ROOTFS/dev\"; then mount --bind /dev \"$ROOTFS/dev\"; fi
|
|
if ! mountpoint -q \"$ROOTFS/data/data/com.termux\"; then
|
|
mkdir -p \"$ROOTFS/data/data/com.termux\"
|
|
mount --bind /data/data/com.termux \"$ROOTFS/data/data/com.termux\"
|
|
fi
|
|
[ -d /sdcard ] && ! mountpoint -q \"$ROOTFS/sdcard\" && { mkdir -p \"$ROOTFS/sdcard\"; mount --bind /sdcard \"$ROOTFS/sdcard\"; } 2>/dev/null
|
|
mkdir -p \"$ROOTFS/tmp\"; chmod 1777 \"$ROOTFS/tmp\"
|
|
" >/dev/null 2>&1
|
|
su -c "chroot \"$ROOTFS\" /bin/su - debian -c \"export HOME=$HOME; export PATH=/usr/local/bin:/usr/bin:/bin; cd \\\"$(pwd)\\\"; $SCRIPT_CMD\""
|
|
else
|
|
export PROOT_NO_SECCOMP=1
|
|
SDCARD_BIND=""
|
|
[ -d /sdcard ] && SDCARD_BIND="--bind /sdcard:/sdcard"
|
|
proot-distro login debian --shared-tmp \
|
|
--bind "$PREFIX:/termux" \
|
|
--bind "$HOME:$HOME" \
|
|
$SDCARD_BIND \
|
|
--bind "$(pwd)":"$(pwd)" \
|
|
--user debian -- bash -c "export HOME=$HOME; cd \"$(pwd)\"; $SCRIPT_CMD"
|
|
fi
|
|
EOF
|
|
chmod +x "$WRAPPER"
|
|
|
|
echo -e "${GREEN}[OK]${NC} Playwright wrapper created at $WRAPPER"
|
|
echo ""
|
|
echo -e "${GREEN}Playwright installation complete.${NC}"
|
|
echo " Run: playwright-node my-scraper.js"
|
|
echo ""
|
|
echo -e "${YELLOW}[NOTE]${NC} Chromium uses ~300-500MB RAM. Devices with <4GB RAM may struggle."
|