#!/bin/bash
#
# Install all dependencies for get_iplayer on Debian or Ubuntu,
# and probably other upstream Debian derivatives.
#
# All those packages suffixed with '-perl' in the list are
# Perl packages.
#
# libav-tools contains the ffmpeg converter.
#
# get_iplayer is at:
#
#  https://github.com/get-iplayer/get_iplayer
#


(( EUID == 0 )) || {
    echo "Must be run as root, try: sudo $0"
    exit 1
}

apt-get -yq update

apt-get -yq install libjson-pp-perl libwww-perl \
    libhtml-parser-perl libhtml-html5-entities-perl \
    zlib1g-dev libhttp-date-perl libxml2-dev \
    libxml-libxml-perl libmojolicious-perl


echo "Checking to see if we have all the needed Perl dependencies..."
for MOD in JSON::PP LWP LWP::Protocol::https Mojolicious XML::LibXML
do
	echo "Have we got ${MOD}?..."
	perl -e "use ${MOD};" &> /dev/null
	if [ $? != 0 ]; then
		echo "${MOD} is not installed"
	else
		echo "${MOD} is installed"
	fi
done

exit 0

