From ace9bdcf2be27bae89075207ff2ca60f200b81cf Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 11 Jan 2019 11:43:22 +0200 Subject: [PATCH] Init scripts: generalize config file setup --- board/common/overlay/etc/init.d/base | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/board/common/overlay/etc/init.d/base b/board/common/overlay/etc/init.d/base index 7b08c9384d..7a102d51ff 100755 --- a/board/common/overlay/etc/init.d/base +++ b/board/common/overlay/etc/init.d/base @@ -8,6 +8,7 @@ test -n "$os_debug" || source /etc/init.d/conf source /etc/init.d/panic + msg_begin() { echo -n " * $1: " } @@ -24,3 +25,35 @@ msg_background() { test -n "$1" && echo $1 || echo "pending" } +prepare_conf() { + # $1 - actual config file + # $2 - system-provided config file + # $3 - user-provided config file + + # long story short: + # * user conf file takes precedence, if present + # * system conf file is used by default, if actual file absent + + actual_conf="$1" + system_conf="$2" + user_conf="$3" + + if [[ -n "$user_conf" && -f "$user_conf" ]]; then + cp -f "$user_conf" "$actual_conf" + grep -E "/boot .*ro[\s,]" /proc/mounts + RO=$? + test $RO == 0 && mount -o remount,rw /boot + rm -f $user_conf + test $RO == 0 && mount -o remount,ro /boot + fi + + if [[ ! -f "$actual_conf" && -f "$system_conf" ]]; then + cp "$system_conf" "$actual_conf" + fi + + # we want only Unix newlines in conf files + if [[ -f "$actual_conf" ]]; then + sed -i 's/\r//g' "$actual_conf" + fi +} +