From 57aa3407a12f77f0316f6bcfe7f669cfb2bae67f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 25 Sep 2016 19:39:09 +0200 Subject: scripts/restore-etc: look for default settings in /usr/share/factory/settings This file, when it exists, contains settings in the following format : ${program}/${setting}=${value} Here restore-etc checks there for the file-system type (fstype) and the mount options (mountopt). These ones can override the script's defaults, but may be overridden by the command line. This will particularly allow some models to override the default size for /etc without having to patch the script nor call it with a command line from a script where it's not convenient. --- scripts/restore-etc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/restore-etc b/scripts/restore-etc index 1d00fca..a1c273a 100755 --- a/scripts/restore-etc +++ b/scripts/restore-etc @@ -16,6 +16,7 @@ FLASHCFG=${FLASHDIR}/cfg FILE=/etc/.restored EXCLUDE=/usr/share/factory/ignore-files REFERENCE=/usr/share/factory/base-etc +SETTINGS=/usr/share/factory/settings DIFF=0 FORCE=0 FACTORY=0 @@ -251,6 +252,20 @@ if ! grep -wq tmpfs /proc/filesystems 2>/dev/null; then FSTYPE=ramfs fi +# Usage: get_settings $PROG $SETTING +# If setting is found, returns 0 with the first value in $REPLY, otherwise 1. +# Please note that an empty value found is different from no entry. +get_settings() { + [ -s "$SETTINGS" ] || return 1 + REPLY=$(sed -n "/^$1\/$2=/{s|^$1/$2=|=|p;Q}" "$SETTINGS") || return 1 + [ -n "$REPLY" ] || return 1 + REPLY="${REPLY#=}" +} + +get_settings "${0##*/}" fstype && FSTYPE="$REPLY" +get_settings "${0##*/}" mountopt && MOUNTOPT="$REPLY" + + while [ $# -gt 0 ]; do if [ ".$1" = ".-f" ]; then FORCE=1 elif [ ".$1" = ".-d" ]; then DIFF=1 -- 1.7.12.1