From d9cb59fcc670f14005c3c40786674094c073c528 Mon Sep 17 00:00:00 2001 From: lemoer Date: Wed, 6 Jan 2021 17:20:07 +0100 Subject: [PATCH] scripts: add imagebuilder/build_gluon.sh --- ...ay-add-scripts-imagebuilder-into-dir.patch | 19 +++++ scripts/imagebuilder/build_gluon.sh | 72 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 patches/openwrt/0019-imagebuilder-hacky-way-add-scripts-imagebuilder-into-dir.patch create mode 100755 scripts/imagebuilder/build_gluon.sh diff --git a/patches/openwrt/0019-imagebuilder-hacky-way-add-scripts-imagebuilder-into-dir.patch b/patches/openwrt/0019-imagebuilder-hacky-way-add-scripts-imagebuilder-into-dir.patch new file mode 100644 index 00000000..252ddee7 --- /dev/null +++ b/patches/openwrt/0019-imagebuilder-hacky-way-add-scripts-imagebuilder-into-dir.patch @@ -0,0 +1,19 @@ +From: lemoer +Date: Wed, 6 Jan 2021 17:23:27 +0100 +Subject: imagebuilder: hacky way add scripts/imagebuilder into dir + +diff --git a/target/imagebuilder/Makefile b/target/imagebuilder/Makefile +index e478b5f266cf47a638c82798e8ee596d1820d2ee..4b538529e950f820aede91275b779ab53f88ff71 100644 +--- a/target/imagebuilder/Makefile ++++ b/target/imagebuilder/Makefile +@@ -39,6 +39,10 @@ $(BIN_DIR)/$(IB_NAME).tar.xz: clean + $(CP) -L \ + $(TOPDIR)/../scripts \ + $(PKG_BUILD_DIR)/gluon/ ++ $(CP) -L \ ++ $(TOPDIR)/../scripts/imagebuilder/* \ ++ $(PKG_BUILD_DIR)/ ++ echo "{}" > $(PKG_BUILD_DIR)/custom.json + + ifeq ($(CONFIG_IB_STANDALONE),) + echo '## Remote package repositories' >> $(PKG_BUILD_DIR)/repositories.conf diff --git a/scripts/imagebuilder/build_gluon.sh b/scripts/imagebuilder/build_gluon.sh new file mode 100755 index 00000000..126d6469 --- /dev/null +++ b/scripts/imagebuilder/build_gluon.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +set -e + +SCRIPT_DIR="$(dirname "$0")" +CUSTOM_DIR="$SCRIPT_DIR/gluon/tmp/custom/" + +cd "$SCRIPT_DIR" + +BOARD="$(grep -e '^CONFIG_TARGET_BOARD=' .config | cut -d '=' -f 2 | tr -d '"')" +SUBTARGET="$(grep -e '^CONFIG_TARGET_SUBTARGET=' .config | cut -d '=' -f 2 | tr -d '"')" + +config2profiles() { + # Using .profiles.mk is not an option, because we disable a lot of devices + # in gluon and we do not want them to be built. + grep -e "^CONFIG_TARGET_DEVICE_${BOARD}_${SUBTARGET}_DEVICE.*=y\$" "$1" | \ + cut -d '=' -f 1 | cut -d '_' -f 7- +} + +config2packages() { + # - some config symbols, which are not a package appear, therefore strip + # everything with uppercase characters + # - installing grub is wrong + grep -e '^CONFIG_PACKAGE.*=y' "$1" | \ + cut -d '_' -f 3- | cut -d '=' -f 1 | \ + grep -ve '[A-Z]' | \ + grep -ve '^grub2$' | \ + tr -s '\n' ' ' + + # Per device packages + grep -e "^CONFIG_TARGET_DEVICE_PACKAGES_${BOARD}_${SUBTARGET}_DEVICE_$2=" "$1" | \ + cut -d '=' -f 2 | tr -d '"' +} + +if [ -z "$INCLUDE_ONLY" ] && [ "$#" -lt 1 ]; then + echo 'This is the gluon imagebuilder. You can use this to build a ' + echo 'customized gluon:' + echo + echo '- Note, that we do not fully support the imagebuilder.' + echo '- Adding additional packages or removing them is not supported.' + echo '- Adding arbitrary files is not supported.' + echo '- The imagebuilder is only used to to add a custom config custom.json' + echo ' with chosen configuration options to gluon. Please refer to' + echo ' https://gluon.readthedocs.io/ to see the available options.' + echo '- Place your custom.json in this directory.' + echo + echo 'To continue, run this script with' + echo + echo "#> $0 PROFILE" + echo + echo 'where PROFILE may be one of the following:' + config2profiles .config | sed 's/^/- /' + exit 0 +fi + + +if [ -z "$INCLUDE_ONLY" ]; then + rm -rf "$CUSTOM_DIR" + mkdir -p "$CUSTOM_DIR/lib/gluon/" + cp "custom.json" "$CUSTOM_DIR/lib/gluon/" + + if ! config2profiles .config | grep -e "^$1\$"; then + echo "Profile $1 not available. Call without argument to see available profiles." + exit 1 + fi + # DEVICE_TYPE=other is kind of a hack to ensure kmod-ipt-offload, odhcpd-ipv6only, ppp and + # ppp-mod-pppoe are not in $DEFAULT_PACKAGES. Otherwise the build will fail, because gluon + # does not provide them. + make image \ + FILES="$CUSTOM_DIR" DEVICE_TYPE=other \ + PACKAGES="$(config2packages .config "$1")" PROFILE="$1" +fi