#!/usr/bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/nextcloud-pre-edit-config - edit configuration file # # Copyright (c) 2013-2025 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2013-05-21 jed # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------- # read eislib etc. . /var/install/include/eislib . /var/install/include/check-eisfair-version pgmname=`basename $0` module_name="`echo "${pgmname}" | cut -d- -f1 | cut -d. -f1`" #exec 2> /tmp/${module_name}-pre-edit-config-trace$$.log #set -x configfile=/etc/config.d/${module_name} nextcloud_path=/var/${module_name} tmp_file=/var/tmp/${pgmname}.$$ # read parameters if [ -f ${configfile} ] then { grep -E "^NEXTCLOUD_DATA_DIR|^NEXTCLOUD_INSTANCE_ID|NEXTCLOUD_INSTANCE_SECRET|NEXTCLOUD_PASSWORD_SALT" ${configfile} } > ${tmp_file} . ${tmp_file} rm -d ${tmp_file} if [ -n "${NEXTCLOUD_DATA_DIR}" ] then # remove trailing slashes nextcloud_path="`echo "${NEXTCLOUD_DATA_DIR}" | sed 's#[/ ]*$##'`" fi ### instance id ### if [ -z "${NEXTCLOUD_INSTANCE_ID}" -a -z "`grep ^NEXTCLOUD_INSTANCE_ID ${configfile}`" ] then # add empty parameter if it doesn't exist echo "NEXTCLOUD_INSTANCE_ID=''" >> ${configfile} fi if [ -z "${NEXTCLOUD_INSTANCE_ID}" ] then # instance id not yet set /usr/bin/php -r "error_reporting(0); include('${nextcloud_path}/config/config.php'); print(\$CONFIG['instanceid']);" 2>/dev/null | \ grep -vi "array" > ${tmp_file} instance_id="`cat ${tmp_file} | sed 's/ *//g'`" rm -f ${tmp_file} if [ -n "${instance_id}" ] then # value found in Nextcloud configuration, save it ... mecho -n "writing instance id to configuration ..." # echo "INSTANCE-ID:${instance_id}" sed "s|^\(NEXTCLOUD_INSTANCE_ID\)=.*\( *# .*\)$|\1='${instance_id}' \2|" ${configfile} >${configfile}.tmp cp ${configfile}.tmp ${configfile} rm -f ${configfile}.tmp echo --info "done." fi fi ### instance secret ### if [ -z "${NEXTCLOUD_INSTANCE_SECRET}" -a -z "`grep ^NEXTCLOUD_INSTANCE_SECRET ${configfile}`" ] then # add empty parameter if it doesn't exist echo "NEXTCLOUD_INSTANCE_SECRET=''" >> ${configfile} fi if [ -z "${NEXTCLOUD_INSTANCE_SECRET}" ] then # secret not yet set /usr/bin/php -r "error_reporting(0); include('${nextcloud_path}/config/config.php'); print(\$CONFIG['secret']);" 2>/dev/null | \ grep -vi "array" > ${tmp_file} instance_secret="`cat ${tmp_file} | sed 's/ *//g'`" rm -f ${tmp_file} if [ -n "${instance_secret}" ] then # value found in Nextcloud configuration, save it ... mecho -n "writing instance secret to configuration ..." # echo "SECRET:${_uro_secret}" sed "s|^\(NEXTCLOUD_INSTANCE_SECRET\)=.*\( *# .*\)$|\1='${instance_secret}' \2|" ${configfile} >${configfile}.tmp cp ${configfile}.tmp ${configfile} rm -f ${configfile}.tmp echo --info "done." fi fi ### password salt ### if [ -z "${NEXTCLOUD_PASSWORD_SALT}" -a -z "`grep ^NEXTCLOUD_PASSWORD_SALT ${configfile}`" ] then # add empty parameter if it doesn't exist echo "NEXTCLOUD_PASSWORD_SALT=''" >> ${configfile} fi if [ -z "${NEXTCLOUD_PASSWORD_SALT}" ] then # secret not yet set /usr/bin/php -r "error_reporting(0); include('${nextcloud_path}/config/config.php'); print(\$CONFIG['passwordsalt']);" 2>/dev/null | \ grep -vi "array" > ${tmp_file} password_salt="`cat ${tmp_file} | sed 's/ *//g'`" rm -f ${tmp_file} if [ -n "${password_salt}" ] then # value found in Nextcloud configuration, save it ... mecho -n "writing password salt to configuration ..." # echo "SECRET:${password_salt}" sed "s|^\(NEXTCLOUD_PASSWORD_SALT\)=.*\( *# .*\)$|\1='${password_salt}' \2|" ${configfile} >${configfile}.tmp cp ${configfile}.tmp ${configfile} rm -f ${configfile}.tmp echo --info "done." fi fi chmod 0600 ${configfile} sleep 3 fi exit 0