HEX
Server: nginx/1.28.0
System: Linux w3c-2 6.8.0-78-generic #78-Ubuntu SMP PREEMPT_DYNAMIC Tue Aug 12 11:34:18 UTC 2025 x86_64
User: e_learni1 (1076)
PHP: 8.3.29
Disabled: NONE
Upload Files
File: //usr/bin/install-wp-cli-login.sh
#!/bin/bash
set -euo pipefail

DEST_DIR="/opt/wp-cli/wp-cli-login-command"
URL="https://github.com/aaemnnosttv/wp-cli-login-command/archive/refs/tags/v1.5.0.tar.gz"

# Idempotency: already installed
if [[ -d "$DEST_DIR" ]]; then
  echo "wp-cli-login-command already installed at $DEST_DIR"
  exit 0
fi

# Ensure parent directory exists
install -d -m 0755 "$(dirname "$DEST_DIR")"

# Temporary workspace
TMP="$(mktemp -d)"
cleanup() {
  rm -rf "$TMP"
}
trap cleanup EXIT

TARBALL="$TMP/pkg.tgz"
STAGING="$TMP/staging"

echo "Downloading wp-cli-login-command v1.5.0…"
wget -q \
  --timeout=100 \
  --dns-timeout=5 \
  --connect-timeout=5 \
  --tries=2 \
  --https-only \
  -O "$TARBALL" \
  "$URL"

# Basic sanity check
if [[ ! -s "$TARBALL" ]]; then
  echo "Download failed or empty archive" >&2
  exit 1
fi

mkdir -p "$STAGING"

echo "Extracting…"
tar -xzf "$TARBALL" \
  -C "$STAGING" \
  --strip-components=1

# Sanity check: expected package structure
if [[ ! -f "$STAGING/composer.json" ]]; then
  echo "Archive does not look like a WP-CLI package (composer.json missing)" >&2
  exit 1
fi

echo "Installing Composer dependencies…"
(
  cd "$STAGING"
  COMPOSER_HTTP_TIMEOUT=60 COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader
)


# Atomic install
mv "$STAGING" "$DEST_DIR"

echo "Installed to $DEST_DIR"
exit 0