#!/bin/bash set -e echo "jrunner Development Environment Setup" echo "=====================================" echo "" # Color codes for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check if running on Linux if [[ "$OSTYPE" != "linux-gnu"* ]]; then echo -e "${YELLOW}Warning: This script is designed for Linux. You may need to manually install dependencies.${NC}" echo "" fi # Function to check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Function to get Java version get_java_version() { if command_exists java; then java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}' | awk -F '.' '{print $1}' else echo "0" fi } echo "Checking dependencies..." echo "" # Check Java JAVA_VERSION=$(get_java_version) if [ "$JAVA_VERSION" -ge 11 ]; then echo -e "${GREEN}✓${NC} Java $JAVA_VERSION detected" java -version 2>&1 | head -n 1 JAVA_OK=true else echo -e "${RED}✗${NC} Java 11+ not found" JAVA_OK=false fi # Check Git if command_exists git; then echo -e "${GREEN}✓${NC} Git detected" DEPENDENCIES_OK=true else echo -e "${RED}✗${NC} Git not found" DEPENDENCIES_OK=false fi # Check if gradlew exists if [ -f "./gradlew" ]; then echo -e "${GREEN}✓${NC} Gradle wrapper found (no need to install Gradle)" GRADLE_OK=true else echo -e "${YELLOW}!${NC} Gradle wrapper not found in current directory" GRADLE_OK=false fi echo "" # If Java is missing, offer installation help if [ "$JAVA_OK" = false ]; then echo -e "${YELLOW}Java 11+ is required to build and run jrunner${NC}" echo "" echo "Installation options:" echo "" echo "1. Install OpenJDK via package manager (recommended):" echo " Ubuntu/Debian: sudo apt update && sudo apt install openjdk-17-jdk" echo " Fedora/RHEL: sudo dnf install java-17-openjdk-devel" echo " Arch: sudo pacman -S jdk-openjdk" echo "" echo "2. Download Oracle JDK manually:" echo " Visit: https://www.oracle.com/java/technologies/downloads/" echo " Download JDK 17+ tarball and extract to /opt" echo " Add to PATH: export JAVA_HOME=/opt/jdk-17 && export PATH=\$PATH:\$JAVA_HOME/bin" echo "" read -p "Would you like to install OpenJDK via package manager? (requires sudo) [y/N]: " install_java if [[ "$install_java" =~ ^[Yy]$ ]]; then if command_exists apt; then echo "Installing OpenJDK 17 via apt..." sudo apt update sudo apt install -y openjdk-17-jdk elif command_exists dnf; then echo "Installing OpenJDK 17 via dnf..." sudo dnf install -y java-17-openjdk-devel elif command_exists pacman; then echo "Installing OpenJDK via pacman..." sudo pacman -S --noconfirm jdk-openjdk else echo -e "${RED}Could not detect package manager. Please install Java manually.${NC}" exit 1 fi # Verify installation JAVA_VERSION=$(get_java_version) if [ "$JAVA_VERSION" -ge 11 ]; then echo -e "${GREEN}✓ Java installed successfully${NC}" JAVA_OK=true else echo -e "${RED}✗ Java installation failed${NC}" exit 1 fi else echo "" echo "Please install Java manually and re-run this script." exit 1 fi fi # Check for unzip (needed for deployment) if ! command_exists unzip; then echo -e "${YELLOW}Note: 'unzip' is recommended for deployment${NC}" read -p "Install unzip? [y/N]: " install_unzip if [[ "$install_unzip" =~ ^[Yy]$ ]]; then if command_exists apt; then sudo apt install -y unzip elif command_exists dnf; then sudo dnf install -y unzip elif command_exists pacman; then sudo pacman -S --noconfirm unzip fi fi fi echo "" echo -e "${GREEN}All required dependencies are installed!${NC}" echo "" # Verify we're in the right directory if [ ! -f "./gradlew" ]; then echo -e "${RED}Error: gradlew not found. Are you in the jrunner project directory?${NC}" exit 1 fi # Make gradlew executable chmod +x ./gradlew echo "Testing build system..." if ./gradlew --version > /dev/null 2>&1; then echo -e "${GREEN}✓${NC} Gradle wrapper working" else echo -e "${RED}✗${NC} Gradle wrapper failed" exit 1 fi echo "" echo "Running test build..." if ./gradlew build; then echo "" echo -e "${GREEN}✓ Build successful!${NC}" echo "" echo "Next steps:" echo " 1. Install locally for testing:" echo " ./gradlew installDist" echo " ./jrunner/build/install/jrunner/bin/jrunner --help" echo "" echo " 2. Or run the interactive deploy script:" echo " ./deploy.sh" echo "" echo " 3. See readme.md for usage examples" else echo -e "${RED}✗ Build failed${NC}" echo "Check the error messages above and try again." exit 1 fi