#!/bin/bash

# Usage check
if [ "$#" -ne 4 ]; then
    echo "Usage: $0 <user@realm> <vds_group> <start_id> <end_id>"
    echo "Example: $0 myuser@pve vdsuser 100 110"
    exit 1
fi

USER=$1         # e.g. myuser@pve
GROUP=$2        # e.g. vdsuser
START_ID=$3     # e.g. 100
END_ID=$4       # e.g. 110

for ((i=START_ID; i<=END_ID; i++)); do
    echo "Assigning group '$GROUP' to user '$USER' on VM/PCT ID $i..."
    # Apply permission at the VM or CT level
    # /vms/ for both VMs and containers (PVE abstracts it)
    pveum aclmod /vms/$i --user $USER --role $GROUP
done

echo "Permission assignment complete from $START_ID to $END_ID."
