summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--scripts/system/vyatta_update_console.pl73
-rw-r--r--templates/system/console/node.def7
-rw-r--r--templates/system/console/node.tag/speed/node.def6
4 files changed, 87 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 1e7b1fcc..b4cfbe92 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,6 +28,7 @@ sbin_SCRIPTS += scripts/system/vyatta_update_login.pl
sbin_SCRIPTS += scripts/system/vyatta_update_logrotate.pl
sbin_SCRIPTS += scripts/system/vyatta_update_resolv.pl
sbin_SCRIPTS += scripts/system/vyatta_update_syslog.pl
+sbin_SCRIPTS += scripts/system/vyatta_update_console.pl
sbin_SCRIPTS += scripts/system/vyatta_update_ntp.pl
sbin_SCRIPTS += scripts/system/vyatta_update_telnet
sbin_SCRIPTS += scripts/snmp/vyatta-snmp.pl
diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl
new file mode 100644
index 00000000..84cf7488
--- /dev/null
+++ b/scripts/system/vyatta_update_console.pl
@@ -0,0 +1,73 @@
+#! /usr/bin/perl
+
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc.
+# All Rights Reserved.
+#
+# **** End License ****
+
+# Update console configuration in /etc/inittab and grub
+# based on Vyatta configuration
+
+use strict;
+use lib "/opt/vyatta/share/perl5";
+use Vyatta::Config;
+use File::Compare;
+use File::Copy;
+
+my $INITTAB = "/etc/inittab";
+my $TMPTAB = "/tmp/inittab.$$";
+
+die "$0 expects no arguments\n" if (@ARGV);
+
+sub update_inittab {
+ open (my $inittab, '<', $INITTAB)
+ or die "Can't open $INITTAB";
+
+ open (my $tmp, '>', $TMPTAB)
+ or die "Can't open $TMPTAB";
+
+ # Clone original inittab but remove all references to serial lines
+ print {$tmp} grep { ~ /^T/ } <$inittab>;
+ close $inittab;
+
+ my $config = new Vyatta::Config;
+ $config->setLevel("system console");
+
+ my $id = 0;
+ foreach my $tty ($config->listNodes()) {
+ my $speed = $config->returnValue("$tty speed");
+ $speed = 9600 unless $speed;
+
+ print {$tmp} "T$id:23:respawn:/sbin/getty $speed $tty";
+ ++$id;
+ }
+ close $tmp;
+
+ if ( compare($INITTAB, $TMPTAB) != 0) {
+ copy($TMPTAB, $INITTAB)
+ or die "Can't copy $TMPTAB to $INITTAB";
+ kill 1, 1; # Send init standard signal to reread table
+ }
+ unlink($TMPTAB);
+}
+
+sub update_grub {
+ # TBD
+}
+
+update_inittab();
+
+update_grub();
+
+exit 0;
diff --git a/templates/system/console/node.def b/templates/system/console/node.def
new file mode 100644
index 00000000..9e946c7e
--- /dev/null
+++ b/templates/system/console/node.def
@@ -0,0 +1,7 @@
+tag:
+type: txt
+help: Serial console configuration
+allowed: (cd $dev; echo tty*)
+syntax:expression: pattern $VAR(@) "^tty[A-Z0-9]+$" \
+ ; "console $VAR(@): not a valid tty name"
+end: /opt/vyatta/sbin/vyatta_update_console.pl
diff --git a/templates/system/console/node.tag/speed/node.def b/templates/system/console/node.tag/speed/node.def
new file mode 100644
index 00000000..cf2a0d09
--- /dev/null
+++ b/templates/system/console/node.tag/speed/node.def
@@ -0,0 +1,6 @@
+type: u32
+help: Console baud rate
+allowed: echo 1200 2400 4800 9600 19200 38400 57600 115200
+syntax:expression: $VAR(@) in 1200 2400 4800 9600 19200 38400 57600 115200 ;
+ "unknown baud rate"
+val_help: u32: 1200-115200: Baud rate for console port