]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
host examination: bootloader: Do not use ed
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 17 May 2017 20:45:37 +0000 (21:45 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 18 May 2017 11:01:17 +0000 (12:01 +0100)
These ed runes are what I used to develop this approach, but they are
rather opaque to those very few programmers who are not proficient
users of ed, the standard text editor.

Also, using target_editfile_root means we keep a record of the
bootloader config in the logs, which is desirable.

The regexps used to edit the grub2 confiug are slightly more
sophisticated than the ed ones were.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
ts-examine-serial-pre

index 26fbc56598b276dbd6a9a39929c02e025de208c7..86f332f61479e2d1257fd5230aaad7bb62d7c077 100755 (executable)
@@ -61,35 +61,34 @@ END
 
 sub bootloader () {
     my $c = get_cookie('bootloader');
-    my $ed = sub {
-       my ($file,$script) = @_;
-       my $cmd = <<END;
-            ed $file <<EOF
-$script
-w
-q
-EOF
-END
-       $cmd .= setupboot_bootloader_edited_rune($ho);
-       target_cmd_root($ho, $cmd, 200);
+    my $edit = sub {
+       my ($file,$editor) = @_;
+       target_editfile_root($ho,$file,$editor);
+       target_cmd_root($ho, setupboot_bootloader_edited_rune($ho), 200);
     };
     my $edscript;
     if ($ho->{Flags}{'need-uboot-bootscr'}) {
-       $ed->('/boot/boot.xen',<<END)
-/^echo Loaded
-i
-echo osstest uboot $c
-.
-END
+       $edit->('/boot/boot.xen', sub {
+            my $done;
+            while (<::EI>) {
+               if (m/^echo Loaded/ && !$done++) {
+                   print ::EO "echo osstest uboot $c\n";
+               }
+               print ::EO;
+           }
+       });
     } else {
-       $ed->('/boot/grub/grub.cfg',<<END); # no support for grub1
-1 
-/^ *menuentry  *
-s/'\([^']*\)'/'$c \1'
-1
-/^ *submenu  *
-s
-END
+       # no support for grub1
+       $edit->('/boot/grub/grub.cfg', sub {
+            my %done;
+            while (<::EI>) {
+               s{^(\s* ( menuentry | submenu ) \s+
+                     (['"]) )( [^'"]+ \3) }{
+                    $done{$2}++ ? $& : "$1$c $4"
+                }xe;
+               print ::EO;
+           }
+       });
     }
 }