bass-o-matic: fix path for encumbered history
[oi-userland.git] / tools / sunw-history-package
blob73df3f827090f62a414dced35ac076841d7d891e
1 #!/usr/perl5/bin/perl
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
22 # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
24 # sunw-history-package
25 # A simple program to generate the actions contained in the SUNW package
26 # that maps between the old (pre build-133) and new ips package names.
29 $|=1;
31 use Getopt::Long;
32 use File::Basename /qw basename/;
34 my $PKG = '/usr/bin/pkg';
36 sub generate_manifest {
37 local ($package_name) = @_;
38 my ($package, %depends) = ();
40 # gather some data
41 open($FP, "$PKG contents -r -H -o action.raw $package_name |");
43 while (<$FP>) { # save what we want
44 if (m{set\s+name=pkg.fmri\s+value=pkg://.+/(.+):.+$}) {
45 $package = $1;
46 } elsif (m{depend fmri=(.+)\s+type=require$}) {
47 $depends{$1} = 1;
51 close($FP);
53 # generate the manifest actions
54 print <<EOF;
55 set name=pkg.fmri value=pkg:/$package
56 set name=pkg.renamed value=true
58 set name=org.opensolaris.consolidation value=\$(CONSOLIDATION)
60 set name=variant.opensolaris.zone value=global value=nonglobal
61 set name=variant.arch value=\$(ARCH)
63 EOF
64 foreach (sort keys %depends) {
65 (m{^consolidation/}) ||
66 print "depend fmri=$_ type=require\n"
70 sub usage {
71 my $program = basename($0);
72 print <<EOF;
73 Usage: $program (--package (new-ips-name)) ...
75 EOF
76 exit(1);
79 sub main {
80 my (@current_packages, %SUNWpackages) = ();
82 GetOptions('package:s' => \@current_packages);
84 ($#current_packages == -1) && usage();
86 # find all SUNW packages that require the supplied packages
87 foreach (@current_packages) {
88 open($FP, "$PKG search -r -H -o pkg.name 'SUNW*:depend::*/$_' |");
90 while (<$FP>) {
91 chomp;
92 $SUNWpackages{$_} = 1;
95 close($FP);
98 # generate manifests for each SUNWpackage
99 foreach (sort keys %SUNWpackages) {
100 print "\n\n$_.p5m actions:\n";
101 generate_manifest($_);
106 # Main execution starts here.
108 main();