|
1 #!/usr/perl5/bin/perl |
|
2 # |
|
3 # CDDL HEADER START |
|
4 # |
|
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. |
|
8 # |
|
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. |
|
13 # |
|
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] |
|
19 # |
|
20 # CDDL HEADER END |
|
21 # |
|
22 # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
23 # |
|
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. |
|
27 # |
|
28 |
|
29 $|=1; |
|
30 |
|
31 use Getopt::Long; |
|
32 use File::Basename /qw basename/; |
|
33 |
|
34 my $PKG = '/usr/bin/pkg'; |
|
35 |
|
36 sub generate_manifest { |
|
37 local ($package_name) = @_; |
|
38 my ($package, %depends) = (); |
|
39 |
|
40 # gather some data |
|
41 open($FP, "$PKG contents -r -H -o action.raw $package_name |"); |
|
42 |
|
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; |
|
48 } |
|
49 } |
|
50 |
|
51 close($FP); |
|
52 |
|
53 # generate the manifest actions |
|
54 print <<EOF; |
|
55 set name=pkg.fmri value=pkg:/$package |
|
56 set name=pkg.renamed value=true |
|
57 |
|
58 set name=org.opensolaris.consolidation value=\$(CONSOLIDATION) |
|
59 |
|
60 set name=variant.opensolaris.zone value=global value=nonglobal |
|
61 set name=variant.arch value=\$(ARCH) |
|
62 |
|
63 EOF |
|
64 foreach (sort keys %depends) { |
|
65 (m{^consolidation/}) || |
|
66 print "depend fmri=$_ type=require\n" |
|
67 } |
|
68 } |
|
69 |
|
70 sub usage { |
|
71 my $program = basename($0); |
|
72 print <<EOF; |
|
73 Usage: $program (--package (new-ips-name)) ... |
|
74 |
|
75 EOF |
|
76 exit(1); |
|
77 } |
|
78 |
|
79 sub main { |
|
80 my (@current_packages, %SUNWpackages) = (); |
|
81 |
|
82 GetOptions('package:s' => \@current_packages); |
|
83 |
|
84 ($#current_packages == -1) && usage(); |
|
85 |
|
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::*/$_' |"); |
|
89 |
|
90 while (<$FP>) { |
|
91 chomp; |
|
92 $SUNWpackages{$_} = 1; |
|
93 } |
|
94 |
|
95 close($FP); |
|
96 } |
|
97 |
|
98 # generate manifests for each SUNWpackage |
|
99 foreach (sort keys %SUNWpackages) { |
|
100 print "\n\n$_.p5m actions:\n"; |
|
101 generate_manifest($_); |
|
102 } |
|
103 } |
|
104 |
|
105 # |
|
106 # Main execution starts here. |
|
107 # |
|
108 main(); |