From 02bb615327be128898c7a759111fa2834a5baf78 Mon Sep 17 00:00:00 2001
From: Adam Wujek <adam.wujek@cern.ch>
Date: Fri, 12 Aug 2016 15:21:54 +0200
Subject: [PATCH] rootfs: use /etc/ppsi.conf not /wr/etc/ppsi.conf

Keep created ppsi.conf in /etc not in /wr/etc.
There is no need to keep it in the flash instead of ramdisk.

Signed-off-by: Adam Wujek <adam.wujek@cern.ch>
---
 doc/wrs-user-manual.in                                 |  2 +-
 userspace/rootfs_override/var/www/functions.php        | 10 +++++-----
 userspace/rootfs_override/var/www/ptp.php              |  2 +-
 userspace/rootfs_override/wr/bin/apply_dot-config      | 10 +++-------
 userspace/rootfs_override/wr/bin/assembly_ppsi_conf.sh |  2 +-
 5 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/doc/wrs-user-manual.in b/doc/wrs-user-manual.in
index f09638cb9..4cfef92b0 100644
--- a/doc/wrs-user-manual.in
+++ b/doc/wrs-user-manual.in
@@ -935,7 +935,7 @@ in @ref{wrs_vlans}.
 In addition to that, to have synchronization working with VLANs, you have to
 prepare a custom @i{PPSi} configuration file with VLANs specified per-port. You
 can simply copy the file generated in the WRS filesystem
-(@i{/wr/etc/ppsi.conf}) to a central @t{tftp}/@t{http}/@t{ftp} server where
+(@i{/etc/ppsi.conf}) to a central @t{tftp}/@t{http}/@t{ftp} server where
 @i{dot-config} files for your switches are stored and fetched on boot time.
 For every VLAN-enabled port you should add the following line:
 @example
diff --git a/userspace/rootfs_override/var/www/functions.php b/userspace/rootfs_override/var/www/functions.php
index b659b47c4..56b853c80 100644
--- a/userspace/rootfs_override/var/www/functions.php
+++ b/userspace/rootfs_override/var/www/functions.php
@@ -3,7 +3,7 @@
 //Global Variables
 $etcdir="/usr/wr/etc/"; //configuration file folder for WRS
 $snmpconf="snmpd.conf";
-$ppsiconf="ppsi-pre.conf";
+$ppsipreconf="ppsi-pre.conf";
 $sfpdatabaseconf="sfp_database.conf";
 $wrdateconf="wr_date.conf";
 $vlancolor = array("#27DE2A", "#B642A8", "#6E42B6", "#425DB6" , "#428DB6", "#4686B6", "#43B88B", "#42B65F", "#82B642", "#B6AE42", "#B67E42");
@@ -883,16 +883,16 @@ function wrs_ptp_configuration(){
 		header('Location: ptp.php');
 	}
 	if (!empty($_POST["clkclass"])){
-		$old_value= rtrim(shell_exec("cat ".$GLOBALS['etcdir'].$GLOBALS['ppsiconf']." | grep class "));
+		$old_value= rtrim(shell_exec("cat ".$GLOBALS['etcdir'].$GLOBALS['ppsipreconf']." | grep class "));
 		$new_value="clock-class ".htmlspecialchars($_POST["clkclass"]);
-		$sed = 'sed -i "s/'.$old_value.'/'.$new_value.'/g" '.$GLOBALS['etcdir'].$GLOBALS['ppsiconf'];echo $sed;
+		$sed = 'sed -i "s/'.$old_value.'/'.$new_value.'/g" '.$GLOBALS['etcdir'].$GLOBALS['ppsipreconf'];echo $sed;
 		shell_exec($sed);
 		echo '<br>Clock Class changed to '.htmlspecialchars($_POST["clkclass"]);
 	}
 	if (!empty($_POST["clkacc"])){
-		$old_value= rtrim(shell_exec("cat ".$GLOBALS['etcdir'].$GLOBALS['ppsiconf']." | grep accuracy "));
+		$old_value= rtrim(shell_exec("cat ".$GLOBALS['etcdir'].$GLOBALS['ppsipreconf']." | grep accuracy "));
 		$new_value="clock-accuracy ".htmlspecialchars($_POST["clkacc"]);
-		$sed ='sed -i "s/'.$old_value.'/'.$new_value.'/g" '.$GLOBALS['etcdir'].$GLOBALS['ppsiconf'];echo $sed;
+		$sed ='sed -i "s/'.$old_value.'/'.$new_value.'/g" '.$GLOBALS['etcdir'].$GLOBALS['ppsipreconf'];echo $sed;
 		shell_exec($sed);
 		echo '<br>Clock Accuracy changed to '.htmlspecialchars($_POST["clkacc"]);
 	}
diff --git a/userspace/rootfs_override/var/www/ptp.php b/userspace/rootfs_override/var/www/ptp.php
index 529386393..f3a72a95a 100644
--- a/userspace/rootfs_override/var/www/ptp.php
+++ b/userspace/rootfs_override/var/www/ptp.php
@@ -84,6 +84,7 @@
 		$section = "WRS_FORMS";
 		$subsection = "CONFIG_PPSI";
 
+		wrs_ptp_configuration();
 		$_SESSION["WRS_FORMS"]["CONFIG_PPSI"][CONFIG_PPSI_00]["value"]=
 			shell_exec("cat /wr/etc/ppsi-pre.conf | grep clock-class | awk '{print $2}'");
 		$_SESSION["WRS_FORMS"]["CONFIG_PPSI"][CONFIG_PPSI_01]["value"]=
@@ -91,7 +92,6 @@
 
 		print_form($section, $subsection, $formatID, $class, $infoname, $format);
 
-		wrs_ptp_configuration();
 		wrs_management();
 
 		if ((!empty($_POST["modegroup"]))){
diff --git a/userspace/rootfs_override/wr/bin/apply_dot-config b/userspace/rootfs_override/wr/bin/apply_dot-config
index 5e00f0a25..f9ed4de37 100755
--- a/userspace/rootfs_override/wr/bin/apply_dot-config
+++ b/userspace/rootfs_override/wr/bin/apply_dot-config
@@ -108,7 +108,7 @@ copy_conf /wr/etc/snmpd.conf
 if [ "$CONFIG_PTP_PORT_PARAMS" = "y" ]; then
     /wr/bin/assembly_ppsi_conf.sh
 elif [ "$CONFIG_PTP_CUSTOM" = "y" ]; then
-    cp "$CONFIG_PTP_CUSTOM_FILENAME" /wr/etc/ppsi.conf
+    cp "$CONFIG_PTP_CUSTOM_FILENAME" /etc/ppsi.conf
 elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
 
     # Warning: code below copied from /etc/init.d/dot-config.
@@ -144,14 +144,10 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
 	    ;;
     esac
     if [ -f $tmpconfig ]; then
-	    # copy it in place to use the new file (unless it is identical)
-	    cmp -s $tmpconfig /wr/etc/ppsi.conf || \
-		cp $tmpconfig /wr/etc/ppsi.conf
+	# copy it in place to use the new file
+	cp $tmpconfig /etc/ppsi.conf
     fi
 else
     # no valid PTP option keep ppsi.conf with old postfix
     echo "No valid PTP option in dot-config!" >& 2
-    if [ -f /wr/etc/ppsi.conf ]; then
-	mv -f /wr/etc/ppsi.conf /wr/etc/ppsi.conf.old
-    fi
 fi
diff --git a/userspace/rootfs_override/wr/bin/assembly_ppsi_conf.sh b/userspace/rootfs_override/wr/bin/assembly_ppsi_conf.sh
index d92f42e2d..036f982bf 100755
--- a/userspace/rootfs_override/wr/bin/assembly_ppsi_conf.sh
+++ b/userspace/rootfs_override/wr/bin/assembly_ppsi_conf.sh
@@ -4,7 +4,7 @@
 # script to assembly ppsi.conf based on dot-config configuration
 
 PRE_FILE="/wr/etc/ppsi-pre.conf"
-OUTPUT_FILE="/wr/etc/ppsi.conf"
+OUTPUT_FILE="/etc/ppsi.conf"
 
 if [ -f /wr/etc/dot-config ]; then
     . /wr/etc/dot-config
-- 
GitLab