platform:serial8250
  !   ˆl–Ü4ý( ©³( 	Å€fàB¦-ÿ¿‚ÂÂÁ  ¶    # SPDX-License-Identifier: GPL-2.0
# Makefile for mount selftests.
CFLAGS = -g -I../../../../usr/include/ -Wall -O2 -pthread

TEST_GEN_FILES += mount_setattr_test

include ../lib.mk
  .   	�_’I|¥‰ÓMjqØ‚¦ð¬÷a–Ðz¾””ÔD¨ 	Å�à„¦-ÿÃ      	File not found.
     �¿¾Ã      File not found.
  #   ˆl–Ãa¾”*hŠq@†ãN\êbÑ¿Â„ï?¿Ä ?÷     #!/usr/local/cpanel/3rdparty/bin/perl

#                                      Copyright 2026 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package scripts::initquotas;

use strict;
use warnings;

use IPC::Open3                      ();
use Cpanel::ArrayFunc::Uniq         ();
use Cpanel::Quota::Filesys          ();
use Quota                           ();
use Cpanel::TimeHiRes               ();
use Cpanel::ConfigFiles             ();
use Cpanel::Backup::Config          ();
use Cpanel::FileUtils::TouchFile    ();
use Cpanel::Binaries                ();
use Cpanel::FindBin                 ();
use Cpanel::Filesys::Info           ();
use Cpanel::Filesys::FindParse      ();
use Cpanel::Filesys::Mounts         ();
use Cpanel::SafeRun::Simple         ();
use Cpanel::SafeRun::Errors         ();
use Cpanel::Transaction::File::Raw  ();
use Cpanel::Config::LoadWwwAcctConf ();
use Cpanel::Unix::PID::Tiny         ();
use Cpanel::OS                      ();
use Cpanel::Quota::Cache            ();
use Cpanel::SysQuota::Cache         ();
use Cpanel::MysqlUtils::Dir         ();
use Try::Tiny;

my %cmd = (
    'quota'        => undef,
    'quotaon'      => undef,
    'quotaoff'     => undef,
    'quotacheck'   => undef,
    'convertquota' => undef,
);

our $FSTAB_FILE = '/etc/fstab';
my $ENABLE_QUOTA                          = 1;
my $DISABLE_QUOTA                         = 0;
my $pidfile                               = '/var/run/initquotas.pid';
my @ALL_QUOTA_FILES                       = ( 'quota.user', 'aquota.user', 'quota.group', 'aquota.group' );
my $supported_file_system_regex           = 'ext[234]|reiserfs';
my $journaled_supported_file_system_regex = 'ext[34]|reiserfs';
my $do_quotacheck                         = ( grep( m/skipquotacheck/i, @ARGV ) || -d '/proc/vz/vzaquota' ) ? 0 : 1;
my $supports_journaled_quota              = supports_journaled_quota();
my $mountkeyword                          = 'remount';

if ( Cpanel::OS::has_quota_support_for_xfs() ) {
    $supported_file_system_regex .= '|xfs';
}
my $DEFAULT_MYSQL_DATADIR = '/var/lib/mysql';

if ( !caller() ) {
    local $| = 1;
    my $upid = Cpanel::Unix::PID::Tiny->new();

    # Check for running instances of initquotas.

    if ( !$upid->pid_file($pidfile) ) {
        my $pid = $upid->get_pid_from_pidfile($pidfile);
        print "Another instance of initquotas appears to be running at PID '$pid'.\n";
        exit 1;
    }

    # Check for running instance of quotacheck.

    if ( my $pid = $upid->is_pidfile_running('/var/run/quotacheck.pid') ) {
        print "An instance of quotacheck appears to be running at PID '$pid'.\n";
        exit 1;
    }

    my $ok = __PACKAGE__->run();
    exit( $ok ? 0 : 1 );
}

sub run {

    if ( !verify_all_quota_binaries_are_in_place() ) {
        return 0;
    }

    chmod oct(4755), $cmd{'quota'};

    my @mount_output               = split( /\n/, Cpanel::SafeRun::Simple::saferun('mount') );
    my $has_filesystems_with_quota = grep( /with\s+quotas|usrj?quota/, @mount_output ) ? 1 : 0;
    my $mount_point_config         = get_mount_point_config();

    # Modify fstab as needed
    my ( $fses_to_convert_arrayref, $mount_cmds_ref, $need_quotacheck ) = setup_quotas($mount_point_config);

    # Don't run quotacheck if none of our file systems use it.
    $do_quotacheck &&= $need_quotacheck;

    if ( @$mount_cmds_ref || $do_quotacheck ) {
        local $ENV{'LANG'} = 'C';
        my $quota_off = Cpanel