#!/usr/bin/sh
#----------------------------------------------------------------------------
# /tmp/install.sh - dnscrypt-proxy installation
#
# Creation   :  2025-01-29 holbru
# Last update:  $Id$
#
# Copyright (c) 2025-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------

# set package name
package_name=dnscrypt-proxy

# ---------------------------------------------------------------------------
# add menu
# ---------------------------------------------------------------------------
/var/install/bin/add-menu \
        --menu \
        "setup.services.menu" \
        "setup.services.${package_name}.menu" \
        "DNSCrypt-proxy Service"

# ---------------------------------------------------------------------------
# Create default config
# ---------------------------------------------------------------------------
cd /etc/dnscrypt-proxy

if [ ! -f dnscrypt-proxy.toml ]
then
    /usr/bin/cp dnscrypt-proxy.toml.default dnscrypt-proxy.toml
fi    

cd / 

/usr/bin/chown -R dnscrypt:dnscrypt /etc/dnscrypt-proxy 

# ---------------------------------------------------------------------------
# Create config
# ---------------------------------------------------------------------------
if [ -f /etc/config.d/${package_name} ]
then
    update=true
fi

/var/install/config.d/${package_name}-update.sh
/usr/bin/rm -f /var/install/config.d/${package_name}-update.sh

# ---------------------------------------------------------------------------
# start package with update
# ---------------------------------------------------------------------------
if ${update:-false}
then
    /var/install/config.d/${package_name}.sh
fi

exit 0
# ---------------------------------------------------------------------------
# end
# ---------------------------------------------------------------------------
