summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/rl-system.init11
-rwxr-xr-xscripts/system/vyatta_update_console.pl92
2 files changed, 51 insertions, 52 deletions
diff --git a/scripts/rl-system.init b/scripts/rl-system.init
index 5c8ba7a6..fddea32a 100755
--- a/scripts/rl-system.init
+++ b/scripts/rl-system.init
@@ -10,10 +10,9 @@
# General Public License for more details.
#
# This code was originally developed by Vyatta, Inc.
-# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# Copyright (C) 2007-2010 Vyatta, Inc.
# All Rights Reserved.
#
-# Author: Tom Grennan <tgrennan@vyatta.com>
# Description: Vyatta Router system setup
# Indirect init sub-script of vyatta-router.init
#
@@ -222,9 +221,6 @@ start () {
# Remove links from the commit hook directory
rm -f /etc/commit/*
- # Remove serial console settings
-# sed -i -e '/^T/d' /etc/inittab
-
## Clear out apt config file--it will be filled in by config load
empty /etc/apt/sources.list
}
@@ -237,8 +233,3 @@ case "$ACTION" in
esac
exit $?
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 4
-# End:
diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl
index 8fbb82a4..5045a0dd 100755
--- a/scripts/system/vyatta_update_console.pl
+++ b/scripts/system/vyatta_update_console.pl
@@ -20,6 +20,8 @@
# based on Vyatta configuration
use strict;
+use warnings;
+
use lib "/opt/vyatta/share/perl5";
use Vyatta::Config;
use File::Compare;
@@ -27,24 +29,30 @@ use File::Copy;
die "$0 expects no arguments\n" if (@ARGV);
+# if file is unchanged, do nothing and return false
+# otherwise update to new version
sub update {
- my ($inpath, $outpath) = @_;
-
- if ( compare($inpath, $outpath) != 0) {
- copy($outpath, $inpath)
- or die "Can't copy $outpath to $inpath";
+ my ($old, $new) = @_;
+
+ if ( compare($old, $new) != 0) {
+ move($new, $old)
+ or die "Can't move $new to $old";
+ return 1;
+ } else {
+ unlink($new);
+ return;
}
- unlink($inpath);
}
-sub update_inittab {
- my ($inpath, $outpath) = @_;
+my $INITTAB = "/etc/inittab";
+my $TMPTAB = "/tmp/inittab.$$";
- open (my $inittab, '<', $inpath)
- or return;
+sub update_inittab {
+ open (my $inittab, '<', $INITTAB)
+ or die "Can't open $INITTAB: $!";
- open (my $tmp, '>', $outpath)
- or die "Can't open $outpath: $!";
+ 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>;
@@ -57,28 +65,35 @@ sub update_inittab {
foreach my $tty ($config->listNodes()) {
my $speed = $config->returnValue("$tty speed");
$speed = 9600 unless $speed;
- my $type = $config->returnValue("$tty type");
-
- print {$tmp} "T$id:23:respawn:";
- # Three cases modem, direct, and normal
- if ($type eq "modem") {
- print {$tmp} "/sbin/mgetty -x0 -s";
+ print {$tmp} "T$id:23:respawn:";
+ if ($config->exists("$tty modem")) {
+ printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty;
} else {
- print {$tmp} "/sbin/getty";
- print {$tmp} " -L" if ($type eq "direct");
+ printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed;
+ }
+
+ # Limit to 0-9 because of limitation of last char in id field
+ if (++$id >= 10) {
+ warn "Ignoring $tty only 10 serial devices supported\n";
+ last;
}
- print {$tmp} "$speed $tty\n";
- ++$id;
}
close $tmp;
- update($inpath, $outpath);
+ if (update($INITTAB, $TMPTAB)) {
+ # This is same as telinit q - it tells init to re-examine inittab
+ kill 1, 1;
+ }
}
+my $GRUBCFG = "/boot/grub/grub.cfg";
+my $GRUBTMP = "/tmp/grub.cfg.$$";
+
# For existing serial line change speed (if necessary)
+# Only applys to ttyS0
sub update_grub {
- my ($inpath, $outpath) = @_;
+ return unless (-f $GRUBCFG);
my $config = new Vyatta::Config;
$config->setLevel("system console device");
@@ -87,35 +102,28 @@ sub update_grub {
my $speed = $config->returnValue("ttyS0 speed");
$speed = "9600" unless defined($speed);
- open (my $grub, '<', $inpath)
- or die "Can't open $inpath: $!";
- open (my $tmp, '>', $outpath)
- or die "Can't open $outpath: $!";
+ open (my $grub, '<', $GRUBCFG)
+ or die "Can't open $GRUBCFG: $!";
+
+ open (my $tmp, '>', $GRUBTMP)
+ or die "Can't open $GRUBTMP: $!";
- select $tmp;
while (<$grub>) {
if (/^serial / ) {
- print "serial --unit=0 --speed=$speed\n";
+ print {$tmp} "serial --unit=0 --speed=$speed\n";
} elsif (/^(.* console=ttyS0),[0-9]+ (.*)$/) {
- print "$1,$speed $2\n";
+ print {$tmp} "$1,$speed $2\n";
} else {
- print $_;
+ print {$tmp} $_;
}
}
close $grub;
close $tmp;
- select STDOUT;
- update($inpath, $outpath);
+ update($GRUBCFG, $GRUBTMP);
}
-my $INITTAB = "/etc/inittab";
-my $TMPTAB = "/tmp/inittab.$$";
-my $GRUBCFG = "/boot/grub/grub.cfg";
-my $GRUBTMP = "/tmp/grub.cfg.$$";
-
-update_inittab($INITTAB, $TMPTAB);
-
-update_grub($GRUBCFG, $GRUBTMP);
+update_inittab;
+update_grub;
exit 0;