# Description: Lightweight web browser with news, e-mail and IRC.
# URL: http://www.opera.com/
# Maintainer: Danny Rawlins, monster dot romster at gmail dot com
# Packager: Olle Gustafsson, ogg at linux dot se
# Depends on: qt4

name=opera
version=12.01
release=1
source=(http://ftp.heanet.ie/pub/opera/linux/${version//./}/$name-$version-1532.i386.linux.tar.xz)

build() {
	cd $name-$version-*

	mv share/doc/opera/LICENSE $SRC/
	rm -rf share/doc/opera
	rm -rf share/opera/package

	# Replace PREFIX and SUFFIX in various files
	sed -i \
		-e "s:@@{PREFIX}:/usr:g" \
		-e "s:@@{SUFFIX}::g" \
		-e "s:@@{_SUFFIX}::g" \
		-e "s:@@{USUFFIX}::g" \
		share/mime/packages/opera-extension.xml \
		share/man/man1/* \
		share/applications/opera-browser.desktop

	# Recreate wrappers
	rm opera
	echo '#!/bin/bash' > opera
	echo 'export OPERA_DIR=/usr/share/opera' >> opera
	echo 'export OPERA_PERSONALDIR="${HOME}/.opera"' >> opera
	echo 'exec /usr/lib/opera/opera "$@"' >> opera

	install -m 0755 -D opera $PKG/usr/bin/opera

	# Install data
	install -d $PKG/usr/{lib,share}
	cp -r lib/opera $PKG/usr/lib/
	cp -r share/applications $PKG/usr/share/
	cp -r share/icons $PKG/usr/share/
	cp -r share/man $PKG/usr/man/
	cp -r share/mime $PKG/usr/share/
	cp -r share/opera $PKG/usr/share/

	# remove license.txt symlinks to doc directory
	# which we remove
	rm \
		$PKG/usr/lib/opera/plugins/README \
		$PKG/usr/share/opera/locale/en/license.txt \
		$PKG/usr/share/opera/defaults/license.txt

	cp $SRC/LICENSE \
                $PKG/usr/share/opera/defaults/license.txt

	ln $PKG/usr/share/opera/defaults/license.txt \
		$PKG/usr/share/opera/locale/en/license.txt

	find  "$PKG/usr/share/opera/locale/" \
		-mindepth 1 -maxdepth 1 -type d \
		-not -name en -exec rm -r {} +
}
