Skip to content

Instantly share code, notes, and snippets.

@S1M0N38
Created May 16, 2024 08:43
Show Gist options
  • Save S1M0N38/beacf2301eab8a818fdcc27d2838c03a to your computer and use it in GitHub Desktop.
Save S1M0N38/beacf2301eab8a818fdcc27d2838c03a to your computer and use it in GitHub Desktop.
#!/bin/bash
REMOTE_HOST=user@my.remote-machine.com
REMOTE_DIR=/path/to/project/dir/in/remote/
LOCAL_DIR=/path/to/project/dir/in/local/
usage() {
echo "Usage: $0 [option]"
echo "Options:"
echo " -u, --upload Upload files to the remote server"
echo " -d, --download Download files from the remote server"
}
upload() {
echo -e "\033[1mUploading...\033[0m"
rsync -avzh \
--files-from <(grep -v '^#' "$LOCAL_DIR/scripts/upload.txt") \
"$LOCAL_DIR" "$REMOTE_HOST:$REMOTE_DIR" |
if [ -n "$SIMPLE" ]; then
grep -v '/$' | grep -v '^$' |
grep -v 'building file list' |
grep -v 'sent' | grep -v 'total size'
else
cat
fi
}
download() {
echo -e "\033[1mDownloading...\033[0m"
rsync -avzrh --files-from <(grep -v '^#' "$LOCAL_DIR/scripts/download.txt") \
"$REMOTE_HOST:$REMOTE_DIR" "$LOCAL_DIR" |
if [ -n "$SIMPLE" ]; then
grep -v '/$' | grep -v '^$' |
grep -v 'building file list' |
grep -v 'sent' | grep -v 'total size'
else
cat
fi
}
# Parse command line options
while (("$#")); do
case "$1" in
-u | --upload)
UPLOAD=true
shift
;;
-d | --download)
DOWNLOAD=true
shift
;;
*)
echo "Invalid option: $1" >&2
usage
exit 1
;;
esac
done
# Check if either upload or download option is specified
if [[ -z $UPLOAD && -z $DOWNLOAD ]]; then
echo "Please specify either --upload or --download option."
usage
exit 1
fi
# Perform upload or download based on options
if [[ $UPLOAD ]]; then
upload
fi
if [[ $DOWNLOAD ]]; then
download
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment