summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorBrandon Stepler <brandon@stepler.net>2021-03-04 16:30:00 -0500
committerChristian Poessinger <christian@poessinger.com>2021-03-18 17:24:43 +0100
commit00082c9b6704fbf026758ae381867e8d471b56da (patch)
tree1af0291a19f4a432bd3076eaf490cee954a8d37f /src/conf_mode
parentc59fdc6b92c996762bc2cdcdfb501b009b83b452 (diff)
downloadvyos-1x-00082c9b6704fbf026758ae381867e8d471b56da.tar.gz
vyos-1x-00082c9b6704fbf026758ae381867e8d471b56da.zip
grub: T3271: don't write grub.cfg if it hasn't changed
(cherry picked from commit 658456982ad4543790a3835f6ddbfbe3b583ec44)
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/system_console.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/conf_mode/system_console.py b/src/conf_mode/system_console.py
index b17818797..33a546bd3 100755
--- a/src/conf_mode/system_console.py
+++ b/src/conf_mode/system_console.py
@@ -17,9 +17,8 @@
import os
import re
-from fileinput import input as replace_in_file
from vyos.config import Config
-from vyos.util import call
+from vyos.util import call, read_file, write_file
from vyos.template import render
from vyos import ConfigError, airbag
airbag.enable()
@@ -98,15 +97,27 @@ def generate(console):
if not os.path.isfile(grub_config):
return None
- # stdin/stdout are redirected in replace_in_file(), thus print() is fine
+ lines = read_file(grub_config).split('\n')
+
p = re.compile(r'^(.* console=ttyS0),[0-9]+(.*)$')
- for line in replace_in_file(grub_config, inplace=True):
+ write = False
+ newlines = []
+ for line in lines:
if line.startswith('serial --unit'):
- line = f'serial --unit=0 --speed={speed}\n'
+ newline = f'serial --unit=0 --speed={speed}'
elif p.match(line):
- line = '{},{}{}\n'.format(p.search(line)[1], speed, p.search(line)[2])
+ newline = '{},{}{}'.format(p.search(line)[1], speed, p.search(line)[2])
+ else:
+ newline = line
+
+ if newline != line:
+ write = True
+
+ newlines.append(newline)
+ newlines.append('')
- print(line, end='')
+ if write:
+ write_file(grub_config, '\n'.join(newlines))
return None