mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-18 13:44:20 +01:00
33 lines
887 B
Bash
33 lines
887 B
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
CONFIG_PATH=/data/options.json
|
|
|
|
DEFAULTS=$(jq --raw-output '.defaults[]' $CONFIG_PATH)
|
|
FORWARDS=$(jq --raw-output '.forwards | length' $CONFIG_PATH)
|
|
HOSTS=$(jq --raw-output '.hosts | length' $CONFIG_PATH)
|
|
|
|
# Add default forward servers
|
|
for line in $DEFAULTS; do
|
|
echo "server=$line" >> /etc/dnsmasq.conf
|
|
done
|
|
|
|
# Create domain forwards
|
|
for (( i=0; i < "$FORWARDS"; i++ )); do
|
|
DOMAIN=$(jq --raw-output ".forwards[$i].domain" $CONFIG_PATH)
|
|
SERVER=$(jq --raw-output ".forwards[$i].server" $CONFIG_PATH)
|
|
|
|
echo "server=/$DOMAIN/$SERVER" >> /etc/dnsmasq.conf
|
|
done
|
|
|
|
# Create static hosts
|
|
for (( i=0; i < "$HOSTS"; i++ )); do
|
|
HOST=$(jq --raw-output ".hosts[$i].host" $CONFIG_PATH)
|
|
IP=$(jq --raw-output ".hosts[$i].ip" $CONFIG_PATH)
|
|
|
|
echo "address=/$HOST/$IP" >> /etc/dnsmasq.conf
|
|
done
|
|
|
|
# run dnsmasq
|
|
exec dnsmasq -C /etc/dnsmasq.conf -z < /dev/null
|