From 57a1fc656e05e1fcf07e4cff3dc988c6b5c2bc59 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 12 Feb 2023 12:13:38 +0530 Subject: add script to recover file dates lost by git --- recover.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 recover.sh diff --git a/recover.sh b/recover.sh new file mode 100755 index 0000000..5c827aa --- /dev/null +++ b/recover.sh @@ -0,0 +1,49 @@ +LIMIT=5000 +read_dom () { + ORIGINAL_IFS=$IFS + IFS=\> + read -d \< ENTITY CONTENT + IFS=$ORIGINAL_IFS +} + +repair_post_dates() { + local count=0 + local url=https://peppe.rs/posts/ + while read_dom; do + ((count++)) + if [ "$count" -ge "$LIMIT" ]; then + exit + fi + if [[ $ENTITY = "link" ]] ; then + local _f=${CONTENT##$url} + local f="posts/${_f%%/}.md" + elif [[ $ENTITY = "pubDate" ]] ; then + local d=$CONTENT + repair "$d" "$f" + fi + done +} + +repair_art_dates() { + local f d + while mapfile -t -n 2 a && ((${#a[@]})); do + f=${a[0]} + d=${a[1]} + + f=${f##src=\"/} + d=$(dateconv -i '%d/%m — %Y' "$d") + + repair "$d" "$f" + done +} + +repair() { + echo "[+] repairing $2" + touch -am -d "$1" "$2" +} + +grep -B1 pubDate docs/index.xml | repair_post_dates +grep -Eo \ + -e 'src="/art/.*.png' \ + -e '[0-9]{2}/[0-9]{2}...[0-9]{4}' \ + docs/art/index.html | repair_art_dates -- cgit v1.2.3