[Devel] [PATCH] Backup network config file if it lacks of warning

Igor Podlesny openvz at poige.ru
Tue Apr 30 16:44:37 PDT 2013


We do warn a user to not edit network config file since it can be
overwritten, but we do this placing our warning inside overwritten file
-- it's too late. Let's at least make a copy.
---
 etc/dists/scripts/debian-add_ip.sh |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/etc/dists/scripts/debian-add_ip.sh b/etc/dists/scripts/debian-add_ip.sh
index 0fb1f36..2ba555a 100755
--- a/etc/dists/scripts/debian-add_ip.sh
+++ b/etc/dists/scripts/debian-add_ip.sh
@@ -38,9 +38,18 @@ fix_networking_conf()
 
 setup_network()
 {
+	local dont_edit='WARNING: Do not edit this file'
+	[ -r "$CFGFILE" ] &&
+		head -n20 "$CFGFILE" | fgrep -q -- "$dont_edit" || {
+			# -- It has no our warning inside, so we'd better
+			# back it up:
+			cp "$CFGFILE" \
+				"${CFGFILE}-$(date --rfc-3339=seconds).bak"
+		}
+
 	echo "# This configuration file is auto-generated.
 #
-# WARNING: Do not edit this file, your changes will be lost.
+# $dont_edit, your changes will be lost.
 # Please create/edit $CFGFILE.head and
 # $CFGFILE.tail instead, their contents will be
 # inserted at the beginning and at the end of this file, respectively.
-- 
1.7.9.5




More information about the Devel mailing list