etc/post-mirror.d/worldofspectrum: Maintain an unzipped tree in parallel. distorted
authorMark Wooding <mdw@distorted.org.uk>
Thu, 28 Aug 2014 14:56:15 +0000 (15:56 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 28 Aug 2014 14:56:15 +0000 (15:56 +0100)
etc/post-mirror.d/worldofspectrum [new file with mode: 0755]

diff --git a/etc/post-mirror.d/worldofspectrum b/etc/post-mirror.d/worldofspectrum
new file mode 100755 (executable)
index 0000000..3531f98
--- /dev/null
@@ -0,0 +1,20 @@
+#! /bin/sh -e
+
+## Unpack all of the zip files.
+wos=$MIRRORS/worldofspectrum
+from=$wos/games to=$wos/games.unpack
+(cd "$from" && find . -name \*.zip -print) |
+while read i; do
+  case $i in ../* | */../*) continue ;; esac
+  path=${i%.zip}; dir=${path%/*} base=${path##*/}
+  if [ -e "$to/$path/.stamp" ] &&
+     [ !  "$from/$i" -nt "$to/$path/.stamp" ]; then
+    continue
+  fi
+  rm -rf "$to/%tmp" "$to/$path"
+  mkdir -p "$to/%tmp/$base"
+  (cd "$to/%tmp/$base" && unzip "$from/$i")
+  touch -r"$from/$i" "$to/%tmp/$base/.stamp"
+  mv "$to/%tmp/$base" "$to/$dir/"
+  rmdir "$to/%tmp"
+done