#!/bin/bash

readonly source_path="$1"
[ -n "$source_path" ] || { echo "please specify a source path."; exit 1; }
readonly target_path="$2"
[ -n "$target_path" ] || { echo "please specify a target path."; exit 1; }

guest_port=$(vagrant ssh-config | grep 'Port ' | awk '{ print $2; }')
guest_user=$(vagrant ssh-config | grep 'User ' | awk '{ print $2; }')
private_key=$(vagrant ssh-config | grep 'IdentityFile ' | awk '{ print $2; }' | tr -d '"')
ssh-keygen -f "$HOME/.ssh/known_hosts" -R [localhost]:$guest_port > /dev/null 2>&1

echo "uploading '$source_path' from host to '$target_path' on VM..."
scp -q -r -P "$guest_port" -i "$private_key" -o "StrictHostKeyChecking no" \
    "$source_path" $guest_user@localhost:"$target_path"

echo "done."
