#!/usr/bin/env bash

. /usr/share/dosis2/bin/shell-support-functions

systemtype="$1"
siteserverip="`/opt/dosis2/etc/personality/common-scripts/siteserver-ip-from-config`"

if [ "${systemtype}" = "site-server" ] || [ "${systemtype}" = "standalone" ]; then
    apply_do_backup="""
    update equipment.dafe_settings
        set value = 'TRUE'
    where dafe_id = (select id from equipment.dafe where tag = 'SYSTEM')
        and setting_type_id = (
            select id from equipment.dafe_setting_types
                where tag = 'DO_BACKUP_FROM_DAFE')
    """
    echo "Enabling DO_BACKUP_FROM_DAFE"
    if [ "${siteserverip}" = "" ]; then
        psql -U dpg -d dosis2 -c "${apply_do_backup}"
    else
        psql -U dpg -d dosis2 -h "${siteserverip}" -c "${apply_do_backup}"
    fi
fi
