diff --git a/ffmuc-mesh-vpn-wireguard-vxlan/Makefile b/ffmuc-mesh-vpn-wireguard-vxlan/Makefile index d74463ee..c1109702 100644 --- a/ffmuc-mesh-vpn-wireguard-vxlan/Makefile +++ b/ffmuc-mesh-vpn-wireguard-vxlan/Makefile @@ -14,4 +14,30 @@ define Package/ffmuc-mesh-vpn-wireguard-vxlan DEPENDS:=+gluon-mesh-vpn-core +micrond +kmod-wireguard +wireguard-tools +ip-full +lua-jsonc endef +define ShSrcDiet + rm -rf $(2) + $(CP) $(1) $(2) + ifdef CONFIG_GLUON_MINIFY + set -e; $(FIND) $(2) -type f | while read src; do \ + echo "Minifying $$$$src..."; \ + ./shell_minify.sh "$$$$src"; \ + done + endif +endef + +define Build/Compile + $(call Gluon/Build/Compile) + $(if $(wildcard ./shsrc/.), + $(call ShSrcDiet,shsrc,$(PKG_BUILD_DIR)/shdest/) + ) +endef + +define Package/$(PKG_NAME)/install + $(Gluon/Build/Install) + + $(if $(wildcard ./shsrc/.), + $(CP) $(PKG_BUILD_DIR)/shdest/. $(1)/ + ) +endef + $(eval $(call BuildPackageGluon,ffmuc-mesh-vpn-wireguard-vxlan)) diff --git a/ffmuc-mesh-vpn-wireguard-vxlan/shell_minify.sh b/ffmuc-mesh-vpn-wireguard-vxlan/shell_minify.sh new file mode 100755 index 00000000..52812f9d --- /dev/null +++ b/ffmuc-mesh-vpn-wireguard-vxlan/shell_minify.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT + +set -eu + +strip_comments() { + filename=$1 + + # strip comments from all but the first line + sed -i '2,$s/\s*#.*//' "${filename}" + + # strip first line if it isn't a shebang + sed -i '1s/\s*#[^!].*//' "${filename}" +} + +strip_duplicate_newlines() { + filename=$1 + + # strip empty lines + sed -i '/^\s*$/d' "${filename}" +} + +strip_spaces_around_vertical_bar() { + filename=$1 + + # convert "true | false" to "true|false" + sed -i 's/\s\+|\s*/|/g' "${filename}" + # convert "true | false" to "true|false" + sed -i 's/\s*|\s\+/|/g' "${filename}" +} + +strip_spaces_between_semicolon_and_then_or_do() { + filename=$1 + + # convert "if true; then" to "if true;then" + sed -i 's/;\s\+then/;then/g' "${filename}" + + # convert "for xxx; do" to "for xxx;do" and "; done" to ";done" + sed -i 's/;\s\+do/;do/g' "${filename}" +} + +strip_spaces_around_boolean_operators() { + filename=$1 + + # convert "true && false" to "true&&false" + sed -i 's/\s*||\s*/||/g' "${filename}" + sed -i 's/\s*&&\s*/&&/g' "${filename}" +} + +strip_trailing_semicolon() { + filename=$1 + # remove trailing ; excluding ";;" for switch/case clauses + sed -i 's/\([^;]\);$/\1/' "${filename}" +} + +strip_comments "$1" +strip_trailing_semicolon "$1" +strip_duplicate_newlines "$1" +strip_spaces_around_vertical_bar "$1" +strip_spaces_around_boolean_operators "$1" +strip_spaces_between_semicolon_and_then_or_do "$1" diff --git a/ffmuc-mesh-vpn-wireguard-vxlan/files/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink b/ffmuc-mesh-vpn-wireguard-vxlan/shsrc/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink similarity index 100% rename from ffmuc-mesh-vpn-wireguard-vxlan/files/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink rename to ffmuc-mesh-vpn-wireguard-vxlan/shsrc/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink