#!/bin/sh
#
# Legacy action script for "service unitd restoreconfig"

CONFIG=/etc/unit/config

if [ -n "$1" ] ; then
    CONFIG=$1
fi

if [ ! -e ${CONFIG} ]; then
    echo "Could not find ${CONFIG} for restoring" >&2
    exit 1
fi

echo "Restoring configuration from ${CONFIG}..."

curl -sS -X PUT -d @${CONFIG} --unix-socket /var/run/control.unit.sock localhost

if [ $? -ne 0 ]; then
    echo "Restoring failed!" >&2
    exit 1
fi

exit 0
