summaryrefslogtreecommitdiff
path: root/bin/poolify
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-07-01 18:17:38 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-07-01 18:17:38 -0400
commit55f9bd8d5226eb49f5899c5ddca89c655ef96e9b (patch)
tree53096770e331f2d571fc9e49af5000cfed1fa0d8 /bin/poolify
parente4109fab0bece003dc53c78c7cc8608b68328312 (diff)
stuff
Diffstat (limited to 'bin/poolify')
-rwxr-xr-xbin/poolify69
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 "$@"