#!/bin/sh
#
# $OpenBSD: pycharm,v 1.1.1.1 2018/03/16 14:07:12 danj Exp $
#
# OpenBSD-specific startup script for PyCharm IDE

PYCHARM_HOME=/usr/local/pycharm
DATASIZE="2048000"
[[ `arch -s` == i386 ]] && DATASIZE="1536000"

#-----------------------------------------------------------------------------
# Determine configuration settings
#-----------------------------------------------------------------------------

export PYCHARM_JDK=/usr/local/jdk-1.8.0

if [ ! -x "${PYCHARM_JDK}/bin/java" ]; then
	echo "Error: JAVA_HOME may not be defined correctly: ${PYCHARM_JDK}"
	echo "       Unable to find Java binary ${PYCHARM_JDK}/bin/java"
        exit 1
fi

# Check if 'pycharm' executable can be found
if [ ! -x "${PYCHARM_HOME}/bin/pycharm.sh" ]; then
	echo "Error: PYCHARM_HOME may not be defined correctly: ${PYCHARM_HOME}"
	echo -n "       Unable to find launcher binary: "
	echo "${PYCHARM_HOME}/bin/pycharm.sh"
	exit 1
fi

xm_log() {
	echo -n "$@\nDo you want to run PyCharm anyway?\n\
(If you don't increase these limits, PyCharm might fail to work properly.)" | \
		/usr/X11R6/bin/xmessage -file - -center -buttons yes:0,no:1 -default no
}

if [ $(ulimit -Sd) -lt ${DATASIZE} ]; then
	ulimit -Sd ${DATASIZE} || \
		xm_log "Cannot increase datasize-cur to at least ${DATASIZE}"
		[ $? -eq 0 ] || exit
fi

PATH=${PYCHARM_JDK}/bin:$PATH exec "${PYCHARM_HOME}/bin/pycharm.sh" $@
