#!/bin/sh

set -eux

mkdir -p /var/run
export SWANCTL_DIR=/etc/swanctl

# The charon binary is not included in the PATH generated by writeShellCommand, find it manually.
charon="$(dirname "$(readlink -f "$(command -v charon-systemd)")")/../libexec/ipsec/charon"

"${charon}" &

while ! swanctl --stats > /dev/null 2> /dev/null; do
  sleep 1
done
swanctl --load-all

wait