diff options
Diffstat (limited to 'bin/poolify')
-rwxr-xr-x | bin/poolify | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/bin/poolify b/bin/poolify new file mode 100755 index 0000000..34e0b42 --- /dev/null +++ b/bin/poolify @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +url2murl() { + local x + x=$1 + x=${x//'^'/'^5E'} + x=${x//':'/'^3A'} + x=${x//'%'/'^25'} + printf '%s' "$x" +} + +main() { + set -euE -o pipefail + shopt -s nullglob + + while read -r snap name date time size; do + dirpart="${name%/*}" + filepart="${name##*/}" + filedir=dat/pools/files/"${date//-/}${time//:/}-${name//\//_}" + snapdir=dat/pools/snaps/"${snap}-${dirpart//\//_}" + mkdir -p -- "$filedir" "$snapdir" + ln -sr "$filedir/$filepart" "$snapdir" + done < "$1" + + while read -r time url; do + name="${url##*/Public/}" + dirpart="${name%/*}" + filepart="${name##*/}" + + if [[ -z "$filepart" ]]; then + continue + fi + + pools=(dat/pools/files/*-"${name//\//_}") + pools=("${pools[@]##*/}") + + mypool='' + for pool in "${pools[@]}"; do + pooltime="${pool%%-*}" + if [[ "${pooltime}00" -le "$time" ]]; then + mypool=$pool + fi + done + if [[ -z "$mypool" ]]; then + >&2 printf 'Could not find pool for %s %s' "$time" "$url" + false + fi + + waurl="http://web.archive.org/web/$time/$url" + file="dat/content-file/$(url2murl "${waurl#http://}")" + + declare -i i=0 + while true; do + link="dat/pools/files/$mypool/$filepart.$i" + link="${link%.0}" + a="$(readlink -f "$link")" || true + b="$(readlink -f "$file")" + if cmp -s -- "$a" "$b"; then + break + fi + if ln -sr "$b" "$link"; then + break + fi + i+=1 + done + done < "$2" +} + +main "$@" |