ambevar-dotfiles/.scripts/dataindex

56 lines
1017 B
Plaintext
Raw Normal View History

2013-05-15 14:22:08 +02:00
#!/bin/sh
2013-08-14 02:33:34 +02:00
DATE=
2013-05-15 14:22:08 +02:00
_printhelp ()
{
cat<<EOF
Usage: ${1##*/} [-f] FOLDERS
2013-05-15 14:22:08 +02:00
2013-08-14 02:33:34 +02:00
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.
2013-05-15 14:22:08 +02:00
2013-08-14 02:33:34 +02:00
-f: overwrite if output exists
2013-05-15 14:22:08 +02:00
EOF
}
2013-08-14 02:33:34 +02:00
OPT_NOCLOBBER=true
while getopts ":dfh" opt; do
2013-05-15 14:22:08 +02:00
case $opt in
h)
_printhelp "$0"
2013-08-14 02:33:34 +02:00
exit 0
;;
f)
OPT_NOCLOBBER=false
2013-05-15 14:22:08 +02:00
;;
?)
_printhelp "$0"
2013-08-14 02:33:34 +02:00
exit 1
2013-05-15 14:22:08 +02:00
;;
:)
_printhelp "$0"
2013-08-14 02:33:34 +02:00
exit 1
2013-05-15 14:22:08 +02:00
;;
esac
done
shift $(($OPTIND - 1))
2013-08-14 02:33:34 +02:00
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"
(cd "$i" && find * -type f) | sort > "$OUTPUT"
# echo "## $(date +%F)" >> "$OUTPUT"
2013-08-14 02:33:34 +02:00
done
2013-05-15 14:22:08 +02:00