From c715c11cf2f30ed95ae88bb3250d3e95335f7f06 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sat, 19 Mar 2022 16:48:32 +0100 Subject: [PATCH] Improve template config copying (#3535) * Do not overwrite config-default.conf Previously, when config-example.conf was missing, it would be created and config-default.conf would be made a symlink to it. However, this would overwrite any existing config-default.conf, potentially throwing away a user's data. This occurs when you clean up and throw away the (cluttering) config-example.conf (and depending on whether you use a symlink to another named config, or put data in config-default.conf, this would either just replace the symlink, or throw away your actual config data). This commit splits the update checks, so no files are ever overwritten, except a broken config-default.conf symlink. * Do not recreate example.conf if you remove it Previously, whenever config-example.conf (and some others) was missing, it start copying any missing example configs. This means that if you would remove config-example.conf to clean up your userpatches directory, it would be recreated everytime. Now, this is triggered by a missing config-default.conf (which is also created by the same block of code). The creating of config-example.conf is still there, so if you have no config-default.conf (or one of the others listed), then config-example.conf is created anyway, with config-default.conf being a link to it, just like before (so the first-run behavior is unmodified). --- compile.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compile.sh b/compile.sh index a2de512d4..3b9031c38 100755 --- a/compile.sh +++ b/compile.sh @@ -209,7 +209,7 @@ mkdir -p "${SRC}"/userpatches # Create example configs if none found in userpatches -if ! ls "${SRC}"/userpatches/{config-example.conf,config-docker.conf,config-vagrant.conf} 1> /dev/null 2>&1; then +if ! ls "${SRC}"/userpatches/{config-default.conf,config-docker.conf,config-vagrant.conf} 1> /dev/null 2>&1; then # Migrate old configs if ls "${SRC}"/*.conf 1> /dev/null 2>&1; then @@ -224,6 +224,10 @@ if ! ls "${SRC}"/userpatches/{config-example.conf,config-docker.conf,config-vagr # Create example config if [[ ! -f "${SRC}"/userpatches/config-example.conf ]]; then cp "${SRC}"/config/templates/config-example.conf "${SRC}"/userpatches/config-example.conf || exit 1 + fi + + # Link default config to example config + if [[ ! -f "${SRC}"/userpatches/config-default.conf ]]; then ln -fs config-example.conf "${SRC}"/userpatches/config-default.conf || exit 1 fi