File: //proc/self/root/scripts.20110531.215904.25158/builddovecotconf
#!/usr/bin/perl
# cpanel - builddovecotconf 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 Cpanel::Config ();
use Cpanel::AdvConfig ();
use Cpanel::AdvConfig::dovecot ();
use Cpanel::AdvConfig::dovecot::utils ();
use Cpanel::Usage ();
use Cpanel::FileUtils::TouchFile ();
my $force = 0;
my $leave_broken = 0;
my $now = time();
Cpanel::Usage::wrap_options( \@ARGV, \&usage, { 'force' => \$force, 'leave-broken' => \$leave_broken } );
my $cpconf_ref = Cpanel::Config::loadcpconf();
if ( !defined( $cpconf_ref->{'mailserver'} ) || $cpconf_ref->{'mailserver'} ne 'dovecot' ) {
print "This system is not currently configured to use the Dovecot mailserver.\n";
print "Use /scripts/setupmailserver to change this setting.\n";
exit 0;
}
if ( $> != 0 ) {
die "Insufficient permissions to rebuild dovecot.conf";
}
my $dovecot_conf = Cpanel::AdvConfig::dovecot::utils::find_dovecot_conf();
my ( $returnval, $message ) = Cpanel::AdvConfig::generate_config_file( { 'service' => 'dovecot', 'force' => $force, '_target_conf_file' => $dovecot_conf . '.' . $now } );
if ( !$returnval ) {
print "Failed to build $dovecot_conf\n$message\n";
unlink $dovecot_conf . '.' . $now;
exit 1;
}
( $returnval, $message ) = Cpanel::AdvConfig::dovecot::check_syntax( $dovecot_conf . '.' . $now );
if ( !$returnval ) {
print <<"EOM";
Configuration generation failed with the following message:
$message
EOM
unless ($force) {
unlink $dovecot_conf . '.' . $now unless ($leave_broken);
exit 1;
}
}
# This will be cached, so there's no big hit
my $conf_hr = Cpanel::AdvConfig::dovecot::get_config();
if ( $conf_hr->{'protocols'} =~ /imap(\s|$)/ ) {
unlink '/var/cpanel/imap_tcp_check_disabled' if ( -e '/var/cpanel/imap_tcp_check_disabled' );
}
else {
Cpanel::FileUtils::TouchFile::touchfile('/var/cpanel/imap_tcp_check_disabled') unless ( -e '/var/cpanel/imap_tcp_check_disabled' );
}
unlink $dovecot_conf;
rename $dovecot_conf . '.' . $now, $dovecot_conf;
unlink $dovecot_conf . '.datastore'; # Just in case
sub usage {
print <<EO_USAGE;
Usage: builddovecotconf [options]
Options:
--help Brief help message
--force Force installation of new conf file even if syntax check fails
--leave-broken Leave broken dovecot.conf on the disk so that it can be manually examined
EO_USAGE
exit 0;
}