steffen: server/kolab/kolab kolab_bootstrap,1.48,1.49

cvs at intevation.de cvs at intevation.de
Wed Jul 14 14:13:53 CEST 2004


Author: steffen

Update of /kolabrepository/server/kolab/kolab
In directory doto:/tmp/cvs-serv10650

Modified Files:
	kolab_bootstrap 
Log Message:
function for user input

Index: kolab_bootstrap
===================================================================
RCS file: /kolabrepository/server/kolab/kolab/kolab_bootstrap,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- kolab_bootstrap	14 Jul 2004 09:29:42 -0000	1.48
+++ kolab_bootstrap	14 Jul 2004 12:13:51 -0000	1.49
@@ -61,6 +61,32 @@
   }
 }
 
+# Ask the user a question
+sub getUserInput {
+  my $text = shift;
+  my $default = shift;
+  my @values = @_;
+
+  if( $default ) {
+        $text = "$text [$default]";
+  }
+  if( @values ) {
+        $text = "$text (".join('/', @values)."): ";
+  } else {
+        $text = "$text: ";
+  }
+AGAIN:
+  print $text;
+  my $tmp = ReadLine;
+  chomp $tmp;
+  if( $default && $tmp eq '' ) { $tmp = $default; }
+  if( @values ) {
+    foreach( @values ) { return $tmp if( $tmp eq $_ ); }
+    goto AGAIN;
+  }
+  return $tmp;
+}
+
 # Fetch entry from ldap server or create new entry of none exist
 sub newOrExistingLDAPEntry {
   my $ldap = shift;
@@ -102,9 +128,7 @@
 if ($?==0) {
   print ("\nFound existing configuration\n");
   print "\nBootstrapping Kolab will overwrite old configuration\n";
-  print "\nContinue n/y [n]: ";
-  my $tmp = ReadLine;
-  chomp $tmp;
+  my $tmp = getUserInput( "\nContinue", "n", "y", "n" );
   if( (lc $tmp eq 'n') || ($tmp eq '')  ) {
     print "Bootstrapping aborted - not creating new configuration\n";
     exit 0;
@@ -161,22 +185,19 @@
 }
 chomp($fqdn);
 
-print "Please enter Hostname [$fqdn]: ";
-my $tmp = ReadLine;
-chomp $tmp;
-if ($tmp) { $fqdn = $tmp; }
+$fqdn = getUserInput("Please enter Hostname", $fqdn);
 print "Proceeding with Hostname $fqdn\n";
 
+my $tmp;
 if( $is_master eq "false" ) {
   $tmp = "2";
 } else {
   $tmp = "1";
 }
 
-print "Do you want to set up (1) a master Kolab server or (2) a slave [$tmp]: ";
-my $tmp2 = ReadLine;
-chomp $tmp2;
-if ( $tmp2 eq "2" || ( !$tmp2 && $tmp eq "2" ) ) {
+my $tmp2 = getUserInput( "Do you want to set up (1) a master Kolab server or (2) a slave",
+			 $tmp, "1", "2");
+if ( $tmp2 eq "2" ) {
   $is_master = "false";
   print "Proceeding with slave server setup\n\n";
 } else {
@@ -193,12 +214,7 @@
     $domain = $fqdn;
   }
 
-  print "Please enter your Maildomain [$domain]: ";
-  my $tmp = ReadLine;
-  chomp $tmp;
-  if ($tmp) {
-    $domain = $tmp;
-  }
+  $domain = getUserInput("Please enter your Maildomain", $domain);
   print "proceeding with Maildomain $domain\n";
 
   if ( $opt_f || $base_dn =~ /\@\@\@/ || $bind_dn =~ /\@\@\@/ || $bind_pw =~ /\@\@\@/ ) {
@@ -218,12 +234,7 @@
     if ($bind_pw =~ /\@\@\@/) {
       $bind_pw = `$kolab_prefix/bin/openssl passwd kolab`;
       chomp $bind_pw;
-      print "Please choose a manager password [$bind_pw]: ";
-      my $tmp = ReadLine;
-      chomp $tmp;
-      if ($tmp) {
-        $bind_pw = $tmp;
-      }
+      $bind_pw = getUserInput("Please choose a manager password", $bind_pw);
       print " bind_pw : $bind_pw\n";
     }
     if ($php_dn =~ /\@\@\@/) {
@@ -254,9 +265,7 @@
   # Set up slapd to replicate to slave server's kolabds
   @kolabhosts = ( $fqdn );
   while(1) {
-    print "Enter hostname of slave kolab server [empty when done]: ";
-    my $tmp = ReadLine;
-    chomp $tmp;
+    my $tmp = getUserInput("Enter hostname of slave kolab server [empty when done]");
     if( $tmp ) {
       push @kolabhosts, $tmp;
       #$cfg .= "replica host=$tmp\n";
@@ -493,9 +502,7 @@
 for the Kolab server.
 EOS
 
-  print "Do you want to create CA and certificates (y/n) [y]: ";
-  my $tmp = ReadLine;
-  chomp $tmp;
+  my $tmp = getUserInput( "Do you want to create CA and certificates", "y", "y", "n");
   if( lc $tmp eq 'n' ) {
     print <<'EOS';
 Skipping certificate creation. Please copy your certificate to
@@ -548,25 +555,16 @@
   # For now we just connect to the remote slapd
  SLAVESTART:
   print "Now some information about the master LDAP server is required:\n\n";
-  print "URI of master LDAP server: ";
-  $ldap_uri = ReadLine;
-  chomp $ldap_uri;
+  do { $ldap_uri = getUserInput("URI of master LDAP server"); } until $ldap_uri;
   my $ldapuri = URI->new($ldap_uri) || warn "error: could not parse given uri";
   if( $ldapuri ) {
     $base_dn = join( ',', map { "dc=$_" } split /\./, $ldapuri->host() );
   }
-  print "Base DN of server [$base_dn]: ";
-  $tmp = ReadLine;
-  chomp $tmp;
-  if( $tmp ) {
-    $base_dn = $tmp;
-  }
+  $base_dn = getUserInput("Base DN of server", $base_dn);
   print "proceeding with base DN $base_dn\n";
 
   $bind_dn = "cn=manager,$base_dn";
-  print "Manager password: ";
-  $bind_pw = ReadLine;
-  chomp $bind_pw;
+  $bind_pw = getUserInput("Manager password");
 
   my $confname = "$kolab_prefix/etc/sasl/apps/smtpd.conf";
   copy("$kolab_prefix/etc/kolab/templates/smtpd.conf.template", $confname) || die "could not write to $confname";
@@ -635,9 +633,8 @@
 a certificate request and copy it to the master to get it signed. If you already
 have a certificate for this server, you can choose to skip this section.
 EOS
-    print "Do you want to create a certificate request and sign it (y/n) [y]: ";
-    my $tmp = ReadLine;
-    chomp $tmp;
+    my $tmp = getUserInput( "Do you want to create a certificate request and sign it", 
+			    "y", "y", "n");
     if( lc $tmp eq 'n' ) {
       print <<'EOS';
 Skipping certificate creation. Please copy your certificate to
@@ -696,4 +693,4 @@
 print "kolab is now ready to run!\n";
 print "please run '$kolab_prefix/bin/openpkg rc all start'\n";
 print ("Use login=manager and passwd=$bind_pw when you log into\n");
-print ("the webinterface https://localhost/admin !\n");
+print ("the webinterface https://$fqdn/admin !\n");





More information about the commits mailing list