#!/bin/bash

# Configure hook for Livepatch Server
#
# For more information on snap hooks, see:
# https://snapcraft.io/docs/supported-snap-hooks

. "$SNAP/scripts/manage_config.sh"

# parse_config:
# As a lot of logic can be done conditionally,
# we aren't using the install hook. The benefit of this
# is it enables users to manually control resets
# of default configurations, directories, etc.
parse_config() {
    DEFAULTS_SET=$(snapctl get defaults.set)
    
    if [ "$DEFAULTS_SET" != "true" ] ; then
        echo 'Setting default configuration...'
        set_defaults
    fi
    echo 'Updating candid configuration...'
    dump_new_config
    

    snapctl restart candid.candidsrv
    sleep 3
}

parse_config

