diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-06-11 14:32:36 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-06-11 14:32:36 +0200 |
commit | d135e1b7b02b99b8b1f0a6232bc1c6e89abcdf4b (patch) | |
tree | 8c60b2a758e091d0f96dc8f53725844b7212c6c8 /src/conf_mode/system_console.py | |
parent | e45f8c9ccb7d192887375bfee9fc6357f4811654 (diff) | |
download | vyos-1x-d135e1b7b02b99b8b1f0a6232bc1c6e89abcdf4b.tar.gz vyos-1x-d135e1b7b02b99b8b1f0a6232bc1c6e89abcdf4b.zip |
console: T2569: replicate console settings to grub.cfg
Diffstat (limited to 'src/conf_mode/system_console.py')
-rwxr-xr-x | src/conf_mode/system_console.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/conf_mode/system_console.py b/src/conf_mode/system_console.py index 6d60a9d4d..59a064b3a 100755 --- a/src/conf_mode/system_console.py +++ b/src/conf_mode/system_console.py @@ -15,7 +15,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os +import re +from fileinput import input as replace_in_file from vyos.config import Config from vyos.util import call from vyos.template import render @@ -78,6 +80,28 @@ def generate(console): # Reload systemd manager configuration call('systemctl daemon-reload') + + # GRUB + # For existing serial line change speed (if necessary) + # Only applys to ttyS0 + if 'ttyS0' not in console['device'].keys(): + return None + + speed = console['device']['ttyS0']['speed'] + grub_config = '/boot/grub/grub.cfg' + if not os.path.isfile(grub_config): + return None + + # stdin/stdout are redirected in replace_in_file(), thus print() is fine + p = re.compile(r'^(.* console=ttyS0),[0-9]+(.*)$') + for line in replace_in_file(grub_config, inplace=True): + if line.startswith('serial --unit'): + line = f'serial --unit=0 --speed={speed}\n' + elif p.match(line): + line = '{},{}{}\n'.format(p.search(line)[1], speed, p.search(line)[2]) + + print(line, end='') + return None def apply(console): |