#!/usr/bin/env bash # # PHP/Laravel Security Linter - Installation Script # # This script builds the Docker image and installs the wrapper script. # # Usage: # ./install.sh # Default: 1024M memory # PHP_MEMORY_LIMIT=2048M ./install.sh # Custom memory limit # set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" IMAGE_NAME="php-security-linter:latest" INSTALL_PATH="/usr/local/bin/php-security-lint" PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:-1024M}" echo -e "${BLUE}" echo "╔════════════════════════════════════════════════════════════╗" echo "║ PHP/Laravel Security Linter - Installer ║" echo "╚════════════════════════════════════════════════════════════╝" echo -e "${NC}" # Check Docker echo -e "${YELLOW}[1/3] Checking Docker...${NC}" if ! command -v docker &> /dev/null; then echo -e "${RED}Error: Docker is not installed.${NC}" echo "Please install Docker first: https://docs.docker.com/get-docker/" exit 1 fi if ! docker info &> /dev/null; then echo -e "${RED}Error: Docker daemon is not running.${NC}" echo "Please start Docker and try again." exit 1 fi echo -e "${GREEN}✓ Docker is available${NC}" # Build Docker image echo "" echo -e "${YELLOW}[2/3] Building Docker image (memory_limit=${PHP_MEMORY_LIMIT})...${NC}" cd "$SCRIPT_DIR" docker build --build-arg PHP_MEMORY_LIMIT="$PHP_MEMORY_LIMIT" -t "$IMAGE_NAME" . echo -e "${GREEN}✓ Docker image built: $IMAGE_NAME${NC}" # Install wrapper script echo "" echo -e "${YELLOW}[3/3] Installing wrapper script...${NC}" if [[ -w "$(dirname "$INSTALL_PATH")" ]]; then cp "$SCRIPT_DIR/php-security-lint" "$INSTALL_PATH" chmod +x "$INSTALL_PATH" echo -e "${GREEN}✓ Installed to $INSTALL_PATH${NC}" else echo -e "${YELLOW}Need sudo to install to $INSTALL_PATH${NC}" sudo cp "$SCRIPT_DIR/php-security-lint" "$INSTALL_PATH" sudo chmod +x "$INSTALL_PATH" echo -e "${GREEN}✓ Installed to $INSTALL_PATH${NC}" fi # Done echo "" echo -e "${GREEN}════════════════════════════════════════════════════════════${NC}" echo -e "${GREEN}Installation complete!${NC}" echo "" echo "Usage:" echo " php-security-lint . # Scan current directory" echo " php-security-lint app/ # Scan specific directory" echo " php-security-lint -s high . # High severity only" echo " php-security-lint -f json -o report.json ." echo "" echo "For more options:" echo " php-security-lint --help" echo -e "${GREEN}════════════════════════════════════════════════════════════${NC}"