2023-01-18 16:43:21 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# simple local copy wintin or merge one directory to another using rsync. Preserves everything
|
|
|
|
# present working directory to supplied destination
|
|
|
|
|
|
|
|
isDir() {
|
|
|
|
if [[ -d $1 ]]
|
|
|
|
then
|
|
|
|
echo "true"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function dir_copy () {
|
|
|
|
|
|
|
|
[[ ! $(which rsync) ]] && { echo rsync must be installed to use this function; return 5; }
|
|
|
|
module_load confirm
|
|
|
|
local usesudo;local cmd;local src;local noconfirm;local merge
|
|
|
|
|
|
|
|
declare OPTION
|
|
|
|
declare OPTARG
|
|
|
|
declare OPTIND
|
|
|
|
while getopts 'sem' OPTION; do
|
|
|
|
case "$OPTION" in
|
|
|
|
s)
|
2023-03-12 10:46:05 -07:00
|
|
|
usesudo=sudo
|
2023-01-18 16:43:21 -08:00
|
|
|
;;
|
|
|
|
e)
|
|
|
|
noconfirm=true
|
|
|
|
;;
|
|
|
|
m)
|
|
|
|
merge=true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo unknown option $OPTION
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
|
|
|
[ $# -ne 2 ] && echo two directories source and destination need to be passed && return 2
|
|
|
|
src=$(realpath -s $1)
|
|
|
|
dest=$(realpath -s $2)
|
|
|
|
[ ! -d "$src" ] && echo source: $src is not a directory && return 3
|
|
|
|
[[ $merge ]] && src=${src}/
|
2023-03-12 10:46:05 -07:00
|
|
|
cmd="$usesudo rsync --exclude *[C]ache* --progress -aAru $src $dest"
|
2023-01-18 16:43:21 -08:00
|
|
|
echo $cmd
|
|
|
|
[[ ! -v PS1 ]] && noconfirm=true
|
|
|
|
[[ ! $noconfirm ]] && { confirm Do you want to $([[ $merge ]] && echo merge $src into || echo copy $src within) $dest? || return 0; }
|
|
|
|
echo copying.....
|
|
|
|
eval $cmd
|
|
|
|
}
|
|
|
|
|