Files
OpenFlux/deploy/phpbox/build-bundle.sh
p1neappleXpress d3d67eff8b Mode without a server: a free PHP exit on any hosting (stream mux, flow control, installer, full tunnel) (#137)
The exit is a small PHP program on an ordinary web hosting, reached through cups.online or Mail.ru. See the PR for the list.
2026-10-01 01:49:46 +03:00

37 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Assembles the upload set for a PHP host straight from the sources here (no
# embedded copies to drift): exits, lib/, the page, the core's link parser
# (WebAssembly) and a config.php holding the token.
#
# deploy/phpbox/build-bundle.sh [OUT_DIR] # default: <repo>/phpbox_bundle
# PHPBOX_TOKEN=... deploy/phpbox/build-bundle.sh # reuse a token; else the bundle's own, else a new one
# NO_WASM=1 ... # skip the parser build (links need it; addresses do not)
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
repo=$(cd "$here/../.." && pwd)
out=${1:-$repo/phpbox_bundle}
token=${PHPBOX_TOKEN:-}
if [ -z "$token" ] && [ -f "$out/config.php" ]; then
token=$(sed -n "s/.*'PHPBOX_TOKEN' => '\([^']*\)'.*/\1/p" "$out/config.php" | head -n1)
fi
[ -n "$token" ] || token=$(openssl rand -hex 12)
if [ -z "${NO_WASM:-}" ]; then "$here/build-wasm.sh" >/dev/null; fi
rm -rf "$out"; mkdir -p "$out/lib" "$out/assets"
cp "$here"/cupsexit.php "$here"/mailruexit.php "$here"/phpbox.php "$out/"
cp "$here"/lib/*.php "$here"/lib/page.html "$out/lib/"
printf 'Require all denied\n' > "$out/lib/.htaccess"
[ -f "$here/assets/share.wasm.gz" ] && cp "$here"/assets/share.wasm.gz "$here"/assets/wasm_exec.js "$out/assets/"
cat > "$out/config.php" <<PHP
<?php
// generated by build-bundle.sh - holds the token; putenv() is disabled on some free hosts, so define() it
if (!defined('PHPBOX_CONFIG_LOADED')) {
define('PHPBOX_CONFIG_LOADED', 1);
if (!defined('PHPBOX_TOKEN')) define('PHPBOX_TOKEN', '$token');
}
PHP
find "$out" -name '*.php' -exec php -l {} \; | grep -v '^No syntax errors' || true
echo "bundle: $out"; (cd "$out" && find . -type f | sort | sed 's/^/ /')