#!/bin/sh -e

GENDIR=/run/systemd/generator

# if the generator ran successfully, nothing to do here
if [ -f $GENDIR/entangle.stamp ]; then
    exit 0
fi

# wait until we have a hostname (timeout is handled by unit file)
while [ `hostname` = localhost ]; do
    sleep 0.2
done

# rerun the generator (happens automatically on daemon-reload)
systemctl daemon-reload

# if it was successful, start the newly created units
if [ -f $GENDIR/entangle.stamp ]; then
    systemctl start entangle.target
fi
