#Packager: George Vlahavas <vlahavas~at~gmail~dot~com>
#
# This just repackages the rstudio binaries for Fedora/RedHat.
# arch should be set to either i686 or x86_64

pkgname=rstudio-desktop
pkgver=0.99.893
pkgrel=1gv
source=("https://download1.rstudio.org/rstudio-$pkgver-$arch-fedora.tar.gz" "rstudio.desktop" "rstudio.xml" "application-x-r-data.png" "application-x-r-project.png"
		"https://github.com/rstudio/rstudio/archive/v${pkgver}.tar.gz")
docs=("readme.md" "install" "copying" "notice" "news.md" "contributing.md")
url=http://rstudio.com/

doinst() {
	if [ -x /usr/bin/update-mime-database ]; then
		/usr/bin/update-mime-database usr/share/mime >/dev/null 2>&1
	fi
	if [ -x /usr/bin/update-desktop-database ]; then
		/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
	fi
}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"rstudio (R Statistical IDE)"
"RStudio is an integrated development environment (IDE) for R. It"
"includes a console, syntax-highlighting editor that supports direct"
"code execution, as well as tools for plotting, history, debugging and"
"workspace management."
)


build() {
	cd $startdir/src/rstudio-$pkgver
	
	# Unfortunately the included pandoc static binaries hang. We'll
	# remove them and have an external pandoc package as a dependency.
	rm -rf bin/pandoc

	mkdir -p $startdir/pkg/usr/lib${LIBDIRSUFFIX}/rstudio
	cp -r ./* $startdir/pkg/usr/lib${LIBDIRSUFFIX}/rstudio/

	mkdir -p $startdir/pkg/usr/share/mime/packages
	cp $startdir/src/rstudio.xml $startdir/pkg/usr/share/mime/packages/

	mkdir -p $startdir/pkg/usr/share/icons/hicolor/48x48/apps
	cp rstudio.png $startdir/pkg/usr/share/icons/hicolor/48x48/apps/

	mkdir -p $startdir/pkg/usr/share/icons/hicolor/48x48/mimetypes
	cp $startdir/src/application-x-r-{data,project}.png $startdir/pkg/usr/share/icons/hicolor/48x48/mimetypes/

	mkdir -p $startdir/pkg/usr/share/applications
	cp $startdir/src/rstudio.desktop $startdir/pkg/usr/share/applications/

	mkdir -p $startdir/pkg/usr/bin
	(
	cd $startdir/pkg/usr/bin
	ln -sf ../lib${LIBDIRSUFFIX}/rstudio/bin/rstudio ./
	)
} 
