#!/usr/bin/perl

use strict;

my $dest = '/root/soft.sh';

if (-f $dest) {
	print STDERR "We've already have $dest. Erase it? (y/n) ";
	my $key = <STDIN>;
	$key =~ s/^\s+//;
	if ($key !~ /^[yY]/) {
		print STDERR "Giving up...\n";
		exit;
	}
}
open FSTAB, '< /etc/fstab' or die 'Cannot open /etc/fstab';
open SOFT, "> $dest" or die "Cannot open $dest."; 
print SOFT "#!/bin/sh\n";
while(<FSTAB>) {
	s/#.*$//;
	if (m!/dev/((ad|da|ar|twed|mlxd|idad)\d+s\d[defgh])\s+(\S+)\s+ufs\s+rw\s+!) {
		print SOFT "#Enable softupdates for /dev/$1 ($3)\n";
		print SOFT "tunefs -n enable $1\n";
	} 
}
close SOFT;
close FSTAB;
chmod 0755, $dest;
