ma
branchfoerste
changeset 48 36aca6fb0ab8
parent 44 35441e1ae083
child 54 1f74755c407e
equal deleted inserted replaced
47:05d5ada37387 48:36aca6fb0ab8
    59 use AppConfig qw(:expand);
    59 use AppConfig qw(:expand);
    60 use File::Basename;
    60 use File::Basename;
    61 use FindBin;
    61 use FindBin;
    62 use Carp;
    62 use Carp;
    63 
    63 
    64 use lib ("$FindBin::RealBin/..", "$FindBin::RealBin/../lib/ma");
    64 use lib ( "$FindBin::RealBin/..", "$FindBin::RealBin/../lib/ma" );
    65 use Common;
    65 use Common;
    66 use ldapBase;
    66 use ldapBase;
    67 
    67 
    68 use constant ME => basename $0;
    68 use constant ME => basename $0;
    69 our $Cf;
    69 our $Cf;
    70 
    70 
    71 sub help();
    71 sub help();
    72 
    72 
    73 my $Module = shift if @ARGV && $ARGV[0] !~ /^-/;
    73 my $Module = shift if @ARGV && $ARGV[0] !~ /^-/;
    74    $Module ||= "UNKNOWN";
    74 $Module ||= "UNKNOWN";
    75 
    75 
    76 
    76 $SIG{__DIE__} = sub { die "\n" . ME . ": ", @_ };
    77 $SIG{__DIE__} = sub { die "\n".ME.": ", @_ };
       
    78 
       
    79 
    77 
    80 MAIN: {
    78 MAIN: {
    81 
    79 
    82     $Cf = new AppConfig Common::CONFIG or die;
    80     $Cf = new AppConfig Common::CONFIG or die;
    83 
    81 
    84     if (exists $ENV{MA_CONF} and -f $ENV{MA_CONF}) {
    82     if ( exists $ENV{MA_CONF} and -f $ENV{MA_CONF} ) {
    85 	my $f = $ENV{MA_CONF};
    83         my $f = $ENV{MA_CONF};
    86 	die ": $f is group/world readable/writeable\n" if  077 & (stat _)[2];
    84         die ": $f is group/world readable/writeable\n" if 077 & ( stat _ )[2];
    87 	$Cf->file($f) or die;
    85         $Cf->file($f) or die;
    88     }
    86     }
    89     $Cf->getopt(\@ARGV) or die "Bad Usage.  Try --help.\n";
    87     $Cf->getopt( \@ARGV ) or die "Bad Usage.  Try --help.\n";
    90 
    88 
    91     die "Need ldap base.\n" if not $Cf->ldap_base;
    89     die "Need ldap base.\n" if not $Cf->ldap_base;
    92     if ($Cf->ldap_admin !~ /\Q$Cf->ldap_base/) {
    90     if ( $Cf->ldap_admin !~ /\Q$Cf->ldap_base/ ) {
    93 	$Cf->ldap_admin($Cf->ldap_admin . "," . $Cf->ldap_base);
    91         $Cf->ldap_admin( $Cf->ldap_admin . "," . $Cf->ldap_base );
    94     }
    92     }
    95 
    93 
    96     if ($Cf->help) {
    94     if ( $Cf->help ) {
    97 	if (-t STDOUT and -x "/usr/bin/less") { open(X, "|less -FX") }
    95         if   ( -t STDOUT and -x "/usr/bin/less" ) { open( X, "|less -FX" ) }
    98 	else { open(X, ">&STDOUT"); }
    96         else                                      { open( X, ">&STDOUT" ); }
    99 	print X help();
    97         print X help();
   100 	exit 0;
    98         exit 0;
   101     }
    99     }
   102 
   100 
   103     @_ = grep { $_ =~ /^\Q$Module\E/ } qw/account alias shared group/;
   101     @_ = grep { $_ =~ /^\Q$Module\E/ } qw/account alias shared group/;
   104     die "Need module.  Try --help\n" if @_ == 0;
   102     die "Need module.  Try --help\n" if @_ == 0;
   105     die "Module ambigous. (@_)\n" if @_ > 1;
   103     die "Module ambigous. (@_)\n" if @_ > 1;
   106 
   104 
   107     if ($_[0] eq 'account') {
   105     if ( $_[0] eq 'account' ) {
   108 	require account;
   106         require account;
   109 	account::import($Cf);
   107         account::import($Cf);
   110 	account::run();
   108         account::run();
   111     } elsif ($_[0] eq 'alias') {
   109     } elsif ( $_[0] eq 'alias' ) {
   112 	require alias;
   110         require alias;
   113 	alias::import($Cf);
   111         alias::import($Cf);
   114 	alias::run();
   112         alias::run();
   115     } elsif ($_[0] eq 'shared') {
   113     } elsif ( $_[0] eq 'shared' ) {
   116         die "Command '$_[0]' is currently not supported\n";
   114         die "Command '$_[0]' is currently not supported\n";
   117 	require shared;
   115         require shared;
   118 	shared::import($Cf);
   116         shared::import($Cf);
   119 	shared::run();
   117         shared::run();
   120     } elsif ($_[0] eq 'group') {
   118     } elsif ( $_[0] eq 'group' ) {
   121         die "Command '$_[0]' is currently not supported\n";
   119         die "Command '$_[0]' is currently not supported\n";
   122 	require group;
   120         require group;
   123 	group::import($Cf);
   121         group::import($Cf);
   124 	group::run();
   122         group::run();
   125     } else {
   123     } else {
   126 	die "Shit";
   124         die "Shit";
   127     }
   125     }
   128 
   126 
   129 }
   127 }
   130 
   128 
   131 sub verbose(@) {
   129 sub verbose(@) {
   132     print STDERR @_;
   130     print STDERR @_;
   133 }
   131 }
   134 
   132 
   135 sub help() {
   133 sub help() {
   136     ($_ = USAGE) =~ s/!(.*?)!/(eval $1) || ""/eg;
   134     ( $_ = USAGE ) =~ s/!(.*?)!/(eval $1) || ""/eg;
   137     return $_;
   135     return $_;
   138 }
   136 }
   139 
   137 
   140 # vim:sts=4 sw=4 aw ai sm nohlsearch incsearch:
   138 # vim:sts=4 sw=4 aw ai sm nohlsearch incsearch: