comparison bin/moedump @ 138:f963d52c031a

Merge.
author Edho Arief <edho@myconan.net>
date Wed, 02 Nov 2011 22:12:16 +0700
parents 5bafb912837e
children
comparison
equal deleted inserted replaced
137:983beb13c736 138:f963d52c031a
1 #!/bin/sh
2
3 safe_mv() { mv -- "$@"; }
4 safe_ln() { ln -s -- "$1" "$2"; }
5 safe_basename() { basename -- "$1"; }
6 get_md5() { ${MD5} -- "$1" | cut -d' ' -f1; }
7 get_filename() { safe_basename "${1%.*}"; }
8
9 eod() { "$@" || errx "$@"; }
10 errx() { echo "Error executing: $@"; exit 1; }
11 MD5="md5sum"
12 [ "$(safe_basename "${PWD}")" = ".all" ] || { echo "Wrong working directory. This script must be run in .all directory. Aborting."; exit 1; }
13
14 [ -d "../.trash" ] || eod mkdir ../.trash
15
16 echo "Total files: $(find ../* -type f | wc -l) files."
17
18 num=0
19 for i in ../*/*
20 do
21 if [ -h "$i" ]
22 then
23 [ -f "$i" ] || { eod safe_mv "$i" "../.trash" && echo "Broken file: $(safe_basename "$i"). Moved to trash."; }
24 else
25 if [ "$(get_md5 "$i")" = "$(get_filename "$i")" ]
26 then
27 eod safe_mv "$i" .
28 eod safe_ln "../.all/$(safe_basename "$i")" "$i"
29 else
30 eod safe_mv "$i" "../.trash" && echo "Broken file: $(get_filename "$i"). Moved to .trash."
31 fi
32 printf "%s" "."
33 num=$((num+1))
34 [ "$((num%100))" -eq 0 ] && printf "${num}"
35 fi
36 done
37
38 echo "done"