#!/bin/bash

set -e

# Start the service
service inetsim start

# Wait for the HTTP server to be up
max_date=$(date +%s -d "now + 1 minute")
while true; do
    curl -s --head localhost:80 >/dev/null && break
    if [ $(date +%s) -ge $max_date ]; then
        echo "Timeout waiting for HTTP server!" >&2
        exit 1
    fi
    sleep 5
done

# Validate HTTP server response
diff -u <(curl -sS localhost:80) /usr/share/inetsim/data/http/fakefiles/sample.html
