From aa02cf8fc16a2e79f71d5140dabc8e6dca3a7a87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <cynerd@email.cz>
Date: Fri, 3 Jul 2020 11:02:45 +0200
Subject: [PATCH] generate_medkit: Modify configuration for package lists

Recetly package lists were expanded by options and they now have their
own configuration file. This makes them incompatible with configuration
done by bootstrap script. This updates bootstrap script to allow usage
of package list options and also removes invalid generation of lists to
updater's config.

The configuration is not replaced by any easy way because we are not
using it and generating another configuration is just too big of a
hustle. Instead we should investigate in future some other way to
generate configuration (for example using package) instead of this.
---
 generate_medkit                     | 12 ++++++++----
 helpers/medkit-updater-ng-config.m4 |  4 ----
 lists/bootstrap.lua                 | 13 ++++++++++---
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/generate_medkit b/generate_medkit
index 490ae206c..71478d4bb 100755
--- a/generate_medkit
+++ b/generate_medkit
@@ -25,7 +25,7 @@ export BOARD=
 export BRANCH="$PUBLISH_BRANCH"
 export UPDATER_BRANCH=
 export L10N=cs,de
-export LISTS=
+export PKGLISTS=
 export UPDATER_SCRIPT=
 export OVERLAY=
 export SIGN_KEY=
@@ -65,7 +65,12 @@ while [ $# -gt 0 ]; do
 			echo "  --lists, -p PKGLIST,.."
 			echo "    What lists should be added to medkit. In default no"
 			echo "    additional lists will be added. Multiple lists can be"
-			echo "    specified by separating them by commas."
+			echo "    specified by separating them by commas. Options for them"
+			echo "    can be specified in parentheses and divided by pipe. Note"
+			echo "    that lists are included in medkit but not configured. This"
+			echo "    means that they will be removed with first update. To"
+			echo "    prevent this you have to include our own"
+			echo "    /etc/config/pkglists in overlay."
 			echo "  --updater-script FILE"
 			echo "    Run file as updater's script. It is executed after primary"
 			echo "    entry script of this tool."
@@ -99,7 +104,7 @@ while [ $# -gt 0 ]; do
 			;;
 		--lists|-p)
 			shift
-			LISTS="$1"
+			PKGLISTS="$1"
 			;;
 		--updater-script)
 			shift
@@ -166,7 +171,6 @@ touch root/usr/lib/opkg/status
 ## Generate /etc/config/updater
 m4args=()
 [ -z "\$UPDATER_BRANCH" ] || m4args+=("-D_BRANCH_='\$UPDATER_BRANCH'")
-[ -z "\$LISTS" ] || m4args+=("-D_LISTS_='\$LISTS'")
 [ -z "\$L10N" ] || m4args+=("-D_LANGS_=\$L10N")
 m4 "\${m4args[@]}" "\$TURRIS_BUILD_DIR/helpers/medkit-updater-ng-config.m4" > root/etc/config/updater
 
diff --git a/helpers/medkit-updater-ng-config.m4 b/helpers/medkit-updater-ng-config.m4
index 3681b3725..16f171e9a 100644
--- a/helpers/medkit-updater-ng-config.m4
+++ b/helpers/medkit-updater-ng-config.m4
@@ -5,14 +5,10 @@ define([foreach],[ifelse(eval($#>2),1,[pushdef([$1],[$3])$2[]popdef([$1])[]ifels
 divert(0)dnl
 
 dnl Set branch from BRANCH variable
-dnl Also enable all lists that were added during medkit generation.
 config turris 'turris'
 	option mode 'branch'
 ifdef([_UPDATER_BRANCH_],	option branch '_UPDATER_BRANCH_'
 )dnl
-ifdef([_LISTS_],foreach([LIST], [	list pkglists 'LIST'
-], _LISTS_)
-)dnl
 
 dnl Enable all languages that were enabled durring medkit generation.
 ifdef([_LANGS_], config l10n 'l10n'
diff --git a/lists/bootstrap.lua b/lists/bootstrap.lua
index 72fd496e0..a4183eef9 100644
--- a/lists/bootstrap.lua
+++ b/lists/bootstrap.lua
@@ -4,7 +4,9 @@ Root script for updater-ng configuration usable for bootstrapping.
 This script expects following variables to be possibly defined in environment:
   BOARD: board name (Mox|Omnia|Turris)
   L10N: commas separated list of languages to be installed in root.
-  LISTS: commas separated list of package lists to be included in root.
+  PKGLISTS: commas separated list of package lists to be included in root. To
+	specify options you can optionally add parentheses at the end of package name
+	and list pipe separated options inside them. (ex: foo(opt1|opt2),fee)
   TESTKEY: if definied non-empty then test kyes are included in installation
 ]]
 
@@ -32,8 +34,13 @@ Export('for_l10n')
 -- Aways include base script
 Script('base.lua')
 -- Include any additional lists
-for list in os.getenv('LISTS'):gmatch('[^,]+') do
-	Script(list .. '.lua')
+for list in os.getenv('PKGLISTS'):gmatch('[^,)]+') do
+	options = {}
+	Export("options")
+	for opt in list:match('%((.*)%)$'):gmatch('[^|]+') do
+		options[opt] = true
+	end
+	Script(list:match('^[^(]+') .. '.lua')
 end
 
 if os.getenv('TESTKEY') then
-- 
GitLab