#!/bin/bash

DEFAULT_SRC_URI="http://dl.google.com/earth/client/current/GoogleEarthLinux.bin"

type -P curl >/dev/null || {
	echo " * Please install net-misc/curl before you use this tool."
	exit 1
}

# Check what SRC_URI to use
if [ -z "$1" ]; then
	SRC_URI="${DEFAULT_SRC_URI}"
	echo " * Using default SRC_URI=\"${SRC_URI}\""
else
	SRC_URI="$1"
	echo " * Using alternative SRC_URI=\"${SRC_URI}\""
fi

# The first fifty lines cover about one kilobyte:

eval $( curl --silent --range 0-1000 "${SRC_URI}" -o - | grep -a '^label=' - )
if [ -n "${label}" ]; then
	version="${label/* }"
	echo
	echo "== ${label} =="
	echo " * Version appears to be: ${version}"
	echo " * Ebuild name should be: googleearth-${version}.ebuild"
else
	echo "!! No label found. Please check the SRC_URI and try again. !!"
	exit 1
fi
