mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-18 05:34:20 +01:00
15
dnsmasq/Dockerfile
Normal file
15
dnsmasq/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM %%BASE_IMAGE%%
|
||||
|
||||
# Add env
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
# Setup base
|
||||
RUN apk add --no-cache tzdata jq dnsmasq
|
||||
|
||||
# Copy data
|
||||
COPY run.sh /
|
||||
COPY dnsmasq.conf /etc/
|
||||
|
||||
RUN chmod a+x /run.sh
|
||||
|
||||
CMD [ "/run.sh" ]
|
||||
33
dnsmasq/config.json
Normal file
33
dnsmasq/config.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "Dnsmasq server",
|
||||
"version": "0.1",
|
||||
"slug": "dnsmasq",
|
||||
"description": "A simple dns server with benefits",
|
||||
"url": "https://home-assistant.io/addons/dnsmasq/",
|
||||
"startup": "before",
|
||||
"boot": "auto",
|
||||
"ports": {
|
||||
"53/udp": 53
|
||||
},
|
||||
"options": {
|
||||
"defaults": ["8.8.8.8", "8.8.4.4"],
|
||||
"forwards": [],
|
||||
"hosts": []
|
||||
},
|
||||
"schema": {
|
||||
"defaults": ["str"],
|
||||
"forwards": [
|
||||
{
|
||||
"domain": "str",
|
||||
"server": "str"
|
||||
}
|
||||
],
|
||||
"hosts": [
|
||||
{
|
||||
"host": "str",
|
||||
"ip": "str"
|
||||
}
|
||||
]
|
||||
},
|
||||
"image": "homeassistant/{arch}-addon-dnsmasq"
|
||||
}
|
||||
6
dnsmasq/dnsmasq.conf
Normal file
6
dnsmasq/dnsmasq.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
no-resolv
|
||||
no-hosts
|
||||
keep-in-foreground
|
||||
log-queries
|
||||
log-facility=-
|
||||
no-poll
|
||||
32
dnsmasq/run.sh
Normal file
32
dnsmasq/run.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
CONFIG_PATH=/data/options.json
|
||||
|
||||
DEFAULTS=$(jq --raw-output '.domain' $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 ".forwards[$i].host" $CONFIG_PATH)
|
||||
IP=$(jq --raw-output ".forwards[$i].ip" $CONFIG_PATH)
|
||||
|
||||
echo "address=/$HOST/$IP" >> /etc/dnsmasq.conf
|
||||
done
|
||||
|
||||
# run dnsmasq
|
||||
exec dnsmasq -C /etc/dnsmasq.conf < /dev/null
|
||||
Reference in New Issue
Block a user