#!/bin/sh
#
# Copyright (c) 2018 Gregory L. Dietsche <Gregory.Dietsche@cuw.edu>
# This is free software, licensed under the MIT License
#
. /lib/functions.sh

update() {
  config_get_bool enabled $1 enabled 0
  config_get mode $1 mode default
  if [ ! -f /etc/safe-search/available/$1.$mode ]; then
    echo Error: /etc/safe-search/available/$1.$mode does not exist. Please check your configuration in /etc/config/safe-search
  else
    if [ "$enabled" -eq 1 ]; then
      ln -s /etc/safe-search/available/$1.$mode /etc/safe-search/enabled/
    fi
  fi
}

rm -f /etc/safe-search/enabled/*
config_load 'safe-search'
config_foreach update safe-search
/etc/init.d/dnsmasq reload
