From 5e60794b428035db69899f229befac504d6dc043 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sun, 17 Nov 2024 04:01:08 +0000 Subject: [PATCH] refactor to use any unknown prefix --- Dockerfile | 4 ++-- Makefile | 10 ++++++---- bin/inet2.sh | 10 +++++----- bin/mkbirdconfig.sh | 2 +- bin/mkwgconfig.sh | 4 ++-- deployments/initd/inet2.initd | 8 +++++--- deployments/openrc/inet2.initd | 8 +++++--- {lib => share}/config.awk | 0 {lib => share}/inet2.sh | 2 +- 9 files changed, 27 insertions(+), 21 deletions(-) rename {lib => share}/config.awk (100%) rename {lib => share}/inet2.sh (82%) diff --git a/Dockerfile b/Dockerfile index b145165..0d57fb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM alpine RUN apk add --no-cache openrc udev-init-scripts-openrc wireguard-tools bind-tools bird -RUN mkdir -p /var/lib/inet2 +RUN mkdir -p /var/share/inet2 COPY ./bin /usr/local/bin -COPY ./lib /var/lib/inet2 +COPY ./share /usr/local/share/inet2 COPY ./deployments/openrc/inet2.initd /etc/init.d/inet2 COPY ./deployments/docker/wait.initd /etc/init.d/wait RUN sed -i 's/#rc_sys=""/rc_sys="docker"/' /etc/rc.conf && \ diff --git a/Makefile b/Makefile index 1582c1e..2aac3ba 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ .PHONY: install alpine openwrt +PREFIX=/usr/local + install: - mkdir -p /usr/local/bin - mkdir -p /var/lib/inet2 - cp ./bin/* /usr/local/bin - cp ./lib/* /var/lib/inet2 + mkdir -p ${PREFIX}/bin + mkdir -p ${PREFIX}/share/inet2 + cp ./bin/* ${PREFIX}/bin + cp ./share/* ${PREFIX}/share/inet2 alpine: apk add --no-cache wireguard-tools bind-tools bird diff --git a/bin/inet2.sh b/bin/inet2.sh index cb98c6c..00f1168 100755 --- a/bin/inet2.sh +++ b/bin/inet2.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env sh +#!/bin/sh -. /var/lib/inet2/inet2.sh +. ${INET2_PREFIX}/share/inet2/inet2.sh runscripts() { if [ -n "$(getval "interface $2" "$1")" ]; then @@ -26,7 +26,7 @@ start() { rm -fr /run/inet2/wg 2> /dev/null mkdir -p /run/inet2/wg - /usr/local/bin/mkbirdconfig.sh + ${INET2_PREFIX}/bin/mkbirdconfig.sh step "Setting loopback addresses" getval Loopback | while read -r addr; do @@ -35,7 +35,7 @@ start() { getval interface | while read -r inter; do step "Generating config for $inter" - run /usr/local/bin/mkwgconfig.sh "$inter" /run/inet2/wg/"$inter" + run ${INET2_PREFIX}/bin/mkwgconfig.sh "$inter" /run/inet2/wg/"$inter" # create the wireguard interface *in the default namespace* step "Adding Wireguard interface $inter" @@ -90,7 +90,7 @@ stop() { reload() { getval interface | while read -r inter; do step "Generating config for $inter" - run /usr/local/bin/mkwgconfig.sh "$inter" /run/inet2/wg/"$inter" /etc/inet2.conf + run ${INET2_PREFIX}/bin/mkwgconfig.sh "$inter" /run/inet2/wg/"$inter" /etc/inet2.conf step "Setting Wireguard config for $inter" run wg setconf "$inter" /run/inet2/wg/"$inter" diff --git a/bin/mkbirdconfig.sh b/bin/mkbirdconfig.sh index bf5c1f3..a7ca42e 100755 --- a/bin/mkbirdconfig.sh +++ b/bin/mkbirdconfig.sh @@ -1,6 +1,6 @@ #!/bin/sh -. /var/lib/inet2/inet2.sh +. ${INET2_PREFIX}/share/inet2/inet2.sh escapebird() { sed -e 's/\\/\\\\/g;s/"/\\"/g' diff --git a/bin/mkwgconfig.sh b/bin/mkwgconfig.sh index 6ee11a9..2da87be 100755 --- a/bin/mkwgconfig.sh +++ b/bin/mkwgconfig.sh @@ -1,11 +1,11 @@ -#!/usr/bin/env sh +#!/bin/sh # args: /path/to/interface-config /path/to/output.conf inter="$1" configfile=/etc/inet2.conf getval() { - /var/lib/inet2/config.awk "$configfile" "$@" + ${INET2_PREFIX}/share/inet2/config.awk "$configfile" "$@" } k() { diff --git a/deployments/initd/inet2.initd b/deployments/initd/inet2.initd index 41bb887..03b14b2 100755 --- a/deployments/initd/inet2.initd +++ b/deployments/initd/inet2.initd @@ -3,13 +3,15 @@ START=70 STOP=10 +export INET2_PREFIX=/usr/local + start() { - /usr/local/bin/inet2.sh start + ${INET2_PREFIX}/bin/inet2.sh start /sbin/service bird start } stop() { - /usr/local/bin/inet2.sh stop + ${INET2_PREFIX}/bin/inet2.sh stop /sbin/service bird stop } @@ -19,7 +21,7 @@ restart() { } reload() { - /usr/local/bin/inet2.sh reload + ${INET2_PREFIX}/bin/inet2.sh reload /sbin/service bird restart } diff --git a/deployments/openrc/inet2.initd b/deployments/openrc/inet2.initd index 3d12227..c9ebe39 100755 --- a/deployments/openrc/inet2.initd +++ b/deployments/openrc/inet2.initd @@ -4,13 +4,15 @@ description="Sets up wireguard interfaces connected via the host's internet conn extra_started_commands="reloadwg" +export INET2_PREFIX=/usr/local + start() { - /usr/local/bin/inet2.sh start + ${INET2_PREFIX}/bin/inet2.sh start rc-service bird start 2> /dev/null } stop() { - /usr/local/bin/inet2.sh stop + ${INET2_PREFIX}/bin/inet2.sh stop rc-service bird stop 2> /dev/null } @@ -20,7 +22,7 @@ restart() { } reload() { - /usr/local/bin/inet2.sh reload + ${INET2_PREFIX}/bin/inet2.sh reload rc-service bird restart 2> /dev/null } diff --git a/lib/config.awk b/share/config.awk similarity index 100% rename from lib/config.awk rename to share/config.awk diff --git a/lib/inet2.sh b/share/inet2.sh similarity index 82% rename from lib/inet2.sh rename to share/inet2.sh index 672286e..73bd279 100755 --- a/lib/inet2.sh +++ b/share/inet2.sh @@ -9,7 +9,7 @@ step() { } getval() { - /var/lib/inet2/config.awk /etc/inet2.conf "$@" + ${INET2_PREFIX}/share/inet2/config.awk /etc/inet2.conf "$@" } haskey() {