Skip to content

Instantly share code, notes, and snippets.

@karlvr
Last active November 3, 2022 08:06
Show Gist options
  • Save karlvr/794a3a03f81da7981204692f72c42422 to your computer and use it in GitHub Desktop.
Save karlvr/794a3a03f81da7981204692f72c42422 to your computer and use it in GitHub Desktop.
Download and update OpenSceneryX from https://www.opensceneryx.com
#!/bin/bash -eu
# Download and update OpenSceneryX from https://www.opensceneryx.com
target="${1:-}"
if [ -z "$target" ]; then
echo "usage: $0 <target dir>" >&2
exit 1
fi
if [ ! -d "$target" ]; then
echo "target is not a directory: $target" >&2
exit 1
fi
manifest="$target/manifest.xml"
if [ -f "$manifest" ]; then
echo "Using manifest: $manifest" >&2
else
echo "Download manifest" >&2
curl -o "${manifest}.zip" https://downloads.opensceneryx.com/manifest.xml.zip
unzip -d "$(dirname "$manifest")" "${manifest}.zip"
rm -f "${manifest}.zip"
fi
stylesheet=$(mktemp)
cat <<EOF > "$stylesheet"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
<xsl:template match="xmldict">
<xsl:apply-templates select="key" />
</xsl:template>
<xsl:template match="xmldict/key">
<xsl:value-of select="." />
<xsl:text>|</xsl:text>
<!-- reference https://devhints.io/xpath -->
<xsl:apply-templates select="./following-sibling::dict[1]/key[text()='size']/following-sibling::integer[1]/text()" />
<xsl:text>|</xsl:text>
<xsl:apply-templates select="./following-sibling::dict[1]/key[text()='digest']/following-sibling::string[1]/text()" />
<xsl:value-of select="'&#10;'" />
</xsl:template>
</xsl:stylesheet>
EOF
xsltproc --novalid "$stylesheet" "$manifest" | while read line; do
IFS="|" read -ra arr <<<"$line"
path="${arr[0]}"
file="$target$path"
if [ -f "$file" ]; then
size=$(stat -f '%z' "$file")
if [ "$size" == "${arr[1]}" ]; then
digest=$(md5 -q "$file" | tr '[:lower:]' '[:upper:]')
if [ "$digest" == "${arr[2]}" ]; then
echo "uptodate: $file"
continue
fi
fi
fi
echo "download: $path"
mkdir -p "$(dirname "$file")"
curl -s -o "$file.zip" https://downloads.opensceneryx.com/repository$path.zip
unzip -q -d "$(dirname "$file")" "$file.zip"
rm -f "$file.zip"
done
rm -f "$stylesheet"
echo
echo "Download / update complete"
echo "Please consider visiting https://www.opensceneryx.com to Donate to support OpenSceneryX"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment