#!/usr/bin/env bashio
declare hostname
bashio::require.unprotected

SETTINGS_CONF=/variables.sh
touch ${SETTINGS_CONF}

SOCKET_PATH=$(bashio::config 'socket_path')
bashio::log.info "Setting socket path: ${SOCKET_PATH}"
echo "export SOCKET_PATH=${SOCKET_PATH}" >> ${SETTINGS_CONF}

if bashio::config.true 'events'; then
  bashio::log.info "Enabling events"
  echo "export ENABLE_EVENTS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling events"
  echo "export ENABLE_EVENTS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'ping'; then
  bashio::log.info "Enabling ping"
  echo "export ENABLE_PING=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling ping"
  echo "export ENABLE_PING=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'version'; then
  bashio::log.info "Enabling version"
  echo "export ENABLE_VERSION=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling version"
  echo "export ENABLE_VERSION=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'build'; then
  bashio::log.info "Enabling build"
  echo "export ENABLE_BUILD=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling build"
  echo "export ENABLE_BUILD=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'commit'; then
  bashio::log.info "Enabling commit"
  echo "export ENABLE_COMMIT=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling commit"
  echo "export ENABLE_COMMIT=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'configs'; then
  bashio::log.info "Enabling configs"
  echo "export ENABLE_CONFIGS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling configs"
  echo "export ENABLE_CONFIGS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'containers'; then
  bashio::log.info "Enabling containers"
  echo "export ENABLE_CONTAINERS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling containers"
  echo "export ENABLE_CONTAINERS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'allow_restarts'; then
  bashio::log.info "Enabling allow_restarts"
  echo "export ENABLE_ALLOW_RESTARTS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling allow_restarts"
  echo "export ENABLE_ALLOW_RESTARTS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'distribution'; then
  bashio::log.info "Enabling distribution"
  echo "export ENABLE_DISTRIBUTION=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling distribution"
  echo "export ENABLE_DISTRIBUTION=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'exec'; then
  bashio::log.info "Enabling exec"
  echo "export ENABLE_EXEC=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling exec"
  echo "export ENABLE_EXEC=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'grpc'; then
  bashio::log.info "Enabling grpc"
  echo "export ENABLE_GRPC=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling grpc"
  echo "export ENABLE_GRPC=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'images'; then
  bashio::log.info "Enabling images"
  echo "export ENABLE_IMAGES=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling images"
  echo "export ENABLE_IMAGES=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'info'; then
  bashio::log.info "Enabling info"
  echo "export ENABLE_INFO=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling info"
  echo "export ENABLE_INFO=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'networks'; then
  bashio::log.info "Enabling networks"
  echo "export ENABLE_NETWORKS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling networks"
  echo "export ENABLE_NETWORKS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'node'; then
  bashio::log.info "Enabling node"
  echo "export ENABLE_NODE=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling node"
  echo "export ENABLE_NODE=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'plugins'; then
  bashio::log.info "Enabling plugins"
  echo "export ENABLE_PLUGINS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling plugins"
  echo "export ENABLE_PLUGINS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'services'; then
  bashio::log.info "Enabling services"
  echo "export ENABLE_SERVICES=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling services"
  echo "export ENABLE_SERVICES=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'session'; then
  bashio::log.info "Enabling session"
  echo "export ENABLE_SESSION=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling session"
  echo "export ENABLE_SESSION=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'swarm'; then
  bashio::log.info "Enabling swarm"
  echo "export ENABLE_SWARM=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling swarm"
  echo "export ENABLE_SWARM=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'system'; then
  bashio::log.info "Enabling system"
  echo "export ENABLE_SYSTEM=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling system"
  echo "export ENABLE_SYSTEM=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'tasks'; then
  bashio::log.info "Enabling tasks"
  echo "export ENABLE_TASKS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling tasks"
  echo "export ENABLE_TASKS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'volumes'; then
  bashio::log.info "Enabling volumes"
  echo "export ENABLE_VOLUMES=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling volumes"
  echo "export ENABLE_VOLUMES=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'auth'; then
  bashio::log.info "Enabling auth"
  echo "export ENABLE_AUTH=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling auth"
  echo "export ENABLE_AUTH=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'secrets'; then
  bashio::log.info "Enabling secrets"
  echo "export ENABLE_SECRETS=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling secrets"
  echo "export ENABLE_SECRETS=0" >> ${SETTINGS_CONF}
fi

if bashio::config.true 'post'; then
  bashio::log.info "Enabling post"
  echo "export ENABLE_POST=1" >> ${SETTINGS_CONF}
else
  bashio::log.info "Disabling post"
  echo "export ENABLE_POST=0" >> ${SETTINGS_CONF}
fi

bashio::log.info "Finished settings config, Starting docker-socker-proxy"
