Skip to content

Commit

Permalink
base: Cleanup the cpv* and mvv* scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jody-frankowski committed Aug 5, 2024
1 parent 637c1e4 commit c65166b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
11 changes: 10 additions & 1 deletion base/.usr/bin/cpv
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/bin/sh
#!/bin/bash

set -eu

if [[ $# == 0 || "$1" == -h || "$1" == --help ]] ; then
echo Use rsync to copy files and directories. >&2
echo >&2
echo "Usage: $(basename $0) [RSYNC_OPTIONS] FILE|DIR... DESTINATION" >&2
exit 1
fi

exec rsync -avPih "$@"
17 changes: 15 additions & 2 deletions base/.usr/bin/cpvr
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/sh
#!/bin/bash

set -eu

if [[ $# == 0 || "$1" == -h || "$1" == --help ]] ; then
echo Use rsync to copy files and directories to a \"remote\" destination. >&2
echo A \"remote\" destination is anything that requires ssh. >&2
echo The transfer won\'t use temporary files and will compare files based on their size only. >&2
echo >&2
echo "Usage: $(basename $0) [RSYNC_OPTIONS] FILE|DIR... DESTINATION" >&2
exit 1
fi

# With rsync 2.*, --append will always do a checksum and with rsync 3.+, --append won't do a
# checksum. Use --append-verify to force the checksum.
# Using `--inplace` might be dangerous in some cases, see
# https://lists.samba.org/archive/rsync/2010-June/025178.html
exec rsync -avPih --inplace --size-only --stats "$@"
exec cpv --append --inplace --size-only --stats "$@"
13 changes: 11 additions & 2 deletions base/.usr/bin/cpvs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#!/bin/sh
#!/bin/bash

exec rsync -avPih --rsync-path="sudo rsync" "$@"
set -eu

if [[ $# == 0 || "$1" == -h || "$1" == --help ]] ; then
echo Use rsync to copy files and directories to a destination owned by root. >&2
echo >&2
echo "Usage: $(basename $0) [RSYNC_OPTIONS] FILE|DIR... DESTINATION" >&2
exit 1
fi

exec cpv --rsync-path="sudo rsync" "$@"
17 changes: 13 additions & 4 deletions base/.usr/bin/mvv
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#!/bin/sh

if [[ $# -lt 2 ]] ; then
echo "$0 expects at least one source and one destination." >&2
return 1
set -euo pipefail

if [[ "$#" == 0 ]] || [[ "$1" == -h ]] || [[ "$1" == --help ]] ; then
echo Use rsync to move files and directories. >&2
echo >&2
echo "Usage: $(basename $0) [RSYNC_OPTIONS] FILE|DIR... DESTINATION" >&2
exit 1
fi

dirs=()
for src in "${@:1:$# - 1}" ; do
[[ -d "${src}" ]] && dirs+=("${src}")
done

if rsync -avPih --remove-source-files "$@" ; then
find "${@:1:$(($# - 1))}" -type d -empty -delete
[[ ${#dirs[@]} -gt 0 ]] && find "${dirs[@]}" -type d -empty -delete
fi
14 changes: 8 additions & 6 deletions base/.usr/bin/mvvs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh

if [[ $# -lt 2 ]] ; then
echo "$0 expects at least one source and one destination." >&2
return 1
fi
set -euo pipefail

if rsync -avPih --remove-source-files --rsync-path="sudo rsync" "$@" ; then
find "${@:1:$(($# - 1))}" -type d -empty -delete
if [[ "$#" == 0 ]] || [[ "$1" == -h ]] || [[ "$1" == --help ]] ; then
echo Use rsync to move files and directories to a destination owned by root. >&2
echo >&2
echo "Usage: $(basename $0) [RSYNC_OPTIONS] FILE|DIR... DESTINATION" >&2
exit 1
fi

exec mvv --rsync-path="sudo rsync" "$@"

0 comments on commit c65166b

Please sign in to comment.