#!/bin/sh
# $OpenBSD: chrome,v 1.3 2011/02/08 21:10:28 sthen Exp $

PROGDIR=TRUEPREFIX/chrome
SHMALL=32768
DATASIZ=716800
FDS=400

if [ `/usr/sbin/sysctl -n kern.shminfo.shmall` -lt ${SHMALL} ]; then
	MSG="You should increase the kern.shminfo.shmall sysctl to at least ${SHMALL},"
	MSG="${MSG}\ne.g.: sysctl kern.shminfo.shmall=${SHMALL}. This can be added to /etc/sysctl.conf.\n"
fi

[ `ulimit -Sd` -lt ${DATASIZ} ] || ulimit -Sd ${DATASIZ}
if [ `ulimit -Sd` -lt ${DATASIZ} ]; then
	LMSG="- increase datasize-max to at least ${DATASIZ}.\n"
fi

[ `ulimit -Sn` -lt ${FDS} ] || ulimit -Sn ${FDS}
if [ `ulimit -Sn` -lt ${FDS} ]; then
	LMSG="${LMSG}- increase openfiles-max to at least ${FDS}.\n"
fi

if [ ! -z "${LMSG}" ]; then
	[ -f /etc/login.conf.db ] && LOGINDB=" and rebuild login.conf.db"
	MSG="${MSG}\nYou should make the following changes for your login class in /etc/login.conf${LOGINDB}\n"
	MSG="${MSG}(you will need to logout and login for these to take effect).\n${LMSG}"
fi

if [ ! -z "${MSG}" ]; then
	MSG="${MSG}\nDo you want to run Chromium anyway?"
	MSG="${MSG}\n(If you don't increase these limits, Chromium might fail to work properly.)"

	answer=`echo ${MSG} | /usr/X11R6/bin/xmessage -center -buttons yes,no -print -file -`

	if [ X"${answer}" = X"no" ]; then
		exit 0
	fi
fi

exec "${PROGDIR}/chrome" "$@"
