SHORT_DESC="Remote Control Application"
WEB_SITE="http://www.teamviewer.com/"
# end of get.list data
WGET_URL=${WEB_SITE}en/download/linux.aspx
DEPENDS="bash ncurses alsa-lib zlib xorg-libXext"

WGET_URL=$(wget --no-check-certificate -O - $WGET_URL | \
	   sed '/i386/!d;s/.*"\([^"]*i386[^"]*\).*/\1/;q')
TARBALL="$(basename $WGET_URL)"
wget --no-check-certificate -O $TARBALL $WGET_URL

[ -f $TARBALL ] || abort_package

mkdir $PACKAGE
dpkg-deb -e $TARBALL $PACKAGE/meta
dpkg-deb -x $TARBALL $PACKAGE/fs
find $PACKAGE/fs | grep /script/ | xargs sed -i 's|--append|-a|'

# extracted pkg can be removed: Save RAM
rm -f $TARBALL

sed '/^Description:/,$!d;s/^Description://' \
	< $PACKAGE/meta/control > $PACKAGE/description.txt

SHORT_DESC="$(sed '/^Description:/!d;s/.*: //' $PACKAGE/meta/control)"
MAINTAINER="$(sed '/^Maintainer:/!d;s/.*: //' $PACKAGE/meta/control)"
VERSION="$(sed '/^Version:/!d;s/.*: //' $PACKAGE/meta/control)"
mv $PACKAGE $PACKAGE-$VERSION

cd $PACKAGE-$VERSION/fs
[ -e usr/bin/$PACKAGE ] ||
ln -s $(cd usr/bin ; ls $PACKAGE* 2> /dev/null) \
	usr/bin/$PACKAGE 2> /dev/null || true
mkdir -p usr/share/applications
sed "s|EXEC|/usr/bin/$PACKAGE|g;s!ICON!/$(find opt | grep $PACKAGE.png)!g" \
	< $(find opt | grep -E '(desktop.template|\.desktop$)') \
	> usr/share/applications/$PACKAGE.desktop
sed -i 's/readlink -e/readlink $0 || echo /' \
	$(find opt -type f | grep /$PACKAGE$)
mkdir -p etc/init.d
ln -s /$(find opt | grep /teamviewerd$) etc/init.d/teamviewerd

# Web viewer (needs flash): https://go.teamviewer.com/v${VERSION%%.*}/
