Created
April 1, 2018 12:27
-
-
Save timm0e/9c1cd25b4b73ca87bb066458a9665685 to your computer and use it in GitHub Desktop.
Dircmp - compare folders with cmp and output the files that are different - great for creating "delta" archives
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 | |
# | |
# This is a positional arguments-only example of Argbash potential | |
# | |
# ARG_HELP([The general script's help msg]) | |
# ARG_POSITIONAL_SINGLE([changed], [The directory with changed contents]) | |
# ARG_POSITIONAL_SINGLE([unchanged], [The directory with unchanged contents]) | |
# ARGBASH_GO | |
# [ <-- needed because of Argbash | |
orgdir=$PWD | |
changed=$(realpath $_arg_changed) | |
unchanged=$(realpath $_arg_unchanged) | |
cd $changed | |
find . -type f -print0 |sed "s#'#\\\'#g"| xargs -0 -i bash -c "cmp -s {} ${unchanged}/{} 2>/dev/null ; if [ \$? -ne 0 ]; then echo {} ;fi" | |
cd $orgdir | |
# ] <-- needed because of Argbash |
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 | |
# | |
# This is a positional arguments-only example of Argbash potential | |
# | |
# ARG_HELP([The general script's help msg]) | |
# ARG_POSITIONAL_SINGLE([changed],[The directory with changed contents]) | |
# ARG_POSITIONAL_SINGLE([unchanged],[The directory with unchanged contents]) | |
# ARGBASH_GO() | |
# needed because of Argbash --> m4_ignore([ | |
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ### | |
# Argbash is a bash code generator used to get arguments parsing right. | |
# Argbash is FREE SOFTWARE, see https://argbash.io for more info | |
die() | |
{ | |
local _ret=$2 | |
test -n "$_ret" || _ret=1 | |
test "$_PRINT_HELP" = yes && print_help >&2 | |
echo "$1" >&2 | |
exit ${_ret} | |
} | |
begins_with_short_option() | |
{ | |
local first_option all_short_options | |
all_short_options='h' | |
first_option="${1:0:1}" | |
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0 | |
} | |
# THE DEFAULTS INITIALIZATION - POSITIONALS | |
_positionals=() | |
# THE DEFAULTS INITIALIZATION - OPTIONALS | |
print_help () | |
{ | |
printf '%s\n' "The general script's help msg" | |
printf 'Usage: %s [-h|--help] <changed> <unchanged>\n' "$0" | |
printf '\t%s\n' "<changed>: The directory with changed contents" | |
printf '\t%s\n' "<unchanged>: The directory with unchanged contents" | |
printf '\t%s\n' "-h,--help: Prints help" | |
} | |
parse_commandline () | |
{ | |
while test $# -gt 0 | |
do | |
_key="$1" | |
case "$_key" in | |
-h|--help) | |
print_help | |
exit 0 | |
;; | |
-h*) | |
print_help | |
exit 0 | |
;; | |
*) | |
_positionals+=("$1") | |
;; | |
esac | |
shift | |
done | |
} | |
handle_passed_args_count () | |
{ | |
_required_args_string="'changed' and 'unchanged'" | |
test ${#_positionals[@]} -ge 2 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 2 (namely: $_required_args_string), but got only ${#_positionals[@]}." 1 | |
test ${#_positionals[@]} -le 2 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 2 (namely: $_required_args_string), but got ${#_positionals[@]} (the last one was: '${_positionals[*]: -1}')." 1 | |
} | |
assign_positional_args () | |
{ | |
_positional_names=('_arg_changed' '_arg_unchanged' ) | |
for (( ii = 0; ii < ${#_positionals[@]}; ii++)) | |
do | |
eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1 | |
done | |
} | |
parse_commandline "$@" | |
handle_passed_args_count | |
assign_positional_args | |
# OTHER STUFF GENERATED BY Argbash | |
### END OF CODE GENERATED BY Argbash (sortof) ### ]) | |
# [ <-- needed because of Argbash | |
orgdir=$PWD | |
changed=$(realpath $_arg_changed) | |
unchanged=$(realpath $_arg_unchanged) | |
cd $changed | |
find . -type f -print0 |sed "s#'#\\\'#g"| xargs -0 -i bash -c "cmp -s {} ${unchanged}/{} 2>/dev/null ; if [ \$? -ne 0 ]; then echo {} ;fi" | |
cd $orgdir | |
# ] <-- needed because of Argbash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment