#!/bin/bash

# Tests redirects of the URLs on the old domain
# URLS array contains the expected oldURL -> newURL pairs

declare -A URLS
URLS['http://waterwave.ch/weblog/6']='https://blog.x-way.org/Webdesign/2002/06/06/Farbenlehre.html'
URLS['http://waterwave.ch/weblog/10']='https://blog.x-way.org/Misc/2002/06/08/fffff.html'
URLS['http://waterwave.ch/weblog/13']='https://blog.x-way.org/Misc/2002/06/11/Blogger_Code.html'
URLS['http://waterwave.ch/weblog/111']='https://blog.x-way.org/Linux/2002/10/17/So_nebenbei.html'
URLS['http://waterwave.ch/weblog/324018']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/x-log_v202c']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'

URLS['http://waterwave.ch/weblog/detail.php']='https://blog.x-way.org'
URLS['http://waterwave.ch/weblog/detail.php?id=6']='https://blog.x-way.org/Webdesign/2002/06/06/Farbenlehre.html'
URLS['http://waterwave.ch/weblog/detail.php?id=10']='https://blog.x-way.org/Misc/2002/06/08/fffff.html'
URLS['http://waterwave.ch/weblog/detail.php?id=13']='https://blog.x-way.org/Misc/2002/06/11/Blogger_Code.html'
URLS['http://waterwave.ch/weblog/detail.php?id=111']='https://blog.x-way.org/Linux/2002/10/17/So_nebenbei.html'
URLS['http://waterwave.ch/weblog/detail.php?id=324018']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/detail.php?label=x-log_v202c']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'

URLS['http://waterwave.ch/weblog/2002/6']='https://blog.x-way.org/archive/archive-2002-06.html' # overlaps with archive URLs
URLS['http://waterwave.ch/weblog/2002/10']='https://blog.x-way.org/archive/archive-2002-10.html' # overlaps with archive URLs
URLS['http://waterwave.ch/weblog/2002/13']='https://blog.x-way.org/Misc/2002/06/11/Blogger_Code.html'
URLS['http://waterwave.ch/weblog/2002/111']='https://blog.x-way.org/Linux/2002/10/17/So_nebenbei.html'
URLS['http://waterwave.ch/weblog/2002/2002/13']='https://blog.x-way.org/Misc/2002/06/11/Blogger_Code.html'
URLS['http://waterwave.ch/weblog/2002/2002/111']='https://blog.x-way.org/Linux/2002/10/17/So_nebenbei.html'
URLS['http://waterwave.ch/weblog/2004/324018']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/2004/2004/324018']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/2004/x-log_v202c']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/2004/2004/x-log_v202c']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'

URLS['http://waterwave.ch/weblog/2002/06/6']='https://blog.x-way.org/archive/archive-2002-06.html' # overlaps with archive URLs
URLS['http://waterwave.ch/weblog/2002/06/10']='https://blog.x-way.org/archive/archive-2002-06.html' # overlaps with archive URLs
URLS['http://waterwave.ch/weblog/2002/06/13']='https://blog.x-way.org/archive/archive-2002-06.html' # overlaps with archive URLs
URLS['http://waterwave.ch/weblog/2002/10/111']='https://blog.x-way.org/Linux/2002/10/17/So_nebenbei.html'
URLS['http://waterwave.ch/weblog/2004/04/324018']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/2004/04/x-log_v202c']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'

URLS['http://waterwave.ch/weblog/2002/06/06/6']='https://blog.x-way.org/Webdesign/2002/06/06/Farbenlehre.html'
URLS['http://waterwave.ch/weblog/2002/06/08/10']='https://blog.x-way.org/Misc/2002/06/08/fffff.html'
URLS['http://waterwave.ch/weblog/2002/06/11/13']='https://blog.x-way.org/Misc/2002/06/11/Blogger_Code.html'
URLS['http://waterwave.ch/weblog/2002/10/17/111']='https://blog.x-way.org/Linux/2002/10/17/So_nebenbei.html'
URLS['http://waterwave.ch/weblog/2004/04/08/324018']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'
URLS['http://waterwave.ch/weblog/2004/04/08/x-log_v202c']='https://blog.x-way.org/Coding/2004/04/08/x-log_v202c.html'

URLS['http://waterwave.ch/weblog/archive.php']='https://blog.x-way.org/archive'
URLS['http://waterwave.ch/weblog/archiv.php']='https://blog.x-way.org/archive'
URLS['http://waterwave.ch/weblog/archive.php?year=2004']='https://blog.x-way.org/archive/archive-2004.html'
URLS['http://waterwave.ch/weblog/archiv.php?jahr=2004']='https://blog.x-way.org/archive/archive-2004.html'
URLS['http://waterwave.ch/weblog/archive.php?year=2004&month=08']='https://blog.x-way.org/archive/archive-2004-08.html'
URLS['http://waterwave.ch/weblog/archive.php?year=2004&month=8']='https://blog.x-way.org/archive/archive-2004-08.html'
URLS['http://waterwave.ch/weblog/archiv.php?jahr=2004&monat=08']='https://blog.x-way.org/archive/archive-2004-08.html'
URLS['http://waterwave.ch/weblog/archiv.php?jahr=2004&monat=8']='https://blog.x-way.org/archive/archive-2004-08.html'
URLS['http://waterwave.ch/weblog/2004']='https://blog.x-way.org/archive/archive-2004.html'
URLS['http://waterwave.ch/weblog/2004/2003/0/0/9876/1234/2003/1/2/2004']='https://blog.x-way.org/archive/archive-2004.html'
URLS['http://waterwave.ch/weblog/2004/4']='https://blog.x-way.org/archive/archive-2004-04.html'
URLS['http://waterwave.ch/weblog/2004/04']='https://blog.x-way.org/archive/archive-2004-04.html'
URLS['http://waterwave.ch/weblog/2002/10']='https://blog.x-way.org/archive/archive-2002-10.html'
URLS['http://waterwave.ch/weblog/2004/4/8']='https://blog.x-way.org/archive/archive-2004-04.html' # don't have per-day archives anymore
URLS['http://waterwave.ch/weblog/2004/04/08']='https://blog.x-way.org/archive/archive-2004-04.html' # don't have per-day archives anymore

URLS['http://waterwave.ch/weblog/index.php?cat=1']='https://blog.x-way.org/Misc'
URLS['http://waterwave.ch/weblog/index.php?cat=2']='https://blog.x-way.org/Webdesign'
URLS['http://waterwave.ch/weblog/index.php?cat=3']='https://blog.x-way.org/Coding'
URLS['http://waterwave.ch/weblog/index.php?cat=4']='https://blog.x-way.org/Tech'
URLS['http://waterwave.ch/weblog/index.php?cat=5']='https://blog.x-way.org/Networking'
URLS['http://waterwave.ch/weblog/index.php?cat=6']='https://blog.x-way.org/Linux'
URLS['http://waterwave.ch/weblog/index.php?cat=7']='https://blog.x-way.org/School'
URLS['http://waterwave.ch/weblog/index.php?cat=8']='https://blog.x-way.org/Mac'
URLS['http://waterwave.ch/weblog/index.php?cat=9']='https://blog.x-way.org/NetBSD'
URLS['http://waterwave.ch/weblog/index.php?cat=10']='https://blog.x-way.org/Music'
URLS['http://waterwave.ch/weblog/index.php?cat=11']='https://blog.x-way.org/Cinema'
URLS['http://waterwave.ch/weblog/index.php']='https://blog.x-way.org'

# old PHP files, currently handled by the catch-all redirect (and then redirected to the main page by the catch-all on blog.x-way.org side)
URLS['http://waterwave.ch/weblog/addcomment.php']='https://blog.x-way.org/addcomment.php'
URLS['http://waterwave.ch/weblog/checkLabel.php']='https://blog.x-way.org/checkLabel.php'
URLS['http://waterwave.ch/weblog/commenterror.php']='https://blog.x-way.org/commenterror.php'
URLS['http://waterwave.ch/weblog/commentpreview.php']='https://blog.x-way.org/commentpreview.php'
URLS['http://waterwave.ch/weblog/config.php']='https://blog.x-way.org/config.php'
URLS['http://waterwave.ch/weblog/genLabels.php']='https://blog.x-way.org/genLabels.php'
URLS['http://waterwave.ch/weblog/genRss.php']='https://blog.x-way.org/genRss.php'
URLS['http://waterwave.ch/weblog/infosender.php']='https://blog.x-way.org/infosender.php'
URLS['http://waterwave.ch/weblog/lastmodified.php']='https://blog.x-way.org/lastmodified.php'
URLS['http://waterwave.ch/weblog/links.php']='https://blog.x-way.org/links.php'
URLS['http://waterwave.ch/weblog/navigation.php']='https://blog.x-way.org/navigation.php'
URLS['http://waterwave.ch/weblog/ping.php']='https://blog.x-way.org/ping.php'
URLS['http://waterwave.ch/weblog/playlist.php']='https://blog.x-way.org/playlist.php'
URLS['http://waterwave.ch/weblog/set.php']='https://blog.x-way.org/set.php'
URLS['http://waterwave.ch/weblog/settings.php']='https://blog.x-way.org/settings.php'
URLS['http://waterwave.ch/weblog/statistics.php']='https://blog.x-way.org/statistics.php'
# URLS['http://waterwave.ch/weblog/trackback.php']='https://blog.x-way.org/trackback.php' # returns a 410 Gone
URLS['http://waterwave.ch/weblog/xml-rpc.php']='https://blog.x-way.org/xml-rpc.php'

URLS['http://waterwave.ch/weblog/2004/css/trash.css']='https://blog.x-way.org/css/trash.css'
URLS['http://waterwave.ch/weblog/2004/10/css/trash.css']='https://blog.x-way.org/css/trash.css'
URLS['http://waterwave.ch/weblog/2004/10/11/css/trash.css']='https://blog.x-way.org/css/trash.css'

RED="\e[31m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"

for url in "${!URLS[@]}" ; do
	expected="${URLS[$url]}"
	res=$(curl -s -o /dev/null -v "$url" 2>&1|grep -E -i -o '< location: \S*'|awk '{print $3}')
	if [ "$res" == "$expected" ] ; then
		echo -e " [ ${GREEN}OK${ENDCOLOR} ] URL $url -> ${res}"
	else
		echo -e " [${RED}FAIL${ENDCOLOR}] URL $url"
		echo -e "   -> ${RED}${res}${ENDCOLOR} (expected: $expected)"
	fi
done
