#!/usr/bin/perl use ZConf::DBI; use strict; use warnings; use Getopt::Std; use Term::ReadKey; $Getopt::Std::STANDARD_HELP_VERSION = 1; #version function sub main::VERSION_MESSAGE { print "zcdbi-set 0.0.0\n"; } #print help sub main::HELP_MESSAGE { print "\n". "-s \n". "-n \n". "-d \n", "-u \n". "-p \n". "-P Ask the password.\n". "-a \n". "-A \n"; } #gets the options my %opts=(); getopts('as:n:d:u:p:', \%opts); #asks the password if asked for if ($opts{P}) { #ask for the password ReadMode(4); print 'password:'; my $pass1=; print "\npassword:"; my $pass2=; print "\n"; ReadMode(0); #makes sure it is the same if ($pass1 ne $pass2) { warn('zcdbi-set:254: The passwords are not the same'); exit 254; } chomp($pass1); $opts{p}=$pass1; } #initilize it my $zcdbi=ZConf::DBI->new; #read the specified set if requested if (defined($opts{s})) { $zcdbi->readset($opts{s}); if ($zcdbi->error) { warn('zcdbi-set:'.$zcdbi->error.': '.$zcdbi->errorString); exit $zcdbi->error; } } #handles changing the data source if (defined($opts{d})) { $zcdbi->setDS($opts{n}, $opts{n}); if ($zcdbi->error) { warn('zcdbi-set:'.$zcdbi->error.': '.$zcdbi->errorString); exit $zcdbi->error; } } #handles changing the user if (defined($opts{u})) { $zcdbi->setDSuser($opts{n}, $opts{u}); if ($zcdbi->error) { warn('zcdbi-set:'.$zcdbi->error.': '.$zcdbi->errorString); exit $zcdbi->error; } } #handles changing the user if (defined($opts{p})) { $zcdbi->setDSattr($opts{n}, $opts{p}); if ($zcdbi->error) { warn('zcdbi-set:'.$zcdbi->error.': '.$zcdbi->errorString); exit $zcdbi->error; } } #handles changing the attribute if (defined($opts{a})) { $zcdbi->setDSpass($opts{n}, $opts{a}, $opts{A}); if ($zcdbi->error) { warn('zcdbi-set:'.$zcdbi->error.': '.$zcdbi->errorString); exit $zcdbi->error; } } exit 0; =head1 NAME zcdbi-set - Modify a existing data source. =head1 SYNOPSIS zcdbi-set [B<-s> ] B<-n> [B<-d> ] [B<-u> ] [B<-p> ] [B<-P>] [B<-a> ] [B<-A> ] =head1 SWTICHES =head2 -a The attribute name to modify. If "-A" is not specified, it is removed. =head2 -A The attribute value. =head2 -d The DBI data source string. =head2 -n The name of the data source to add. =head2 -p Specifiy the password via a switch. =head2 -P Specifiy the password via standard input. It will be asked for twice. =head2 -s The set to load. =head2 -u The user name to use with the data source. =head1 EXIT CODES Any non-zero exit codes, not listed below, are the error codes returned by ZConf. =head2 254 The -a switch was used and the passwords did not match. =head1 AUTHOR Copyright (c) 2010, Zame C. Bowers All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS` OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =head1 Changelog =head2 2010-03-12/15:00 Initial release. =cut