From: Christian Marangi Date: Wed, 3 May 2023 23:47:07 +0000 (+0200) Subject: nginx: introduce migration for old uci conf template X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=6a3cc76ea56d8e4ac675e67a55c7f4b76e97bd5b;p=feed%2Fpackages.git nginx: introduce migration for old uci conf template Introduce support for migration of old uci conf template to new version. Uci conf template are saved in config backup. This cause problem on config restore as old config template might have compatibility problem with new nginx implementation. Add logic to migrate the template script at runtime to correctly align to latest change from nginx and nginx-util. Fixes: 65a676ed56fb ("nginx: introduce support for dynamic modules") Fixes: #20904 Signed-off-by: Christian Marangi --- diff --git a/net/nginx/files/nginx.init b/net/nginx/files/nginx.init index 632a3f10a7..9e3ed0a7ac 100644 --- a/net/nginx/files/nginx.init +++ b/net/nginx/files/nginx.init @@ -8,11 +8,27 @@ USE_PROCD=1 G_OPTS="daemon off;" NGINX_UTIL="/usr/bin/nginx-util" +UCI_CONF_TEMPLATE="/etc/nginx/uci.conf.template" +LATEST_UCI_CONF_VERSION="1.1" eval $("${NGINX_UTIL}" get_env) CONF="" +nginx_check_luci_template() { + UCI_CONF_VERSION="$(sed -nr 's/# UCI_CONF_VERSION=(.*)/\1/p' $UCI_CONF_TEMPLATE)" + + # No need to migrate already latest version + if [ "$UCI_CONF_VERSION" = "$LATEST_UCI_CONF_VERSION" ]; then + return + fi + + if [ -z "$UCI_CONF_VERSION" ]; then + echo "" >> $UCI_CONF_TEMPLATE + echo "include module.d/*.module;" >> $UCI_CONF_TEMPLATE + echo "# UCI_CONF_VERSION=1.1" >> $UCI_CONF_TEMPLATE + fi +} nginx_init() { [ -z "${CONF}" ] || return # already called. @@ -23,6 +39,10 @@ nginx_init() { rm -f "$(readlink "${UCI_CONF}")" ${NGINX_UTIL} init_lan + if [ -f $UCI_CONF_TEMPLATE ]; then + nginx_check_luci_template + fi + if [ -e "${UCI_CONF}" ] then CONF="${UCI_CONF}" else CONF="${NGINX_CONF}"