AnonSec Team
Server IP : 62.171.151.215  /  Your IP : 216.73.217.19
Web Server : nginx/1.18.0
System : Linux vmi3128365 5.15.0-176-generic #186-Ubuntu SMP Fri Mar 13 11:01:42 UTC 2026 x86_64
User : alex ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF
Directory (0755) :  /var/www/workoutfacile.com/../jesuisfauche.com/wp-admin/../../

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /var/www/workoutfacile.com/../jesuisfauche.com/wp-admin/../../wp-plugin-install.sh
#!/usr/bin/env bash
set -euo pipefail

usage() {
  cat <<'EOF'
Usage:
  wp-plugin-install.sh --site /var/www/your-site wporg <plugin-slug> [--no-activate]
  wp-plugin-install.sh --site /var/www/your-site git <git-url> [--no-activate]
  wp-plugin-install.sh --site /var/www/your-site zip <zip-url> [--no-activate]
  wp-plugin-install.sh --site /var/www/your-site local <zip-path> [--no-activate]

Examples:
  wp-plugin-install.sh --site /var/www/anti-tabac.com wporg updraftplus
  wp-plugin-install.sh --site /var/www/anti-tabac.com git git@github.com:alexdepfile/universal-form-500.git
  ZIP_USER=plugins ZIP_PASSWORD='secret' wp-plugin-install.sh --site /var/www/anti-tabac.com zip https://www.learnfrenchiseasy.com/private-plugin-zips/universal-form-500.zip
  wp-plugin-install.sh --site /var/www/anti-tabac.com local /var/www/learnfrenchiseasy.com/private-plugin-zips/universal-form-500.zip
EOF
}

SITE_PATH=""
ACTIVATE="1"

while [[ $# -gt 0 ]]; do
  case "$1" in
    --site)
      SITE_PATH="${2:-}"
      shift 2
      ;;
    --no-activate)
      ACTIVATE="0"
      shift
      ;;
    -h|--help)
      usage
      exit 0
      ;;
    *)
      break
      ;;
  esac
done

MODE="${1:-}"
TARGET="${2:-}"

if [[ -z "$SITE_PATH" || -z "$MODE" || -z "$TARGET" ]]; then
  usage
  exit 1
fi

if [[ ! -f "$SITE_PATH/wp-load.php" ]]; then
  echo "WordPress not found in: $SITE_PATH" >&2
  exit 1
fi

PLUGINS_DIR="$SITE_PATH/wp-content/plugins"
mkdir -p "$PLUGINS_DIR"

TMP_DIR="$(mktemp -d)"
cleanup() {
  rm -rf "$TMP_DIR"
}
trap cleanup EXIT

fix_permissions() {
  local path="$1"
  if [[ -e "$path" ]]; then
    chmod -R u+rwX "$path" || true
    if sudo -n true 2>/dev/null; then
      sudo -n chgrp -R www-data "$path" || true
      sudo -n chmod -R g+rwX "$path" || true
    fi
  fi
}

extract_zip_to_plugin_dir() {
  local zip_file="$1"
  local fallback_name="$2"
  local extract_dir="$TMP_DIR/extract-$fallback_name"
  mkdir -p "$extract_dir"
  if [[ ! -f "$zip_file" ]]; then
    echo "ZIP file missing: $zip_file" >&2
    return 1
  fi
  if ! unzip -q "$zip_file" -d "$extract_dir"; then
    echo "Unable to unzip: $zip_file" >&2
    return 1
  fi

  local candidate_dir
  candidate_dir="$(find "$extract_dir" -mindepth 1 -maxdepth 1 -type d | head -n 1)"

  if [[ -n "$candidate_dir" ]] && [[ "$(find "$extract_dir" -mindepth 1 -maxdepth 1 | wc -l)" -eq 1 ]]; then
    :
  else
    candidate_dir="$extract_dir/$fallback_name"
    mkdir -p "$candidate_dir"
    find "$extract_dir" -mindepth 1 -maxdepth 1 ! -name "$fallback_name" -exec mv {} "$candidate_dir"/ \;
  fi

  local plugin_dir="$PLUGINS_DIR/$(basename "$candidate_dir")"
  rm -rf "$plugin_dir"
  cp -a "$candidate_dir" "$plugin_dir"
  fix_permissions "$plugin_dir"
  echo "$plugin_dir"
}

find_plugin_file() {
  local plugin_dir="$1"
  find "$plugin_dir" -maxdepth 2 -type f -name '*.php' -print \
    | while IFS= read -r file; do
        if grep -q "Plugin Name:" "$file"; then
          echo "$file"
        fi
      done \
    | awk '{ print length($0) "|" $0 }' \
    | sort -n \
    | head -n 1 \
    | cut -d'|' -f2-
}

activate_plugin_file() {
  local plugin_file="$1"
  local rel_plugin_file
  rel_plugin_file="${plugin_file#"$PLUGINS_DIR/"}"

  php <<PHP
<?php
require '$SITE_PATH/wp-load.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
\$plugin = '$rel_plugin_file';
\$result = activate_plugin(\$plugin, '', false, true);
if (is_wp_error(\$result)) {
    fwrite(STDERR, \$result->get_error_message() . PHP_EOL);
    exit(1);
}
echo "Activated: \$plugin" . PHP_EOL;
PHP
}

install_wporg() {
  local slug="$1"
  local zip_file="$TMP_DIR/${slug}.zip"

  if ! curl -fL "https://downloads.wordpress.org/plugin/${slug}.latest-stable.zip" -o "$zip_file"; then
    echo "Unable to download WordPress.org plugin: $slug" >&2
    return 1
  fi
  extract_zip_to_plugin_dir "$zip_file" "$slug"
}

install_git_repo() {
  local repo_url="$1"
  local repo_name
  repo_name="$(basename "$repo_url" .git)"
  local plugin_dir="$PLUGINS_DIR/$repo_name"

  if [[ -d "$plugin_dir/.git" ]]; then
    if ! git -C "$plugin_dir" pull --ff-only; then
      echo "Unable to update git plugin: $repo_url" >&2
      return 1
    fi
  else
    rm -rf "$plugin_dir"
    if ! git clone "$repo_url" "$plugin_dir"; then
      echo "Unable to clone git plugin: $repo_url" >&2
      return 1
    fi
  fi

  fix_permissions "$plugin_dir"
  echo "$plugin_dir"
}

install_zip_url() {
  local zip_url="$1"
  local zip_name
  zip_name="$(basename "${zip_url%%\?*}")"
  local fallback_name="${zip_name%.zip}"
  local zip_file="$TMP_DIR/${zip_name:-plugin.zip}"
  local curl_args=(-fL)

  if [[ -n "${ZIP_USER:-}" || -n "${ZIP_PASSWORD:-}" ]]; then
    curl_args+=(-u "${ZIP_USER:-}:${ZIP_PASSWORD:-}")
  fi

  if ! curl "${curl_args[@]}" "$zip_url" -o "$zip_file"; then
    echo "Unable to download ZIP URL: $zip_url" >&2
    return 1
  fi
  extract_zip_to_plugin_dir "$zip_file" "${fallback_name:-plugin}"
}

install_local_zip() {
  local zip_path="$1"
  if [[ ! -f "$zip_path" ]]; then
    echo "ZIP file not found: $zip_path" >&2
    exit 1
  fi

  local zip_name
  zip_name="$(basename "$zip_path")"
  local fallback_name="${zip_name%.zip}"
  extract_zip_to_plugin_dir "$zip_path" "${fallback_name:-plugin}"
}

case "$MODE" in
  wporg)
    if ! INSTALLED_DIR="$(install_wporg "$TARGET")"; then
      exit 1
    fi
    ;;
  git)
    if ! INSTALLED_DIR="$(install_git_repo "$TARGET")"; then
      exit 1
    fi
    ;;
  zip)
    if ! INSTALLED_DIR="$(install_zip_url "$TARGET")"; then
      exit 1
    fi
    ;;
  local)
    if ! INSTALLED_DIR="$(install_local_zip "$TARGET")"; then
      exit 1
    fi
    ;;
  *)
    echo "Unknown mode: $MODE" >&2
    usage
    exit 1
    ;;
esac

PLUGIN_FILE="$(find_plugin_file "$INSTALLED_DIR")"
if [[ -z "$PLUGIN_FILE" ]]; then
  echo "Installed, but no plugin entry file was found in: $INSTALLED_DIR" >&2
  exit 1
fi

echo "Installed in: $INSTALLED_DIR"
echo "Main plugin file: $PLUGIN_FILE"

if [[ "$ACTIVATE" == "1" ]]; then
  activate_plugin_file "$PLUGIN_FILE"
fi

AnonSec - 2021