Mercurial > ec-dotfiles
comparison 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 |
comparison
equal
deleted
inserted
replaced
123:173833e4ba35 | 124:5bafb912837e |
---|---|
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" |