#!/usr/bin/env bash


set -e
function getFileName() {
	curl -s https://files.openscad.org/snapshots/ | htmlq 'a[href$="x86_64.AppImage"]' -a href | tail -n1
}

function getDownloadUrl() {
	echo "https://files.openscad.org/snapshots/$(getFileName)"
}


wget -q  -O /tmp/openscad "$(getDownloadUrl)"
chmod +x /tmp/openscad
chmod +x /tmp/openscad
cd /opt
 /tmp/openscad --appimage-extract
 ln -s /opt/squashfs-root/usr/bin/openscad /usr/local/bin/openscad
