#!/bin/bash
# Script to run commands on R630-01 using sshpass
# Usage: ./run-remote-commands.sh [password]

set -e

PROXMOX_HOST="192.168.11.11"
PROXMOX_USER="root"

if [ -z "$1" ]; then
    echo "Usage: $0 <password>"
    echo "Or set PROXMOX_PASSWORD environment variable"
    exit 1
fi

PASSWORD="$1"

# Check if sshpass is installed
if ! command -v sshpass &> /dev/null; then
    echo "sshpass not found. Installing..."
    sudo apt-get update && sudo apt-get install -y sshpass
fi

echo "Running commands on $PROXMOX_USER@$PROXMOX_HOST..."
echo ""

# Run pvesm status
echo "=== Proxmox Storage Status ==="
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no "$PROXMOX_USER@$PROXMOX_HOST" "pvesm status"
echo ""

# Run lsblk
echo "=== Block Devices ==="
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no "$PROXMOX_USER@$PROXMOX_HOST" "lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE,MODEL"
echo ""

# Check 250GB drives
echo "=== 250GB Drives Status ==="
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no "$PROXMOX_USER@$PROXMOX_HOST" "
for drive in sdc sdd sde sdf sdg sdh; do
    if [ -b \"/dev/\$drive\" ]; then
        echo \"\"
        echo \"/dev/\$drive:\"
        lsblk /dev/\$drive
    fi
done
"

