#!/bin/bash

feed_dir="$HOME/tmp/hpr/rss"

wget https://hackerpublicradio.org/hpr_opus_rss.php -O "${feed_dir}/2_opus.xml"
wget https://hackerpublicradio.org/hpr_ogg_rss.php -O "${feed_dir}/2_ogg.xml"
wget https://hackerpublicradio.org/hpr_rss.php -O "${feed_dir}/2_mp3.xml"
wget https://hackerpublicradio.org/hpr_total_opus_rss.php -O "${feed_dir}/f_opus.xml"
wget https://hackerpublicradio.org/hpr_total_ogg_rss.php -O "${feed_dir}/f_ogg.xml"
wget https://hackerpublicradio.org/hpr_total_rss.php -O "${feed_dir}/f_mp3.xml"
wget https://hackerpublicradio.org/rss-future.php -O "${feed_dir}/ff.xml"
wget https://hackerpublicradio.org/comments.rss -O "${feed_dir}/comments.xml"

cd "${feed_dir}"

for feed in *.xml
do
  echo "Checking ${feed}"
  xmllint --format "${feed}" >/dev/null 2>&1
  if [ "${?}" -ne "0" ]
  then
    echo "Error: The rss feed \"${feed}\" is not correct"
    xmllint --format "${feed}"
    exit 1
  fi
done
