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