home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # spuedit -- edit spu file from JP, keeping a backup
- # tom christiansen
-
- die "usage: $0 spufile ...\n" if $#ARGV < 0;
-
- die "$0: Not superuser\n" if $>;
-
- $editor = $ENV{'VISUAL'} || $ENV{'EDITOR'} || 'vi';
- $tmp = "/tmp/spuedit.$$";
- $status = 0;
- $| = 1;
-
- for $file (@ARGV) {
- system("/usr/convex/spu -r $file > $tmp\n") && exit(1);
-
- ($otime = (stat($tmp))[9])
- || die "$0: Can't stat $tmp: $!\n";
-
- system($editor,$tmp)
- && die "$0: Command \"$editor $tmp\" failed\n";
-
- ($ntime = (stat($tmp))[9])
- || die "$0: Can't stat $tmp: $!\n";
-
- if ($ntime > $otime) {
- print "copying file..";
- $cmd = "cp $file $file.bak";
- chop($output = `/usr/convex/spucmd $cmd 2>&1`);
- $status |= $?;
- if (($? >>= 8) || $output ne "+ $cmd ") {
- warn "spucmd \"$cmd\" failed:\n\t(status $?) \"$output\"\n";
- warn "temporary file saved to $tmp\n";
- } else {
- print "..";
- $status |= system("/usr/convex/spu -w $file < $tmp\n");
- print "done\n";
- }
- } else {
- warn "$0: Temporary file $tmp unmodified\n";
- $status |= 1;
- }
- unlink $tmp;
- }
-
- exit $status;
-