#!/usr/bin/env perl # Shared with permission use strict; use warnings; my @files = @ARGV; die if ( not defined $files[0] ); foreach my $file (@files) { my ( $fh, $byte ); open( $fh, "+<", "$file" ) or die "can't open flar"; print "Searching for content_architectures at top of flar...\n"; my ( $last_position, $current_position ); while (<$fh>) { $current_position = tell($fh); if ( $current_position > 800 ) { print "ERROR: failed to find content_architectures...\n\n"; exit; } if (/^content_architectures/) { last; } $last_position = $current_position; } print "Found line at byte $last_position to $current_position\n"; my $lineLength = $current_position - $last_position; my $valueLength = $lineLength - 23; if ( $valueLength < 5 ) { print "ERROR: Can't replace value inline. Current value of content_architectures is too short.\n"; exit; } my $numSpaces = $valueLength - 5; seek( $fh, $last_position + 22, 0 ); sysread( $fh, $byte, $lineLength - 23 ); print "Replacing \n"; print "~~$byte~~\n"; my $replacementString = "sun4v" . " " x $numSpaces; print "with\n"; print "~~$replacementString~~\n"; print "completed successfully.\n"; seek( $fh, $last_position + 22, 0 ); syswrite( $fh, $replacementString ) == $valueLength or die "write failed: $!\n"; print "NEW HEADER:\n"; seek( $fh, 0, 0 ); while (<$fh>) { last if (/^begin/); print $_; } close $fh; print "\n"; }