Mercurial > ec-dotfiles
diff bin/moedump @ 138:f963d52c031a
Merge.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Wed, 02 Nov 2011 22:12:16 +0700 |
parents | 5bafb912837e |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/moedump Wed Nov 02 22:12:16 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"