#!/bin/sh

# WARNING: this wrapper is only for setting up screen environment variables
# that would need to be shared between a greeter process and the user session.
# Do NOT add any other hacks here.  We eventually intend for this wrapper to
# go away, once we dynamically determine screen settings.

export QT_QPA_PLATFORM=ubuntumirclient

# defaults
GRID_UNIT_PX=18
QTWEBKIT_DPR=2.0
NATIVE_ORIENTATION=portrait

# override defaults by sourcing /etc/ubuntu-touch-session.d/$device.conf
device=$(getprop ro.product.device)
[ -e /etc/ubuntu-touch-session.d/$device.conf ] && . /etc/ubuntu-touch-session.d/$device.conf

export GRID_UNIT_PX=${GRID_UNIT_PX}
export QTWEBKIT_DPR=${QTWEBKIT_DPR}
export NATIVE_ORIENTATION=${NATIVE_ORIENTATION}

# Save in bashrc so that adb picks them up (for autopilot's benefit)
dot_profile=$HOME/.profile
grep -q GRID_UNIT_PX $dot_profile || echo "export GRID_UNIT_PX=${GRID_UNIT_PX}" >> $dot_profile
grep -q QTWEBKIT_DPR $dot_profile || echo "export QTWEBKIT_DPR=${QTWEBKIT_DPR}" >> $dot_profile
grep -q NATIVE_ORIENTATION $dot_profile || echo "export NATIVE_ORIENTATION=${NATIVE_ORIENTATION}" >> $dot_profile

if [ "$#" -ne 0 ]; then
    exec $@
else
    exec init --user
fi
