File: //proc/self/root/scripts.20110531.215904.25158/fixquotas
#!/usr/bin/perl
# cpanel - fixquotas Copyright(c) 2010 cPanel, Inc.
# All Rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use strict;
use IPC::Open2 ();
use Cpanel::FindBin ();
use Cpanel::SafeRun::Errors ();
my %cmd = (
'quotaon' => undef,
'quotaoff' => undef,
);
my @missing_cmds;
foreach my $cmd_name ( keys %cmd ) {
$cmd{$cmd_name} = Cpanel::FindBin::findbin($cmd_name);
if ( !-x $cmd{$cmd_name} ) {
push @missing_cmds, $cmd_name;
}
}
if ( scalar @missing_cmds ) {
print "Incomplete quota kit: unable to fix quotas.\n";
print 'Missing commands: ', join( ', ', @missing_cmds ), "\n";
exit 1;
}
my $system = $^O;
# Exclude running quotaoff on FreeBSD as it might have been manually set to on
if ( $system !~ m/freebsd/i ) {
Cpanel::SafeRun::Errors::saferunnoerror( $cmd{'quotaoff'}, '-a' );
system 'cp -f /etc/fstab /etc/fstab.quotas';
}
$| = 1;
print "Installing Default Quota Databases...";
if ( open FTQ, '/etc/fstab.quotas' ) {
while (<FTQ>) {
my $line = $_;
/^(\S+)/;
my $dsk = $1;
$dsk =~ s/^LABEL=//g;
if ( $line =~ /ext(?:2|3|4)|reiserfs/ ) {
if (/defaults/) {
if ( $line =~ /\S+\s*(\S+)/ ) {
my $mntpoint = $1;
$mntpoint =~ s/\/$//g;
unlink "${mntpoint}/aquota.user.new";
unlink "${mntpoint}/quota.user.new";
zinstall( "/scripts/aquota.user_emptyfs.gz", "$mntpoint/aquota.user" );
zinstall( "/scripts/quota.user_emptyfs.gz", "$mntpoint/quota.user" );
}
}
}
}
close FTQ;
print "...Done\n";
}
else {
print "\nUnable to determine filesystems with quotas enabled\n";
exit 1;
}
system '/scripts/initquotas';
# Exclude running reset on FreeBSD as it might have been manually set
if ( $system !~ m/freebsd/i ) {
system '/scripts/resetquotas';
}
Cpanel::SafeRun::Errors::saferunnoerror( $cmd{'quotaon'}, '-a' );
sub zinstall {
my ( $file, $dest ) = @_;
open( RFILE, $file );
binmode RFILE;
my $pid = IPC::Open2::open2( \*GZIPR, \*GZIPW, "gzip", "-df" );
binmode GZIPW;
binmode GZIPR;
while (<RFILE>) {
print GZIPW $_;
}
close(RFILE);
close(GZIPW);
open( DEST, ">", $dest );
binmode DEST;
while (<GZIPR>) {
print DEST $_;
}
close(DEST);
waitpid $pid, 0;
print "..${dest}..";
}