#!/bin/bash

# Disable ssl
coolconfig set ssl.enable  false
coolconfig set ssl.termination  true
coolconfig set net.listen loopback
coolconfig set net.proto IPv4


#Generate a list of hosts that can access to the wopi storage
#Server FQDN
AllowWopiHosts=`hostname`

#Nextcloud virtualhost
if [[ -n `/sbin/e-smith/config getprop nextcloud VirtualHost` ]];then AllowWopiHosts+="|`/sbin/e-smith/config getprop nextcloud VirtualHost`";fi
if [[ -n `/sbin/e-smith/config getprop nextcloud CloudDomain` ]];then AllowWopiHosts+="|`/sbin/e-smith/config getprop nextcloud CloudDomain`";fi

#Additional external host
if [[ -n `/sbin/e-smith/config getprop coolwsd AllowWopiHost` ]];then AllowWopiHosts+="|`/sbin/e-smith/config getprop coolwsd AllowWopiHost |sed -e 's/,/|/g' `";fi

coolconfig set storage.wopi.host "$AllowWopiHosts"


if [[ -n `/sbin/e-smith/config getprop coolwsd VirtualHost` ]]; then

  #Configure smeserver-Nextcloud
  if [[ -x "/usr/bin/occ" ]]; then

    /usr/bin/occ app:install richdocuments

    /usr/bin/occ config:app:set richdocuments wopi_url --value=https://`/sbin/e-smith/config getprop coolwsd VirtualHost`

    /usr/bin/occ app:enable richdocuments

    /usr/bin/occ config:system:set allow_local_remote_servers --value true --type bool
  fi

fi
