recursive md5
This commit is contained in:
@@ -1,34 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
function helpexit() {
|
||||
echo Add more files in md5sum list
|
||||
echo 'Usage: m5sum-update [list name]'
|
||||
echo 'list name is md5sums.txt by default'
|
||||
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
|
||||
}
|
||||
|
||||
[[ "$1" = "-h" ]] && helpexit
|
||||
list_name="$1"
|
||||
[[ -z "$1" ]] && list_name="md5sums.txt"
|
||||
|
||||
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"
|
||||
|
||||
for file in *; do
|
||||
if [ $file = $list_name ]; then
|
||||
continue
|
||||
_update() {
|
||||
if [ "$file" = "$list_name" ]; then
|
||||
return
|
||||
fi
|
||||
if test -d "$file"; then
|
||||
echo $file is a directory
|
||||
continue
|
||||
echo "$file is a directory"
|
||||
return
|
||||
fi
|
||||
if test -f "$file"; then
|
||||
if grep -q " $file$" $list_name; then
|
||||
echo "$file already added"
|
||||
if grep -q " $file$" "$list_name"; then
|
||||
echo "$file: exist"
|
||||
else
|
||||
echo "$file adding..."
|
||||
echo "$file: new"
|
||||
md5sum "$file" >> "$list_name"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user