#!/bin/sh
TERM_APP=$(ls /accounts/1000/appdata | grep Term)

if [ -z "$TERM_APP" ]; then
  echo "No Term app found in /accounts/1000/appdata"
  exit 1
fi

if [ ! -z $PROFILE_LOADED ]; then
  exit 0
fi

TERM_DATA_PATH="/accounts/1000/appdata/${TERM_APP}/data"
PROFILE_CONTENT="'
export PYTHONHOME=/usr:/usr
export LOGDIR=/var/log
export TMPDIR=/var/tmp
export HOME=/var
export PERSISTENCE_DATA="/"
export PPSDIR=/var/pps
export LOCFILE=/usr/share/locale/locale.file
export uname_m=`uname -m`
export STDIO_DEFAULT_BUFSIZE=8192

# Setup Qt environment
QTDIR=/usr/lib/qt4
export QT_LIB_PATH=${QTDIR}/lib
export QT_PLUGIN_PATH=${QTDIR}/plugins
export QML_IMPORT_PATH=${QTDIR}/imports

LD_LIBRARY_PATH="/usr/lib:/lib:/lib/dll:${QT_LIB_PATH}"
export LD_LIBRARY_PATH
PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/photon/bin:/scripts:/accounts/devuser:/accounts/1000/shared/.installer"
export PATH
export LIBIMG_CFGFILE=/etc/system/config/img.conf
export FLASH_FONT_CFG_PATH=/etc/system/config/flash-font.cfg
export FONTCONFIG_FILE=/etc/fontconfig/fonts.conf
export PHKSCOPE=1
export FLASHTMP=/tmp
export PHFONT=/dev/phfont
export PHOTON=/dev/photon
export TERM=xterm
export PROFILE_LOADED=1

if [ -e /q ]; then
/accounts/1000/shared/.installer/run.sh --silent --startup &
fi
'"
echo "echo ${PROFILE_CONTENT} > ${TERM_DATA_PATH}/.profile" | /q/__apps > /dev/null 2>&1