#!/bin/sh

( useradd -r psrt -s /usr/sbin/nologin -d / || exit 0 )
for f in config.yml acl.yml; do
  if [ ! -f /etc/psrtd/$f ]; then
    cp -prvf /etc/psrtd/$f-dist /etc/psrtd/$f
  fi
done
touch /etc/psrtd/psrt-passwd
chmod 600 /etc/psrtd/psrt-passwd
chown psrt /etc/psrtd/psrt-passwd
systemctl enable psrtd
if [ "$1" = "configure" ] && [ -z "$2" ]; then
cat << EOF
Service psrtd enabled

To start the server, execute

  systemctl start psrtd
EOF
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
  systemctl restart psrtd
fi
