#!/bin/sh

# postflight script for R 
cd /usr/bin

if uname -r | grep -E '^(1[5-9]|[2-9])' >/dev/null; then
    ## 15.0 and higher don't allow messing with /usr/bin
    ## so use /usr/local/bin instead
    if [ ! -e /usr/local/bin ]; then
	mkdir -p /usr/local/bin
    fi
    cd /usr/local/bin
fi

# create convenience links to R and Rscript
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .

# update font cache (if this R includes fontconfig)
if [ -e /Library/Frameworks/R.framework/Resources/bin/fc-cache ]; then
    /Library/Frameworks/R.framework/Resources/bin/fc-cache
fi
# make sure the framework is admin-writable
chown -Rh root:admin /Library/Frameworks/R.framework
chmod -R g+w /Library/Frameworks/R.framework