| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /proc/2798582/cwd/scripts/setup/ |
Upload File : |
#!/usr/bin/env bash
#
# Install OpenAPI Generator CLI on the production server.
#
# The admin SDK generator (app/Console/Commands/GenerateApiSdk.php) shells out
# to `npx @openapitools/openapi-generator-cli`. That CLI is a Node wrapper
# around a Java JAR, so the server needs:
# 1. Node.js + npm (already required for deploy build artifacts)
# 2. A JRE (the wrapper downloads and invokes a generator JAR)
# 3. The CLI installed globally so `npx` resolves it without a local
# node_modules (the deploy archive does not ship node_modules).
#
# Idempotent: safe to re-run. Pass `--force` to reinstall the CLI even if a
# version is already detected.
#
# Usage (on the server):
# sudo bash scripts/setup/install-openapi-generator.sh
# sudo bash scripts/setup/install-openapi-generator.sh --force
#
# Or remotely from a workstation:
# ssh ubuntu@<host> 'sudo bash -s' < scripts/setup/install-openapi-generator.sh
set -euo pipefail
FORCE=0
for arg in "$@"; do
case "$arg" in
--force) FORCE=1 ;;
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
esac
done
log() { printf '[install-openapi-generator] %s\n' "$*"; }
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
log "ERROR: required command '$1' not found in PATH"
return 1
fi
}
ensure_java() {
if command -v java >/dev/null 2>&1; then
log "Java detected: $(java -version 2>&1 | head -n1)"
return 0
fi
log "Java not found. Installing default-jre-headless..."
if ! command -v apt-get >/dev/null 2>&1; then
log "ERROR: apt-get not available; install a JRE manually (openjdk-17-jre-headless or similar)"
return 1
fi
apt-get update -y
apt-get install -y --no-install-recommends default-jre-headless
log "Java installed: $(java -version 2>&1 | head -n1)"
}
ensure_node() {
require_cmd node
require_cmd npm
log "Node detected: $(node --version), npm: $(npm --version)"
}
ensure_www_data_npm_cache() {
# Laravel invokes `npx ...` from PHP at runtime as the Apache user
# (www-data on this server). www-data's HOME is /var/www, which is
# not writable by www-data, so npm/npx fail with EACCES trying to
# create the cache at /var/www/.npm. Pre-create it with the right
# ownership so the runtime call succeeds.
if ! id -u www-data >/dev/null 2>&1; then
log "www-data user not present; skipping npm cache pre-create"
return 0
fi
local home_dir
home_dir="$(getent passwd www-data | cut -d: -f6)"
if [[ -z "$home_dir" ]]; then
home_dir="/var/www"
fi
local cache_dir="${home_dir}/.npm"
if [[ -d "$cache_dir" ]]; then
log "npm cache dir already exists: ${cache_dir}"
else
install -d -o www-data -g www-data -m 0775 "$cache_dir"
log "Created npm cache dir for www-data: ${cache_dir}"
fi
# Sanity-check that www-data can actually use the CLI through npx.
if sudo -u www-data -H bash -c "cd / && npx --no-install @openapitools/openapi-generator-cli version >/dev/null 2>&1"; then
log "www-data can resolve openapi-generator-cli via npx"
else
log "WARNING: www-data still cannot resolve the CLI via npx — check PATH for the Apache process"
fi
}
install_cli() {
local installed_version=""
if command -v openapi-generator-cli >/dev/null 2>&1; then
installed_version="$(openapi-generator-cli version 2>/dev/null | head -n1 || true)"
fi
if [[ -n "$installed_version" && "$FORCE" -eq 0 ]]; then
log "openapi-generator-cli already installed (${installed_version}); skipping (use --force to reinstall)"
return 0
fi
log "Installing @openapitools/openapi-generator-cli globally via npm..."
npm install -g @openapitools/openapi-generator-cli
log "Installed: $(openapi-generator-cli version 2>&1 | head -n1)"
}
verify() {
log "Verifying npx wrapper used by the Laravel command..."
if npx --no-install @openapitools/openapi-generator-cli version >/dev/null 2>&1; then
log "npx wrapper resolves the CLI successfully"
else
log "WARNING: npx could not resolve the CLI without install — confirm global npm prefix is on PATH"
log " global prefix: $(npm config get prefix)"
log " add \$(npm config get prefix)/bin to PATH for the web server user if needed"
fi
}
main() {
if [[ "$(id -u)" -ne 0 ]]; then
log "ERROR: run as root (sudo) so npm -g and apt-get can install system-wide"
exit 1
fi
ensure_node
ensure_java
install_cli
ensure_www_data_npm_cache
verify
log "Done. The admin SDK generator should now succeed against languages other than --spec-only."
}
main "$@"