From 5e30ec5c958a5d03a5a52322c92cf985d8bf652f Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Wed, 29 Aug 2018 15:24:41 +0300 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Makefile | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ plugin.cfg | 33 +++++++++++++++++++++++++++ postinstall.sh | 35 +++++++++++++++++++++++++++++ postrm.sh | 6 +++++ preinstall.sh | 3 +++ prerm.sh | 3 +++ 7 files changed, 142 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 plugin.cfg create mode 100644 postinstall.sh create mode 100644 postrm.sh create mode 100644 preinstall.sh create mode 100644 prerm.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..386bfa8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/*.deb +/go_* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7587d0f --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +NAME=adguard-internal-dns +VERSION=$(version) +MAINTAINER="AdGuard Web Team" +USER="dns" +SHELL := /bin/bash + +.PHONY: default +default: repo + +GOPATH=$(shell pwd)/go_$(VERSION) + +clean: + rm -fv *.deb + +## replace bit.adguard.com with github and remove ln -s once we push adguard-dns to github +build: check-vars clean + mkdir -p $(GOPATH) + GOPATH=$(GOPATH) go get -v -d -insecure bit.adguard.com/dns/adguard-dns + GOPATH=$(GOPATH) go get -v -d github.com/coredns/coredns + mkdir -p $(GOPATH)/src/github.com/AdguardTeam + ln -s $(GOPATH)/src/bit.adguard.com/dns/adguard-dns $(GOPATH)/src/github.com/AdguardTeam/AdguardDNS + cp plugin.cfg $(GOPATH)/src/github.com/coredns/coredns + cd $(GOPATH)/src/github.com/coredns/coredns; GOPATH=$(GOPATH) go generate + cd $(GOPATH)/src/github.com/coredns/coredns; GOPATH=$(GOPATH) go get -v -d -t . + cd $(GOPATH)/src/github.com/coredns/coredns; GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) make + cd $(GOPATH)/src/github.com/coredns/coredns; GOPATH=$(GOPATH) go build -x -v -ldflags="-X github.com/coredns/coredns/coremain.GitCommit=$(VERSION)" -o $(GOPATH)/bin/coredns + +package: build + fpm --prefix /opt/$(NAME) \ + --deb-user $(USER) \ + --after-install postinstall.sh \ + --after-remove postrm.sh \ + --before-install preinstall.sh \ + --before-remove prerm.sh \ + --template-scripts \ + --template-value user=$(USER) \ + --template-value project=$(NAME) \ + --template-value version=1.$(VERSION) \ + --license proprietary \ + --url https://adguard.com/adguard-dns/overview.html \ + --category non-free/web \ + --description "AdGuard DNS (internal)" \ + --deb-no-default-config-files \ + -v 1.$(VERSION) \ + -s dir \ + -t deb \ + -n $(NAME) \ + -m $(MAINTAINER) \ + --vendor $(MAINTAINER) \ + -C go_$(VERSION)/bin \ + coredns + +repo: package + for package in *.deb ; do freight-add $$package apt/jessie/non-free ; done + freight-cache + +check-vars: +ifndef version + $(error VERSION is undefined) +endif diff --git a/plugin.cfg b/plugin.cfg new file mode 100644 index 0000000..79ca114 --- /dev/null +++ b/plugin.cfg @@ -0,0 +1,33 @@ +# Directives are registered in the order they should be +# executed. +# +# Ordering is VERY important. Every plugin will +# feel the effects of all other plugin below +# (after) them during a request, but they must not +# care what plugin above them are doing. + +# How to rebuild with updated plugin configurations: +# Modify the list below and run `go gen && go build` + +# The parser takes the input format of +# : +# Or +# : +# +# External plugin example: +# log:github.com/coredns/coredns/plugin/log +# Local plugin example: +# log:log + +bind:bind +debug:debug +pprof:pprof +prometheus:metrics +errors:errors +log:log +ratelimit:github.com/AdguardTeam/AdguardDNS/coredns_plugin/ratelimit +refuseany:github.com/AdguardTeam/AdguardDNS/coredns_plugin/refuseany +dnsfilter:github.com/AdguardTeam/AdguardDNS/coredns_plugin +cache:cache +file:file +forward:forward diff --git a/postinstall.sh b/postinstall.sh new file mode 100644 index 0000000..aa5324a --- /dev/null +++ b/postinstall.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e -x -o pipefail +echo "executing $0" + +case "$1" in + configure) + if ! getent passwd "<%= user %>" > /dev/null ; then + echo "Adding user for <%= project %>" >&2 + + adduser --system -ingroup nogroup --quiet \ + --no-create-home \ + --disabled-login \ + --gecos "<%= project %> user" \ + --shell /bin/bash "<%= user %>" + fi + URL="https://filters.adtidy.org/android/filters/15.txt" + OUTFILE="/var/lib/dnsfilter/dns.txt" + + mkdir -p /var/lib/dnsfilter + wget -q --timeout=90 "$URL" -O "$OUTFILE" + if [ $? -ne 0 ] + then + echo "Filter rules could not be downloaded." + fi + + # Link logs dir (Required for request logs) + ln -s /var/log/<%= project %> /opt/<%= project %>/logs + + chown -R <%= user %>: /opt/<%= project %> + ;; + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac diff --git a/postrm.sh b/postrm.sh new file mode 100644 index 0000000..bd6cdfe --- /dev/null +++ b/postrm.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e -x -o pipefail +echo "executing $0" + +# Unlink logs dir +rm -rf /opt/<%= project %>/logs diff --git a/preinstall.sh b/preinstall.sh new file mode 100644 index 0000000..061ecaa --- /dev/null +++ b/preinstall.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -e -x -o pipefail +echo "executing $0" diff --git a/prerm.sh b/prerm.sh new file mode 100644 index 0000000..061ecaa --- /dev/null +++ b/prerm.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -e -x -o pipefail +echo "executing $0"