#!/bin/bash
set -e

../scripts/build-luan.sh

mkdir -p local
mkdir -p logs
rm -f logs/*
hg identify >logs/changeset.txt

if [ ! -f local/tiny_account.key ]; then
	echo "Register letsencrypt (tiny-acme)"
	openssl genrsa 4096 >local/tiny_account.key
fi

./gen_nginx.sh

# this is done because the nginx conf uses absolute paths
# and this breaks sites when the luan/host directory is moved
luan classpath:luan/host/update.luan

echo "(re)Starting..."
./restart.sh
