#!/bin/sh

set -eu

# Create folders for storing certs and agent token, they should be available
# to owner ie. stork-agent user.
home_dir=/var/lib/stork-agent
mkdir -p "${home_dir}/certs"
mkdir -p "${home_dir}/tokens"
chmod 700 "${home_dir}/certs"
chmod 700 "${home_dir}/tokens"

pw group add stork-agent || /bin/true
pw user add -n stork-agent -c "Stork Agent User" -g stork-agent -G bind -G _kea || /bin/true

# Change ownership of all folders and files in home dir to stork-agent user.
chown -R stork-agent "${home_dir}"
