#! /bin/bash # Rsyncs ~/Homework dir and contents. case "$#" in 0) # nothing was passed in extra, do everything doAll=true; ;; 1) case "$1" in "-fh" | "--from-home") fromHome=true; ;; "-th" | "--to-home") toHome=true; ;; *) showHelp=true; ;; esac ;; *) echo "Wrong number of parameters provided."; echo -e "Usage:\t$0"; echo -e "\t$0 --from-home"; echo -e "\t$0 -from"; echo -e "\t$0 --to-home"; echo -e "\t$0 -to"; echo -e "\t$0 -h\t(Prints a full help message.)"; exit; ;; esac if [ $showHelp ]; then echo "Usage: $0 [OPTIONS]" echo -e "\t-OPTIONS-" echo -e "\tNo parameters, copying both back and forth (does not overwrite, only updates)"; echo -e "\t--from-home OR -from copies files from Home to localhost only."; echo -e "\t--to-home OR -to copies files from localhost to Home only."; echo -e "\t-h prints this help message"; exit; fi if [ -e ~/Homework ]; then # z, compress # r, recursive # v, verbose # n, dry-run # u, updates only (dont overwrite if DEST has newer) if [[ $doAll || $fromHome ]]; then echo "Copying from Home to localhost"; rsync -zru mkava@home.mattkava.com:~/Homework/* ~/Homework/ fi if [[ $doAll || $toHome ]]; then echo "Copying to Home from localhost"; rsync -zru ~/Homework/* mkava@home.mattkava.com:~/Homework/ fi else echo "~/Homework doesnt exist."; exit; fi echo "Back up complete.";