dataindex: more versatile

master
Pierre Neidhardt 2013-08-14 02:33:34 +02:00
parent c1f128c630
commit e19cb4e939
2 changed files with 46 additions and 31 deletions

View File

@ -1,51 +1,55 @@
#!/bin/sh
FOLDER_LIST="/media/data1/Documents
/media/data1/Videos
/media/data2/GamesFiles
/media/data2/Musics"
OUTPUT="$HOME/personal/dataperso/index"
DATE="$(date +%F)"
DATE=
_printhelp ()
{
cat<<EOF
Usage: ${1##*/} [-h]
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.
-h: Show this help.
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
}
while getopts ":dh" opt; do
OPT_NOCLOBBER=true
while getopts ":dfh" opt; do
case $opt in
h)
_printhelp "$0"
return 1
exit 0
;;
f)
OPT_NOCLOBBER=false
;;
?)
_printhelp "$0"
return 1
exit 1
;;
:)
_printhelp "$0"
return 1
exit 1
;;
esac
done
shift $(($OPTIND - 1))
## Prepare output.
mkdir -p "$OUTPUT"
if [ $# -eq 0 ]; then
_printhelp "$0"
exit 1
fi
while read -r i; do
echo "$i"
find "$i" -type f | sort > "$OUTPUT/${i##*/}.index"
echo "## $DATE" >> "$OUTPUT/${i##*/}.index"
done <<EOF
$FOLDER_LIST
EOF
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

View File

@ -23,15 +23,20 @@ $HOME/.lesshst
$HOME/.local/share/newsbeuter
$HOME/.local/share/webkit
$HOME/.mtap.fuseiso
$HOME/.mutt.pwds.cpt
$HOME/.pulse-cookie
$HOME/.ssh
$HOME/.viminfo
$HOME/.w3m
$HOME/.zcompdump"
echo "==> List of files to be cleaned."
RMLIST_CRITICAL="
$HOME/.mutt.pwds.cpt
$HOME/.ssh"
echo "==> List of files to be removed."
echo "$RMLIST"
echo
echo "==> List of files to be wiped."
echo "$RMLIST_CRITICAL"
CHOICE="N"
echo
@ -59,18 +64,16 @@ if [ -d "$HOME/Dropbox" ] || [ -d "$HOME/.dropbox" ]; then
fi
## Clean trash if possible.
echo
echo "==> Emptying trash."
if [ -z "$(command -v trash-empty)" ]; then
echo
echo "==> Emptying trash."
echo ":: 'trash-empty' not installed, you have to clean trash manually."
rm -rvf "$HOME/.local/share/Trash"
else
echo
echo "==> Emptying trash."
trash-empty
fi
## Clear data.
## Remove data.
echo
while read -r i; do
rm -rvf "$i"
@ -78,5 +81,13 @@ done <<EOF
$RMLIST
EOF
## Wipe data
echo
while read -r i; do
shred -zuv "$i"
done <<EOF
$RMLIST_CRITICAL
EOF
echo
echo "==> Cleaning done."