# Chown definitions created by SBT Native Packager

# Generate secret key
if ! test -e /etc/thehive/secret.conf; then
  key=$(dd if=/dev/urandom bs=1024 count=1 | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)
  echo "play.http.secret.key=\"$key\"" > /etc/thehive/secret.conf
fi

chown root:thehive /etc/thehive/application.conf /etc/thehive/logback.xml /etc/thehive/secret.conf
chmod 0640 /etc/thehive/application.conf /etc/thehive/logback.xml /etc/thehive/secret.conf
if test -x /bin/systemctl; then
 	/bin/systemctl daemon-reload || /bin/true
 fi

mkdir -p /var/log/thehive /opt/thp/thehive/index /opt/thp/thehive/database /opt/thp/thehive/files
touch /var/log/thehive/application.log
chown -R thehive:thehive /var/log/thehive /opt/thp/thehive/index /opt/thp/thehive/database /opt/thp/thehive/files

