Mercurial > ec-dotfiles
view bin/moedump @ 693:37a2470380f2
[bashrc] Fix comment about freebsd grep
author | nanaya <me@nanaya.pro> |
---|---|
date | Sun, 23 Oct 2022 01:56:54 +0900 |
parents | 5bafb912837e |
children |
line wrap: on
line source
#!/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"