From 05e2b4b7564ba517aed3e1e714235312df6349d9 Mon Sep 17 00:00:00 2001 From: Eric Hameleers Date: Fri, 15 Jun 2018 13:06:32 +0200 Subject: Add support for on-disk OS configuration file The configuration file must be in the liveslak main directory ('/liveslak' by default) and be called 'DISTRO_os.cfg' where DISTRO is the lower-case name of the distro ('slackware' by default). The following variables can be defined in the configuration file, one per line, in the format VAR=value: BLACKLIST, INIT, KEYMAP, LIVE_HOSTNAME, LOAD, LOCALE, LUKSVOL, NOLOAD, RUNLEVEL, TWEAKS, TZ, XKB. Since the configuration file is sourced by the live init script, it is OK to have comments in it that are prefixed with '#'. --- liveinit.tpl | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'liveinit.tpl') diff --git a/liveinit.tpl b/liveinit.tpl index 5cddd02..da1b4ff 100755 --- a/liveinit.tpl +++ b/liveinit.tpl @@ -2,7 +2,7 @@ # # Copyright 2004 Slackware Linux, Inc., Concord, CA, USA # Copyright 2007, 2008, 2009, 2010, 2012 Patrick J. Volkerding, Sebeka, MN, USA -# Copyright 2015, 2016, 2017 Eric Hameleers, Eindhoven, NL +# Copyright 2015, 2016, 2017, 2018 Eric Hameleers, Eindhoven, NL # All rights reserved. # # Redistribution and use of this script, with or without modification, is @@ -49,6 +49,9 @@ LIVEUID="@LIVEUID@" LIVEMEDIA="" LIVEPATH="" +DISTROCFG="@DISTRO@_os.cfg" +CFGACTION="" + # By default, let the media determine if we can write persistent changes: # However, if we define TORAM=1, we will also set VIRGIN=1 since we want # to avoid anything that writes to disk after we copy the OS to RAM. @@ -185,6 +188,10 @@ for ARG in $(cat /proc/cmdline); do # nic=::[:ipaddr:netmask[:gateway]] ENET=$(echo $ARG | cut -f2 -d=) ;; + cfg=*) + CFGACTION=$(echo $ARG | cut -f2 -d=) + if [ "${CFGACTION}" = "skip" ]; then DISTROCFG="" ; fi + ;; noload=*) NOLOAD=$(echo $ARG | cut -f2 -d=) ;; @@ -676,6 +683,35 @@ if [ "$RESCUE" = "" ]; then debugit + # liveslak can optionally load a OS config file "@DISTRO@_os.cfg" + # which contains "VARIABLE=value" lines, where VARIABLE is one of + # the following variables that are used below in the live init script: + # BLACKLIST, INIT, KEYMAP, LIVE_HOSTNAME, LOAD, LOCALE, LUKSVOL, + # NOLOAD, RUNLEVEL, TWEAKS, TZ, XKB. + if [ -z "$CFGACTION" ]; then + # Read OS configuration from disk file if present + # (prevent this by adding 'cfg=skip' to the boot commandline). + if [ -f "/mnt/media/${LIVEMAIN}/${DISTROCFG}" ]; then + source /mnt/media/${LIVEMAIN}/${DISTROCFG} + fi + elif [ "$CFGACTION" = "write" ]; then + # Write liveslak OS parameters to disk: + echo > /mnt/media/${LIVEMAIN}/${DISTROCFG} 2>/dev/null + if [ $? -ne 0 ]; then + echo "${MARKER}: Live media read-only, cannot write config file." + else + echo "${MARKER}: Writing config to /${LIVEMAIN}/${DISTROCFG}" + for LIVEPARM in \ + BLACKLIST INIT KEYMAP LIVE_HOSTNAME LOAD LOCALE LUKSVOL \ + NOLOAD RUNLEVEL TWEAKS TZ XKB ; + do + if [ -n "$(eval echo \$$LIVEPARM)" ]; then + echo $LIVEPARM=$(eval echo \$$LIVEPARM) >> /mnt/media/${LIVEMAIN}/${DISTROCFG} + fi + done + fi + fi + # Start assembling our live system components below /mnt/live : mkdir /mnt/live -- cgit v1.2.3