#!/bin/sh
set -e
nl='
'
bad_urls=
urls=$(cat <<'END'
https://lists.debian.org
https://alioth.debian.org/projects/
https://alioth.debian.org/tracker/
https://alioth.debian.org"
https://alioth.debian.org/"
https://penta.debconf.org"
https://penta.debconf.org/"
https://www.debian.org
https://wiki.debian.org
https://debconf6.debconf.org/comas
https://penta.debconf.org/user
END
)
regexes=$(cat <<'END'
https://debconf[0-9]\+.debconf.org/
https://penta.debconf.org/dc[0-9]\+_schedule
END
)

for url in $urls
do
	if grep -qF "$url" $* ; then
		bad_urls="$bad_urls${nl}$url"
	fi
done

for regex in $regexes
do
	urls="$(grep -oh "$regex" $* | sort -u)"
	if [ "x$urls" != x ] ; then
		bad_urls="$bad_urls${nl}$urls"
	fi
done

if [ "x$bad_urls" != x ] ; then
	cat <<EOF
Commit contains these Debian HTTPS URLs, please change them to HTTP.
Since the SSL certs for Debian/DebConf/SPI websites are only signed by
SPI and not by any SSL CA that is trusted by browsers outside of Debian,
we should avoid linking to https versions of Debian websites so that
people not using Debian don't get errors they may not understand.
$bad_urls
EOF
	exit 1
fi