remove-ds.pl.in 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!@perlexec@
  2. # BEGIN COPYRIGHT BLOCK
  3. # This Program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; version 2 of the License.
  6. #
  7. # This Program is distributed in the hope that it will be useful, but WITHOUT
  8. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License along with
  12. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  13. # Place, Suite 330, Boston, MA 02111-1307 USA.
  14. #
  15. # Copyright (C) 2007 Red Hat, Inc.
  16. # All rights reserved.
  17. # END COPYRIGHT BLOCK
  18. #
  19. use lib qw(@perlpath@);
  20. use strict;
  21. use File::Basename;
  22. use File::Path;
  23. use Getopt::Long;
  24. use DSUtil;
  25. use Resource;
  26. use DSCreate qw(removeDSInstance);
  27. # process command line options
  28. Getopt::Long::Configure(qw(bundling)); # bundling allows -ddddd
  29. my $res = new Resource("@propertydir@/setup-ds.res");
  30. sub usage {
  31. print(STDERR "Usage: $0 [-f] [-d -d ... -d] -i instance\n\n");
  32. print(STDERR " Opts: -f - force removal\n");
  33. print(STDERR " -i instance - instance name to remove (e.g. - slapd-example)\n");
  34. print(STDERR " -d - turn on debugging output\n");
  35. }
  36. my $force = "";
  37. my $instname = "";
  38. my $initconfig_dir = "";
  39. GetOptions('help|h|?' => sub { &usage; exit(1); },
  40. 'debug|d+' => \$DSUtil::debuglevel,
  41. 'instance|i=s' => \$instname,
  42. 'initconfig_dir|c=s' => \$initconfig_dir,
  43. 'force|f' => \$force
  44. );
  45. # Make sure the instance name option was provided.
  46. unless ($instname) {
  47. &usage; exit(1);
  48. }
  49. # Make sure a full instance name was provided.
  50. my ($slapd, $inst) = split(/-/, $instname, 2);
  51. unless ($inst) {
  52. print STDERR "Full instance name must be specified (e.g. - slapd-example)\n";
  53. exit 1;
  54. }
  55. my @errs = removeDSInstance($inst, $force, $initconfig_dir);
  56. if (@errs) {
  57. print STDERR "The following errors occurred during removal:\n";
  58. for (@errs) {
  59. print STDERR $res->getText($_);
  60. }
  61. print STDERR "Error: could not remove directory server $inst\n";
  62. exit 1;
  63. }
  64. # if we got here, report success
  65. print "Instance $instname removed.\n";
  66. exit 0;
  67. # emacs settings
  68. # Local Variables:
  69. # mode:perl
  70. # indent-tabs-mode: nil
  71. # tab-width: 4
  72. # End: