#!/bin/sh

server=localhost

set -e

PATH=/usr/sbin:$PATH
export PATH

at_exit() {
    echo "Info: Test exiting"
}

trap at_exit INT TERM EXIT

systemctl enable --now icecast2 2>/dev/null || \
    update-rc.d icecast2 enable && invoke-rc.d icecast2 start

echo "Info: Reporting daemon status"
if service icecast2 status ; then
    echo "Success: service reported success"
fi

if curl -s http://$server:8000/ | grep -q icecast.org ; then
    echo "Success: HTTP request to Icecast server worked."
else
    echo "Failure: HTTP request to Icecast server did not contain the words icecast.org."
    exit 1
fi
