ambevar-dotfiles/.scripts/dataindex

56 lines
997 B
Bash
Executable File

#!/bin/sh
DATE=
_printhelp ()
{
cat<<EOF
Usage: ${1##*/} [-f]
Create index of folder hierarchies. This is used as a small "backup" purpose. In
case of data loss, it is still possible to get the full file list thanks to the
indexes.
-f: overwrite if output exists
EOF
}
OPT_NOCLOBBER=true
while getopts ":dfh" opt; do
case $opt in
h)
_printhelp "$0"
exit 0
;;
f)
OPT_NOCLOBBER=false
;;
?)
_printhelp "$0"
exit 1
;;
:)
_printhelp "$0"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
_printhelp "$0"
exit 1
fi
for i ; do
i="$(realpath "$i")"
[ ! -d "$i" ] && continue
OUTPUT="${i##*/}.index"
[ -e "$OUTPUT" ] && $OPT_NOCLOBBER && OUTPUT="${i##*/}-$(date +%F-%T).index"
echo "$OUTPUT"
find "$i" -type f | sort > "$OUTPUT"
echo "## $(date +%F)" >> "$OUTPUT"
done