59 lines
1.0 KiB
Bash
Executable File
59 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
function helpexit() {
|
|
echo 'Create or append md5sum list of files
|
|
Usage: md5sum-update [-r] [list name]
|
|
-r recursive
|
|
list name is md5sums.txt by default
|
|
|
|
Check files with "md5sum -m m5sums.txt"
|
|
'
|
|
exit
|
|
}
|
|
|
|
recursive=0
|
|
list_name="md5sums.txt"
|
|
for ((i=1; i<=${#@}; i++)) {
|
|
[[ "${!i}" = "-h" ]] && helpexit
|
|
[[ "${!i}" = "--help" ]] && helpexit
|
|
[[ "${!i}" = "-r" ]] && { recursive=1; continue; }
|
|
list_name="${!i}"
|
|
}
|
|
set -e
|
|
echo "Updating: $list_name"
|
|
test -f "$list_name" || touch "$list_name"
|
|
|
|
_update() {
|
|
if [ "$file" = "$list_name" ]; then
|
|
return
|
|
fi
|
|
if test -d "$file"; then
|
|
echo "$file is a directory"
|
|
return
|
|
fi
|
|
if test -f "$file"; then
|
|
if grep -q " $file$" "$list_name"; then
|
|
echo "$file: exist"
|
|
else
|
|
echo "$file: new"
|
|
md5sum "$file" >> "$list_name"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
shopt -s globstar
|
|
shopt -s nullglob
|
|
|
|
if [[ "$recursive" -eq 1 ]]; then
|
|
for file in **; do
|
|
_update
|
|
done
|
|
else
|
|
for file in *; do
|
|
_update
|
|
done
|
|
fi
|
|
|
|
|
|
sort -k 2 -o "$list_name" "$list_name"
|