mirror of
https://github.com/ApfelTeeSaft/ps4-fortniteserver.git
synced 2026-08-26 19:33:25 +00:00
125 lines
4.2 KiB
Bash
125 lines
4.2 KiB
Bash
if grep -qP '\r' "$0" 2>/dev/null; then
|
||
exec bash <(tr -d '\r' < "$0") "$@"
|
||
fi
|
||
|
||
set -euo pipefail
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
SERVER_DIR="$SCRIPT_DIR/ps4-server"
|
||
TOOLCHAIN_DIR="$SCRIPT_DIR/PS4Toolchain"
|
||
|
||
if [[ -t 1 ]]; then
|
||
G='\033[0;32m' Y='\033[1;33m' C='\033[0;36m' B='\033[1m' N='\033[0m'
|
||
else
|
||
G='' Y='' C='' B='' N=''
|
||
fi
|
||
info() { printf "${C}[INFO]${N} %s\n" "$*"; }
|
||
ok() { printf "${G}[ OK ]${N} %s\n" "$*"; }
|
||
warn() { printf "${Y}[WARN]${N} %s\n" "$*"; }
|
||
die() { printf '\033[0;31m[ERR ]\033[0m %s\n' "$*" >&2; exit 1; }
|
||
hdr() { printf "\n${B}%s${N}\n" "$*"; }
|
||
|
||
is_wsl() { [[ -f /proc/version ]] && grep -qiE "microsoft|wsl" /proc/version; }
|
||
|
||
detect_pm() {
|
||
if command -v apt-get &>/dev/null; then echo "apt"
|
||
elif command -v pacman &>/dev/null; then echo "pacman"
|
||
elif command -v dnf &>/dev/null; then echo "dnf"
|
||
elif command -v yum &>/dev/null; then echo "yum"
|
||
elif command -v brew &>/dev/null; then echo "brew"
|
||
else echo "unknown"
|
||
fi
|
||
}
|
||
|
||
install_deps() {
|
||
local pm="$1"
|
||
local need=()
|
||
|
||
command -v make &>/dev/null || need+=("make")
|
||
command -v clang++ &>/dev/null || need+=("clang")
|
||
if ! command -v ld.lld &>/dev/null && ! command -v lld &>/dev/null; then
|
||
need+=("lld")
|
||
fi
|
||
|
||
if [[ ${#need[@]} -eq 0 ]]; then
|
||
ok "All required tools already installed (make, clang++, ld.lld)."
|
||
return
|
||
fi
|
||
|
||
info "Installing missing tools: ${need[*]}"
|
||
case "$pm" in
|
||
apt)
|
||
sudo apt-get update -qq
|
||
sudo apt-get install -y "${need[@]}"
|
||
;;
|
||
pacman) sudo pacman -Sy --noconfirm "${need[@]}" ;;
|
||
dnf) sudo dnf install -y "${need[@]}" ;;
|
||
yum) sudo yum install -y "${need[@]}" ;;
|
||
brew)
|
||
brew install llvm
|
||
export PATH="/usr/local/opt/llvm/bin:$PATH"
|
||
;;
|
||
*)
|
||
warn "Unknown package manager. Please install manually: ${need[*]}"
|
||
;;
|
||
esac
|
||
ok "Dependencies ready."
|
||
}
|
||
|
||
check_toolchain() {
|
||
if [[ ! -d "$TOOLCHAIN_DIR/include" || ! -d "$TOOLCHAIN_DIR/lib" ]]; then
|
||
die "Bundled toolchain missing at $TOOLCHAIN_DIR – is the repo fully cloned?"
|
||
fi
|
||
ok "Bundled PS4Toolchain found at $TOOLCHAIN_DIR"
|
||
}
|
||
|
||
check_compiler() {
|
||
local cxx; cxx="$(command -v clang++ 2>/dev/null || true)"
|
||
[[ -n "$cxx" ]] || die "clang++ not found after install step."
|
||
|
||
local ver; ver="$("$cxx" --version 2>&1 | head -1)"
|
||
ok "Compiler: $ver"
|
||
|
||
# Warn if Apple clang is being used on macOS (it can't target FreeBSD ELF).
|
||
if [[ "$ver" == *"Apple clang"* ]]; then
|
||
warn "Apple clang detected. You need a pure LLVM build (brew install llvm)."
|
||
warn "Re-run after: export PATH=\"/usr/local/opt/llvm/bin:\$PATH\""
|
||
die "Cannot build PS4 PRX with Apple clang."
|
||
fi
|
||
}
|
||
|
||
|
||
hdr "════════════════════════════════════════════════════════"
|
||
hdr " PS4GS — Setup & Build"
|
||
is_wsl && hdr " (WSL / Ubuntu detected)"
|
||
hdr "════════════════════════════════════════════════════════"
|
||
|
||
PM="$(detect_pm)"
|
||
info "Package manager: $PM"
|
||
|
||
hdr "── Step 1/3: System dependencies"
|
||
install_deps "$PM"
|
||
|
||
hdr "── Step 2/3: Verifying bundled PS4Toolchain"
|
||
check_toolchain
|
||
check_compiler
|
||
|
||
hdr "── Step 3/3: Building PS4GS.prx"
|
||
echo ""
|
||
|
||
[[ -d "$SERVER_DIR" ]] || die "ps4-server/ not found at $SERVER_DIR"
|
||
|
||
cd "$SERVER_DIR"
|
||
make ps4
|
||
|
||
echo ""
|
||
hdr "════════════════════════════════════════════════════════"
|
||
ok "Build complete → ps4-server/PS4GS.prx"
|
||
echo ""
|
||
echo " Deploy to your PS4:"
|
||
echo " scp PS4GS.prx root@<ps4-ip>:/data/homebrew/"
|
||
echo ""
|
||
printf " Load on the console:\n"
|
||
printf " sceKernelLoadStartModule(\"/data/homebrew/PS4GS.prx\", 0, NULL, 0, NULL, NULL);\n"
|
||
hdr "════════════════════════════════════════════════════════"
|