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
|
|
|
|
}
|
|
|
|
|
2024-02-12 13:11:40 -08:00
|
|
|
rsynchc() { rsync --help | grep "\-$1"; }
|
|
|
|
alias rsynch="rsynchc"
|
|
|
|
|
2023-01-18 16:43:21 -08:00
|
|
|
function dir_copy () {
|
|
|
|
|
2023-03-20 10:37:45 -07:00
|
|
|
[[ ! $(command -v rsync) ]] && { echo rsync must be installed to use this function; return 5; }
|
2023-01-18 16:43:21 -08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-02-12 12:53:25 -08:00
|
|
|
dir_size () {
|
|
|
|
if sudo ls $1 >/dev/null ; then
|
|
|
|
sudo du -h --apparent-size --max-depth=1 $1 | sort -rh
|
|
|
|
else
|
|
|
|
echo $1 not a directory
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# for dir in $(/bin/find -maxdepth 1 -name "*[cC]ache*" -type d ); do; echo $dir; done
|