m5dsum list utility

This commit is contained in:
2018-02-25 21:13:40 +02:00
parent 752a7ca645
commit 324b666c1a
2 changed files with 35 additions and 0 deletions

1
bin/md5sum-update Symbolic link
View File

@@ -0,0 +1 @@
../files/md5sum-update

34
files/md5sum-update Executable file
View File

@@ -0,0 +1,34 @@
#!/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'
exit
}
[[ "$1" = "-h" ]] && helpexit
list_name="$1"
[[ -z "$1" ]] && list_name="md5sums.txt"
test -f "$list_name" || touch "$list_name"
for file in *; do
if [ $file = $list_name ]; then
continue
fi
if test -d "$file"; then
echo $file is a directory
continue
fi
if test -f "$file"; then
if grep -q " $file$" $list_name; then
echo "$file already added"
else
echo "$file adding..."
md5sum "$file" >> "$list_name"
fi
fi
done
sort -k 2 -o "$list_name" "$list_name"