#!/usr/bin/env bash

# rsync-freevo
#
#   <dmeyer@tzi.de>
# $Id: rsync-freevo 5743 2004-06-11 09:20:13Z dischi $


VERSION=3.0


. /etc/make.conf

file=freevo-ebuild.tgz

if [ "$PORTDIR_OVERLAY" = "" ]; then
    echo please define a PORTDIR_OVERLAY in /etc/make.conf
    echo and make sure you have the permission to write in it
    exit 1
fi

if ! [ -w "$PORTDIR_OVERLAY" ]; then
    echo unable to write to $PORTDIR_OVERLAY: permission denied
    exit 1
fi

cd /tmp
rm rsync-ChangeLog $file 2>/dev/null
echo downloading version information
wget -q http://freevo.sourceforge.net/gentoo/ChangeLog -O rsync-ChangeLog

if [ '!' -e rsync-ChangeLog ]; then
    echo download failed
    exit 1
fi

if ! head -n 1 rsync-ChangeLog | grep "$VERSION" >/dev/null; then
    cat rsync-ChangeLog
    echo
    echo please download a new version of rsync-freevo from
    echo http://freevo.sourceforge.net/gentoo/
    rm rsync-ChangeLog
    exit 1
fi

echo downloading ebuilds
wget -q http://freevo.sourceforge.net/gentoo/$file

if [ '!' -e $file ]; then
    echo download failed
    rm rsync-ChangeLog
    exit 1
fi

cd $PORTDIR_OVERLAY

rm -rf app-misc/freevo_runtime app-misc/freevo_snapshot \
    media-video/freevo_runtime media-video/freevo_snapshot media-video/freevo \
    media-video/freevo-snapshot dev-python/mmpython dev-python/mmpython-snapshot \
    dev-python/pylirc media-tv/freevo-snapshots media-tv/freevo

echo unpack ebuilds
tar -zxvf /tmp/$file  2>&1 | grep ebuild
rm /tmp/$file /tmp/rsync-ChangeLog

if ! grep pylirc /etc/portage/package.keywords 2>/dev/null >/dev/null; then
    echo
    echo "Warning: pylirc is masked"
    echo "To install freevo without any problems, you need to add"
    echo "dev-python/pylirc ~x86"
    echo "into /etc/portage/package.keywords"
    echo
fi

# echo
# echo
# echo
# echo "WARNING: Freevo is now in the gentoo portage tree, you don't need this script"
# echo "anymore. It does the following things:"
# echo "1. add stuff to use Freevo with the DXR3 (USE dxr3)"
# echo "2. add ebuilds for freevo-snapshot and mmpython-snapshot"
# echo "3. remove the mask from all packages Freevo needs"
# echo "4. add ebuilds for new version which are not in the portage tree (yet)"
# echo
# echo "And a small change: freevo is now in media-tv, not media-video"
# echo

# end of rsync-freevo
