[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

custom persistence for live-config components



Hi

Attached is a prototype patch to implement custom persistence for
live-config components. Only one component is converted to this to show
how it's intended to work. The patch is not yet tested. I'd like to have
some feeback before going on and converting all the components and
testing.

Gaudenz
From fe609f3c78afe898c6c9c4690a87de2543f0563c Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@debian.org>
Date: Sat, 28 Mar 2015 14:47:40 +0100
Subject: [PATCH] Custom persistence for components

Persistence can be enabled/disabled with the parameters
persistent-components and nonpersistent-components. These parameters
take a comma separated list of components. Each components can define
it's default setting in case it's not listed in one of these parameters.
---
 components/0010-debconf |  8 +++++---
 components/functions.sh | 38 ++++++++++++++++++++++++++++++++++++++
 frontend/live-config    | 12 ++++++++----
 3 files changed, 51 insertions(+), 7 deletions(-)
 create mode 100644 components/functions.sh

diff --git a/components/0010-debconf b/components/0010-debconf
index cc70e46..8b02254 100755
--- a/components/0010-debconf
+++ b/components/0010-debconf
@@ -10,6 +10,8 @@
 
 #set -e
 
+. /lib/live/config/functions.sh
+
 Cmdline ()
 {
 	# Reading kernel command line
@@ -27,7 +29,7 @@ Init ()
 {
 	# Checking if package is installed or already configured
 	if [ ! -e /var/lib/dpkg/info/debconf.list ] || \
-	   [ -e /var/lib/live/config/debconf ]
+	   check_statefile
 	then
 		exit 0
 	fi
@@ -84,8 +86,8 @@ Config ()
 		rm -f "${_TMPFILE}"
 	done
 
-	# Creating state file
-	touch /var/lib/live/config/debconf
+	# Creating state file if requested
+	create_statefile "false"
 }
 
 Cmdline
diff --git a/components/functions.sh b/components/functions.sh
new file mode 100644
index 0000000..f8141f5
--- /dev/null
+++ b/components/functions.sh
@@ -0,0 +1,38 @@
+
+_SCRIPT="$(readlink -f ${0})"
+_COMPONENT_NAME="${_SCRIPT#/lib/live/config/????-}"
+
+create_statefile() {
+
+    # set default value
+    _CREATE="$1"
+
+    if echo "${LIVE_CONFIG_PERSISTENT_COMPONENTS}" | grep -q "${_COMPONENT_NAME}"
+    then
+        _CREATE="true"
+    elif echo "${LIVE_CONFIG_NONPERSISTENT_COMPONENTS}" | grep -q "${_COMPONENT_NAME}"
+    then
+        _CREATE="false"
+    fi
+
+    # create statefile if requested
+    if [ ${_CREATE} = "true" ]
+    then
+        touch /var/lib/live/config/${_COMPONENT_NAME}
+    fi
+}
+
+check_statefile() {
+
+    # if the component is listed in LIVE_CONFIG_NONPERSISTENT_COMPONENTS the statefile
+    # is ignored
+    if echo "${LIVE_CONFIG_NONPERSISTENT_COMPONENTS}" | grep -q "${_COMPONENT_NAME}"
+    then
+        return 1
+    elif [ -e /var/lib/live/config/${_COMPONENT_NAME} ]
+    then
+        return 0
+    else
+        return 1
+    fi
+}
diff --git a/frontend/live-config b/frontend/live-config
index ee9dfd1..6d01615 100755
--- a/frontend/live-config
+++ b/frontend/live-config
@@ -38,8 +38,6 @@ _IP_SEPARATOR="-"
 _PROC_OPTIONS="onodev,noexec,nosuid"
 export _IP_SEPARATOR _PROC_OPTIONS
 
-_COMPONENTS="$(ls /lib/live/config/*)"
-
 # Reading configuration files from filesystem and live-media
 for _FILE in /etc/live/config.conf /etc/live/config/* \
 	     /lib/live/mount/medium/live/config.conf /lib/live/mount/medium/live/config/*
@@ -67,14 +65,14 @@ Cmdline ()
 				# Run all components
 				LIVE_CONFIG_COMPONENTS=""
 				LIVE_CONFIG_NOCOMPONENTS=""
-				_COMPONENTS="$(ls /lib/live/config/*)"
+				_COMPONENTS="$(ls /lib/live/config/????-*)"
 				;;
 
 			live-config.nocomponents=*|nocomponents=*)
 				# Don't run requested components
 				LIVE_CONFIG_COMPONENTS=""
 				LIVE_CONFIG_NOCOMPONENTS="${_PARAMETER#*nocomponents=}"
-				_COMPONENTS="$(ls /lib/live/config/*)"
+				_COMPONENTS="$(ls /lib/live/config/????-*)"
 				;;
 
 			live-config.nocomponents|nocomponents)
@@ -83,6 +81,12 @@ Cmdline ()
 				LIVE_CONFIG_NOCOMPONENTS=""
 				_COMPONENTS=""
 				;;
+			live-config.persistent-components=*|persistent-components=*)
+				export LIVE_CONFIG_PERSISTENT_COMPONENTS="${_PARAMETER#*persistent-components=*}"
+				;;
+			live-config.nonpersistent-components=*|nonpersistent-components=*)
+				export LIVE_CONFIG_NONPERSISTENT_COMPONENTS="${_PARAMETER#*nonpersistent-components=}"
+				;;
 
 			# Shortcuts
 			live-config.noroot|noroot)
-- 
2.1.4

Attachment: signature.asc
Description: PGP signature


Reply to: