39 lines
1.4 KiB
Bash
39 lines
1.4 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
## install-lscache-wp.sh — auto-install the official litespeed-cache plugin
|
||
|
|
## on first boot if WP is detected and plugin not already managed.
|
||
|
|
## Idempotent: re-runs are no-ops. Honors LSCACHE_AUTOINSTALL=0 escape hatch.
|
||
|
|
##
|
||
|
|
## Args: $1 = $user (customer system user)
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
user="${1:?usage: install-lscache-wp.sh <user>}"
|
||
|
|
home="/home/${user}"
|
||
|
|
|
||
|
|
if [ "${LSCACHE_AUTOINSTALL:-1}" = "0" ]; then
|
||
|
|
echo "[lscache] LSCACHE_AUTOINSTALL=0 — skipping plugin install."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ ! -f "$home/public_html/wp-config.php" ]; then
|
||
|
|
echo "[lscache] No wp-config.php in $home/public_html — skipping (not a WP site)."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
## With setUIDMode 2, lsphp runs as the customer, and customer owns their
|
||
|
|
## home tree — wp-cli also runs as the customer, files end up correctly owned.
|
||
|
|
if ! command -v wp >/dev/null 2>&1; then
|
||
|
|
echo "[lscache] wp-cli not on PATH — skipping (image build issue, not fatal)."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
if sudo -u "$user" -- wp --path="$home/public_html" plugin is-installed litespeed-cache 2>/dev/null; then
|
||
|
|
echo "[lscache] litespeed-cache already installed — leaving customer's settings alone."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[lscache] Installing litespeed-cache plugin for $user…"
|
||
|
|
sudo -u "$user" -- wp --path="$home/public_html" plugin install litespeed-cache --activate \
|
||
|
|
|| { echo "[lscache] plugin install failed (network? wp-cli? perms?) — non-fatal."; exit 0; }
|
||
|
|
|
||
|
|
echo "[lscache] Done."
|