#!/bin/sh

# todo: log all ocis services to stdout

echo "Waiting for EOS MGM"
echo "until nc -z -w 3 $EOS_MGM_ALIAS 1094; do sleep 2; done;" > /wait-for-mgm
chmod +x /wait-for-mgm
mkdir -p /var/log/ocis

(/wait-for-mgm; /setup > /var/log/ocis/setup.log; cat /var/log/ocis/setup.log ) &

echo "----- [ocis] DOMAIN setup -----"
echo "Domain / IP: $OCIS_DOMAIN"
mkdir -p /etc/ocis
sed -e "s|@IPADDR@|${OCIS_DOMAIN}|g" /config/identifier-registration.yml.tmpl > /etc/ocis/identifier-registration.yml

# TODO do we still need to precreate this folder?
mkdir -p /var/tmp/reva

echo "----- [ocis] Starting oCIS -----"
# todo start ocis as daemon not as root
ocis reva-storage-home &
ocis reva-storage-home-data &
ocis reva-storage-eos & 
ocis reva-storage-eos-data &
ocis reva-storage-public-link &
ocis micro &
ocis glauth &
ocis graph-explorer &
ocis graph &
ocis konnectd &
ocis phoenix &
ocis thumbnails &
ocis webdav &
ocis reva-auth-basic &
ocis reva-auth-bearer &
ocis reva-frontend &
ocis reva-gateway &
ocis reva-sharing &
ocis reva-users &
exec ocis proxy
