#!/bin/bash

# VPN Installation Script - Enhanced Version
set -e  # Exit immediately on error

echo "=== VPN Client Installation Script ==="

# Check if curl is installed
if ! command -v curl &> /dev/null; then
    echo "Error: curl is not installed. Please install curl first."
    exit 1
fi

# Define file list
files=(
    "vpn.sh"
    "OpenVPN-Client.conf" 
    "setup-vpn-service.sh"
)

base_url="https://download.lizhiyun.top/"

# Download files
echo "Starting to download necessary files..."
for file in "${files[@]}"; do
    echo "Downloading: $file"
    if curl -k -o "$file" "$base_url/$file"; then
        echo "✓ $file downloaded successfully"
    else
        echo "✗ $file download failed"
        exit 1
    fi
done

# Add execute permissions
chmod +x vpn.sh setup-vpn-service.sh

# Execute installation scripts
echo "Starting installation..."
sh vpn.sh
sh setup-vpn-service.sh

echo "=== VPN Installation Completed ==="