35 lines
688 B
Bash
Executable File
35 lines
688 B
Bash
Executable File
#!/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"
|