#!/bin/sh

# TESTED-ON: 7.0.3 build-19193900

# on cli: copy and execute the line below to download and configure rsync straight away on your esxi system
# esxcli network firewall ruleset set -e true -r httpClient ; wget "https://svzone.de/files/srv/scripts/esxi-packages/rsync/install.sh" -O- --no-check-certificate | sh


echo "downloading rsync binary and fw config..."
#wget --no-check-certificate https://github.com/itiligent/RSYNC-for-ESXi/raw/main/rsync
wget "https://svzone.de/files/srv/scripts/esxi-packages/rsync/rsync" --no-check-certificate
echo $?
wget "https://svzone.de/files/srv/scripts/esxi-packages/rsync/rsync-openfwports.xml" --no-check-certificate

# create a symbolic link to the file on the datastore
#ln -s /vmfs/volumes/622d4808-61d34746-1916-1866da7f1485/rsync/rsync-static /bin/rsync

echo "copying to bin directory..."
cp rsync /bin/rsync
echo $?
chmod 755 /bin/rsync
echo $?

# open fw for rsync
echo "opening firewall port ..."
mv rsync-openfwports.xml /etc/vmware/firewall/rsync.xml
esxcli network firewall refresh
esxcli network firewall ruleset list

echo "checking rsync..."
/bin/rsync -V | grep version

echo
echo "example usage to copy VMDKs..."
echo "rsync -av --partial --inplace --append --progress vmdk_file syncuser@host1:/destination"
echo

echo "esxi IPs..."
esxcli network ip interface ipv4 get
echo "put ssh-keys here: vi /etc/ssh/keys-root/authorized_keys"
exit
