#!/bin/bash

set -euo pipefail

if [ $# -ne 2 ]; then
  echo "Usage: $0 <local_file> <remote_absolute_path>"
  exit 1
fi

LOCAL_FILE="$1"
REMOTE_PATH="$2"

if [ ! -f "$LOCAL_FILE" ]; then
  echo "Error: Local file '$LOCAL_FILE' not found."
  exit 1
fi

if [ ! -f "$hosts_file" ]; then
  echo "Error: Hosts file '$hosts_file' not found."
  exit 1
fi

# Push the file content using tee with doas
echo "Pushing $LOCAL_FILE to $REMOTE_PATH on all hosts in $hosts_file"
pssh -h "$hosts_file" -l "$USER" -i "doas tee \"$REMOTE_PATH\" > /dev/null" < "$LOCAL_FILE"

