edquota_editor 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/perl -w
  2. use strict;
  3. die "QUOTA_USER environment variable not set\n" unless defined $ENV{'QUOTA_USER'};
  4. die "QUOTA_FILESYS environment variable not set\n" unless defined $ENV{'QUOTA_FILESYS'};
  5. die "QUOTA_SBLOCKS environment variable not set\n" unless defined $ENV{'QUOTA_SBLOCKS'};
  6. die "QUOTA_HBLOCKS environment variable not set\n" unless defined $ENV{'QUOTA_HBLOCKS'};
  7. die "QUOTA_SFILES environment variable not set\n" unless defined $ENV{'QUOTA_SFILES'};
  8. die "QUOTA_HFILES environment variable not set\n" unless defined $ENV{'QUOTA_HFILES'};
  9. open FILE, $ARGV[0];
  10. my $qdata = join '', (@_=<FILE>);
  11. close FILE;
  12. open FILE, ">$ARGV[0]";
  13. print FILE &edit_quota_file($qdata, $ENV{'QUOTA_FILESYS'}, $ENV{'QUOTA_SBLOCKS'}, $ENV{'QUOTA_HBLOCKS'}, $ENV{'QUOTA_SFILES'}, $ENV{'QUOTA_HFILES'});
  14. close FILE;
  15. # edit_quota_file(data, filesys, sblocks, hblocks, sfiles, hfiles)
  16. sub edit_quota_file {
  17. my($rv, $line, @line, $i);
  18. @line = split /\n/, $_[0];
  19. for ( $i=0; $i<@line; $i++ ) {
  20. if ($line[$i] =~ /^\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/ && ($1 eq $_[1] || $_[1] eq '*')) {
  21. # new-style line to change
  22. $rv .= " $1 $2 $_[2] $_[3] $5 $_[4] $_[5]\n";
  23. } else {
  24. $rv .= "$line[$i]\n";
  25. }
  26. }
  27. return $rv;
  28. }