Created
May 16, 2024 08:43
-
-
Save S1M0N38/beacf2301eab8a818fdcc27d2838c03a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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