From d2eac3175055baaacc10ccd9fcb1bed5e8e3bd34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <karel.koci@nic.cz>
Date: Tue, 3 Jul 2018 10:32:59 +0200
Subject: [PATCH] lists: generalize lists for all boards

Make lists general. Board specific packages are handled by lua not m4
that meanst that we have same lists for all boards and specific sections
are ignored/skipped depending on model variable.
---
 compile_fw                    |  2 +-
 helpers/generate_userlists.sh | 27 +++++++--------------------
 lists/base.lua.m4             |  8 +++++++-
 lists/repository.m4           | 19 +++++++++++++++----
 lists/utils.m4                |  6 ++----
 5 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/compile_fw b/compile_fw
index c2ea58c21..5f6662461 100755
--- a/compile_fw
+++ b/compile_fw
@@ -397,7 +397,7 @@ gen_lists() {
 	_report "Generating package lists for updater"
 	[ -n "${TARGET_BOARD}" ] || _die "You need to specify target board!"
 	mkdir -p bin/packages/lists
-	"${SRC_DIR}"/helpers/generate_userlists.sh --model "${TARGET_BOARD}" --branch "${PUBLISH_BRANCH}" --src "${SRC_DIR}/lists" bin/packages/lists
+	"${SRC_DIR}"/helpers/generate_userlists.sh --branch "${PUBLISH_BRANCH}" --src "${SRC_DIR}/lists" bin/packages/lists
 }
 
 build_help="	Builds everything"
diff --git a/helpers/generate_userlists.sh b/helpers/generate_userlists.sh
index dab5f16e2..990cb7630 100755
--- a/helpers/generate_userlists.sh
+++ b/helpers/generate_userlists.sh
@@ -1,9 +1,9 @@
 #!/bin/sh
 set -e
 
-MINIMAL=false
 LISTS_DIR=
 OUTPUT_PATH=
+FALLBACK=
 while [ $# -gt 0 ]; do
 	case "$1" in
 		-h|--help)
@@ -13,30 +13,21 @@ while [ $# -gt 0 ]; do
 			echo "Options:"
 			echo "  --help, -h"
 			echo "    Prints this help text."
-			echo "  --model (turris|omnia|mox)"
-			echo "    Target Turris model."
 			echo "  --branch BRANCH"
 			echo "    Target branch for which this userlist is generated."
-			echo "  --minimal"
-			echo "    Generate userlists for minimal branch. (This adds nightly as a fallback branch)"
+			echo "  --minimal BRANCH"
+			echo "    Generate userlists for minimal branch. (This adds BRANCH as a fallback branch)"
 			echo "  --src PATH"
 			echo "    Source directory with list to process"
 			exit
 			;;
-		--model)
-			shift
-			[ "$1" != "turris" -a "$1" != "omnia" -a "$1" != "mox" ] && {
-				echo "Unknown model: $1" >&2
-				exit 1
-			}
-			BOARD="$1"
-			;;
 		--branch)
 			shift
 			BRANCH="$1"
 			;;
 		--minimal)
-			MINIMAL=true
+			shift
+			FALLBACK="$1"
 			;;
 		--src)
 			shift
@@ -58,10 +49,6 @@ done
 	echo "You have to specify output path." >&2
 	exit 1
 }
-[ -z "$BOARD" ] && {
-	echo "Missing --model option." >&2
-	exit 1
-}
 [ -z "$BRANCH" ] && {
 	echo "Missing --branch option." >&2
 	exit 1
@@ -77,8 +64,8 @@ done
 
 mkdir -p $OUTPUT_PATH
 
-M4ARGS="--include=$LISTS_DIR -D _INCLUDE_=$LISTS_DIR/ -D _BRANCH_=$BRANCH -D _BOARD_=$BOARD"
-$MINIMAL && M4ARGS="$M4ARGS -D _BRANCH_FALLBACK_=nightly"
+M4ARGS="--include=$LISTS_DIR -D _INCLUDE_=$LISTS_DIR/ -D _BRANCH_=$BRANCH"
+[ -z "$FALLBACK" ] || M4ARGS="$M4ARGS -D _BRANCH_FALLBACK_=$FALLBACK"
 
 for f in $(find "$LISTS_DIR" -name '*.lua.m4'); do
 	m4 $M4ARGS $f > "$OUTPUT_PATH/$(basename "$f" | sed s/\.m4$//)"
diff --git a/lists/base.lua.m4 b/lists/base.lua.m4
index 678eb25a8..1f8b21eca 100644
--- a/lists/base.lua.m4
+++ b/lists/base.lua.m4
@@ -18,7 +18,13 @@ Install("base-files", "busybox", { critical = true })
 Package("kernel", { reboot = "delayed" })
 Package("kmod-mac80211", { reboot = "delayed" })
 forInstallCritical(kmod,file2args(kmod.list))
-forInstallCritical(kmod,file2args(kmod-_BOARD_.list))
+if model:match("[Mm][Oo][Xx]") then
+	forInstallCritical(kmod,file2args(kmod-mox.list))
+elseif model:match("[Oo]mnia") then
+	forInstallCritical(kmod,file2args(kmod-omnia.list))
+elseif model:match("^[Tt]urris$") then
+	forInstallCritical(kmod,file2args(kmod-turris.list))
+end
 Install("fstools", { critical = true })
 if model and model:match("[Tt]urris") then
 	Install("turris-support", { critical = true })
diff --git a/lists/repository.m4 b/lists/repository.m4
index 02967e7d0..4f750eabc 100644
--- a/lists/repository.m4
+++ b/lists/repository.m4
@@ -6,11 +6,22 @@ divert(-1)
 pushdef(`SUBDIRS',`subdirs = {"base", "core" esyscmd(`awk "/src-git/{printf \", \\\"%s\\\"\", \$'`2}" feeds.conf')}')
 
 divert(0)dnl
+local board
+if model:match("[Mm][Oo][Xx]") then
+	board = "mox"
+elseif model:match("[Oo]mnia") then
+	board = "omnia"
+elseif model:match("^[Tt]urris$") then
+	board = "turris"
+else
+	DIE("Unsupported Turris model: " .. tostring(model))
+end
+
 dnl
 if version_match and version_match(self_version, ">=60.0.1") then
 dnl
 dnl Basic turris repository
-	Repository("turris", "https://repo.turris.cz/_BOARD_`'ifdef(`_BRANCH_',-_BRANCH_)/packages", {
+	Repository("turris", "https://repo.turris.cz/" .. board .. "ifdef(`_BRANCH_',-_BRANCH_)/packages", {
 		SUBDIRS
 	})
 dnl
@@ -18,7 +29,7 @@ dnl Fallback turris repository for not complete branches
 dnl In testing branches we are compiling just a minimal set of packages to allow
 dnl updater to use all packages we are adding nightly as fallback reposutory.
 ifdef(`_BRANCH_FALLBACK_',
-`	Repository("turris-fallback", "https://repo.turris.cz/_BOARD_-_BRANCH_FALLBACK_/packages", {
+`	Repository("turris-fallback", "https://repo.turris.cz/" .. board .. "-_BRANCH_FALLBACK_/packages", {
 		SUBDIRS,
 		priority = 40,
 		ignore = {"missing"}
@@ -28,11 +39,11 @@ dnl
 dnl Repeat the same (this time without comments for api.turris.cz for backward
 dnl compatibility.
 else
-	Repository("turris", "https://api.turris.cz/openwrt-repo/_BOARD_`'ifdef(`_BRANCH_',-_BRANCH_)/packages", {
+	Repository("turris", "https://api.turris.cz/openwrt-repo/" .. board .. "ifdef(`_BRANCH_',-_BRANCH_)/packages", {
 		SUBDIRS
 	})
 ifdef(`_BRANCH_FALLBACK_',
-`	Repository("turris-fallback", "https://api.turris.cz/openwrt-repo/_BOARD_-_BRANCH_FALLBACK_/packages", {
+`	Repository("turris-fallback", "https://api.turris.cz/openwrt-repo/" .. board .. "-_BRANCH_FALLBACK_/packages", {
 		SUBDIRS,
 		priority = 40,
 		ignore = {"missing"}
diff --git a/lists/utils.m4 b/lists/utils.m4
index 7744497fe..28a0f59fc 100644
--- a/lists/utils.m4
+++ b/lists/utils.m4
@@ -1,9 +1,7 @@
 divert(-1)
 
-# We require the _BOARD_ variable to be defined so let's check
-ifdef(`_BOARD_',,`errprint(`_BOARD_ have to be defied when gerating new userlist. For example pass argument -D _BOARD_=turris to m4.')m4exit(`1')')
-# Also we use the _BRANCH_ variable, but if it isn't defined than it means deploy
-# and if defined as deploy then we undefine it.
+# We use the _BRANCH_ variable, but if it isn't defined than it means deploy and
+# if defined as deploy then we undefine it.
 ifelse(_BRANCH_,deploy,`undefine(`_BRANCH_')',)
 
 
-- 
GitLab