1 #!/usr/perl5/bin/perl -w
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 #ident "%Z%%M% %I% %E% SMI"
36 use Getopt
::Long
qw(:config no_ignore_case bundling);
37 use POSIX
qw(locale_h);
38 use Sun
::Solaris
::Utils
qw(textdomain gettext);
39 use Sun
::Solaris
::Project
qw(:ALL :PRIVATE);
42 # Print a usage message and exit.
47 my $prog = basename
($0);
48 print(STDERR
"$prog: @msg\n") if (@msg);
49 printf(STDERR gettext
("Usage: %s [-f filename] project\n"), $prog);
54 # Print a list of error messages and exit.
59 my $prog = basename
($0) . ': ';
60 foreach my $err (@_) {
61 my ($e, $fmt, @args) = @
$err;
62 printf(STDERR
$prog . $fmt . "\n", @args);
68 # Main routine of script.
70 # Set the message locale.
72 setlocale
(LC_ALL
, '');
73 textdomain
(TEXT_DOMAIN
);
75 # Process command options and do some initial command-line validity checking.
78 GetOptions
("f=s" => \
$opt_f) || usage
();
79 usage
(gettext
('Invalid command-line arguments')) if (@ARGV != 1);
80 usage
(gettext
('No project name specified')) if (! defined($ARGV[0]));
87 if (defined($opt_f)) {
90 $projfile = &PROJF_PATH
;
93 # Fabricate an unique temporary filename.
94 $tmpprojf = $projfile . ".tmp.$$";
98 # Read the project file. sysopen() is used so we can control the file mode.
99 if (! sysopen($pfh, $projfile, O_RDONLY
)) {
100 error
([10, gettext
('Cannot open %s: %s'), $projfile, $!]);
102 my ($mode, $uid, $gid) = (stat($pfh))[2,4,5];
105 $flags->{'validate'} = 'false';
106 $flags->{'res'} = 'true';
107 $flags->{'dup'} = 'true';
109 my ($ret, $pf) = projf_read
($pfh, $flags);
115 # Search for the project & remove it.
117 my @newpf = grep { $_->{'name'} eq $pname ?
$del++ && 0 : 1 } @
$pf;
118 error
([6, gettext
('Project "%s" does not exist'), $pname])
120 error
([6, gettext
('Duplicate project name "%s"'), $pname])
121 if ($del > 1); # Should be impossible due to projf_validate() check.
123 # Write out the project file.
125 sysopen($pfh, $tmpprojf, O_WRONLY
| O_CREAT
| O_EXCL
, $mode) ||
126 error
([10, gettext
('Cannot create %s: %s'), $tmpprojf, $!]);
127 projf_write
($pfh, \
@newpf);
129 if (!chown($uid, $gid, $tmpprojf)) {
131 error
([10, gettext
('Cannot set ownership of %s: %s'),
134 if (! rename($tmpprojf, $projfile)) {
136 error
([10, gettext
('cannot rename %s to %s: %s'),
137 $tmpprojf, $projfile, $!]);