Mercurial > ec-dotfiles
diff bin/moedump @ 124:5bafb912837e
Massive addition of old scripts collection.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Wed, 26 Oct 2011 15:22:00 +0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/moedump Wed Oct 26 15:22:00 2011 +0700 @@ -0,0 +1,38 @@ +#!/bin/sh + +safe_mv() { mv -- "$@"; } +safe_ln() { ln -s -- "$1" "$2"; } +safe_basename() { basename -- "$1"; } +get_md5() { ${MD5} -- "$1" | cut -d' ' -f1; } +get_filename() { safe_basename "${1%.*}"; } + +eod() { "$@" || errx "$@"; } +errx() { echo "Error executing: $@"; exit 1; } +MD5="md5sum" +[ "$(safe_basename "${PWD}")" = ".all" ] || { echo "Wrong working directory. This script must be run in .all directory. Aborting."; exit 1; } + +[ -d "../.trash" ] || eod mkdir ../.trash + +echo "Total files: $(find ../* -type f | wc -l) files." + +num=0 +for i in ../*/* +do + if [ -h "$i" ] + then + [ -f "$i" ] || { eod safe_mv "$i" "../.trash" && echo "Broken file: $(safe_basename "$i"). Moved to trash."; } + else + if [ "$(get_md5 "$i")" = "$(get_filename "$i")" ] + then + eod safe_mv "$i" . + eod safe_ln "../.all/$(safe_basename "$i")" "$i" + else + eod safe_mv "$i" "../.trash" && echo "Broken file: $(get_filename "$i"). Moved to .trash." + fi + printf "%s" "." + num=$((num+1)) + [ "$((num%100))" -eq 0 ] && printf "${num}" + fi +done + +echo "done"