2013-05-15 14:22:08 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-12-27 11:16:50 +01:00
|
|
|
unset DATE
|
2013-05-15 14:22:08 +02:00
|
|
|
|
|
|
|
_printhelp ()
|
|
|
|
{
|
|
|
|
cat<<EOF
|
2013-10-16 14:22:01 +02:00
|
|
|
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-12-27 11:16:50 +01: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
|
2013-12-27 11:16:50 +01:00
|
|
|
base="$(basename "$i")"
|
2013-08-14 02:33:34 +02:00
|
|
|
[ ! -d "$i" ] && continue
|
2013-12-27 11:16:50 +01:00
|
|
|
OUTPUT="$base.index"
|
|
|
|
[ -e "$OUTPUT" ] && $OPT_NOCLOBBER && OUTPUT="$base-$(date +%F-%T).index"
|
2013-08-14 02:33:34 +02:00
|
|
|
echo "$OUTPUT"
|
2013-12-27 11:16:50 +01:00
|
|
|
|
|
|
|
## Find over '.*' and '*', is bad practice since if will fail if no existing
|
|
|
|
## files or for files beginning with a dash. The 'printf' command in find is
|
|
|
|
## for GNU find only.
|
|
|
|
|
|
|
|
## The two following lines do the same for the same time cost. The former is shorter.
|
|
|
|
(cd "$i" && find . -type f) | sed 's/^.\///' | sort > "$OUTPUT"
|
|
|
|
# find "$i" -type f | awk -v str="$i" '{l=length(str)+2; print substr($0, l)}' | sort > "$OUTPUT"
|
2013-08-14 02:33:34 +02:00
|
|
|
done
|
2013-05-15 14:22:08 +02:00
|
|
|
|