Files
VCS/push.sh
T

49 lines
1.3 KiB
Bash
Raw Normal View History

2024-06-26 12:03:29 -04:00
#!/bin/bash
# Navigate to the current working directory
cd "$PWD"
if [ ! -f "$HOME/ionsrc/creds.txt" ]; then
2024-06-26 13:11:19 -04:00
echo -e "\e[31mcredentials file not found!\e[0m"
2024-06-26 12:03:29 -04:00
exit 1
elif [ ! -f "$PWD/.ionvcs/src.config"]; then
2024-06-26 13:11:19 -04:00
echo -e "\e[31mconfig file not found!\e[0m"
2024-06-26 12:03:29 -04:00
exit 1
fi
source "$HOME/ionsrc/creds.txt"
source "$PWD/.ionvcs/src.config"
# Set the remote path for rsync
REMOTE_PATH="$csrc"
while getopts ":of" opt; do
case $opt in
f)
force_flag=true
;;
esac
done
2024-06-26 12:34:01 -04:00
# Set the destination folder
if [ -n "$2" ]; then
DEST_FOLDER="$PWD/$2"
else
DEST_FOLDER="$PWD"
fi
2024-06-26 12:03:29 -04:00
# Use rsync with sshpass to check for differences without copying
DIFF_OUTPUT=$(/usr/bin/sshpass -p "$password" rsync -avcn --delete -e ssh "$REMOTE_PATH" "$DEST_FOLDER")
# Check if there are differences
if [ ! -z "$DIFF_OUTPUT" && ! $force_flag ]; then
2024-06-26 13:11:19 -04:00
echo -e "\e[31mERROR\e[0m conflicts found between the local and remote directories (make sure they're correct and re-run using the \e[31m-f\e[0m flag):"
2024-06-26 12:03:29 -04:00
echo "$DIFF_OUTPUT"
exit 1;
fi
# Use rsync with sshpass to copy files with a progress bar
echo -n "cloning..."
2024-06-26 18:59:59 -04:00
/usr/bin/sshpass -p "$password" rsync -avcn --include-from="$PWD/.ionvcs/add.config" --info=progress2 --no-i-r -h -e ssh "$DEST_FOLDER" "$REMOTE_PATH" || { echo "failed to clone!"; exit 1; }
2024-06-26 12:03:29 -04:00
echo "done!"