#!/usr/bin/bash

PORT=2002
export TMPDIR=/home/$USER/tmp
[[ -d $TMPDIR ]] || TMPDIR=/tmp
cd "$TMPDIR"

if [[ "$1" = "--desc" ]] ; then
    echo "Start the LibreOffice UNO server"
    exit 0
fi

# export DISPLAY=localhost:10.0
bin=$(which libreoffice 2>/dev/null)
if [[ -d /opt/libreoffice/program ]] ; then
    bin=/opt/libreoffice/program/soffice
elif [[ -d /opt/libreoffice26.2/program ]] ; then
    bin=/opt/libreoffice26.2/program/soffice
elif [[ ! $bin ]] ; then
    bin=libreoffice
fi

exec "$bin" "--accept=socket,host=localhost,port=$PORT;urp;StarOffice.Service" --nologo --headless --nofirststartwizard
