sunw-history-package revision 5680
62N/A#!/usr/perl5/bin/perl
62N/A#
62N/A# CDDL HEADER START
62N/A#
62N/A# The contents of this file are subject to the terms of the
62N/A# Common Development and Distribution License (the "License").
62N/A# You may not use this file except in compliance with the License.
62N/A#
62N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
62N/A# or http://www.opensolaris.org/os/licensing.
62N/A# See the License for the specific language governing permissions
62N/A# and limitations under the License.
62N/A#
62N/A# When distributing Covered Code, include this CDDL HEADER in each
62N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
62N/A# If applicable, add the following below this CDDL HEADER, with the
62N/A# fields enclosed by brackets "[]" replaced with your own identifying
62N/A# information: Portions Copyright [yyyy] [name of copyright owner]
62N/A#
62N/A# CDDL HEADER END
62N/A#
5680N/A
5680N/A#
62N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
62N/A#
62N/A# sunw-history-package
62N/A# A simple program to generate the actions contained in the SUNW package
62N/A# that maps between the old (pre build-133) and new ips package names.
62N/A#
62N/A
62N/A$|=1;
62N/A
62N/Ause Getopt::Long;
62N/Ause File::Basename /qw basename/;
62N/A
62N/Amy $PKG = '/usr/bin/pkg';
62N/A
62N/Asub generate_manifest {
62N/A local ($package_name) = @_;
62N/A my ($package, %depends) = ();
62N/A
62N/A # gather some data
62N/A open($FP, "$PKG contents -r -H -o action.raw $package_name |");
62N/A
62N/A while (<$FP>) { # save what we want
62N/A if (m{set\s+name=pkg.fmri\s+value=pkg://.+/(.+):.+$}) {
62N/A $package = $1;
62N/A } elsif (m{depend fmri=(.+)\s+type=require$}) {
62N/A $depends{$1} = 1;
62N/A }
62N/A }
62N/A
62N/A close($FP);
62N/A
62N/A # generate the manifest actions
62N/A print <<EOF;
62N/Aset name=pkg.fmri value=pkg:/$package
62N/Aset name=pkg.renamed value=true
62N/A
62N/Aset name=org.opensolaris.consolidation value=\$(CONSOLIDATION)
62N/A
62N/Aset name=variant.opensolaris.zone value=global value=nonglobal
62N/Aset name=variant.arch value=\$(ARCH)
62N/A
62N/AEOF
62N/A foreach (sort keys %depends) {
62N/A (m{^consolidation/}) ||
62N/A print "depend fmri=$_ type=require\n"
62N/A }
62N/A}
62N/A
62N/Asub usage {
62N/A my $program = basename($0);
62N/A print <<EOF;
62N/AUsage: $program (--package (new-ips-name)) ...
62N/A
62N/AEOF
62N/A exit(1);
62N/A}
62N/A
62N/Asub main {
62N/A my (@current_packages, %SUNWpackages) = ();
62N/A
62N/A GetOptions('package:s' => \@current_packages);
62N/A
62N/A ($#current_packages == -1) && usage();
62N/A
62N/A # find all SUNW packages that require the supplied packages
62N/A foreach (@current_packages) {
62N/A open($FP, "$PKG search -r -H -o pkg.name 'SUNW*:depend::*/$_' |");
62N/A
62N/A while (<$FP>) {
62N/A chomp;
62N/A $SUNWpackages{$_} = 1;
62N/A }
62N/A
62N/A close($FP);
62N/A }
62N/A
62N/A # generate manifests for each SUNWpackage
62N/A foreach (sort keys %SUNWpackages) {
62N/A print "\n\n$_.p5m actions:\n";
62N/A generate_manifest($_);
62N/A }
62N/A}
62N/A
62N/A#
62N/A# Main execution starts here.
62N/A#
62N/Amain();