userland-incorporator revision 2213
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#!/usr/bin/perl
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# CDDL HEADER START
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# The contents of this file are subject to the terms of the
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# Common Development and Distribution License (the "License").
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# You may not use this file except in compliance with the License.
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# or http://www.opensolaris.org/os/licensing.
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# See the License for the specific language governing permissions
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# and limitations under the License.
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# When distributing Covered Code, include this CDDL HEADER in each
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# If applicable, add the following below this CDDL HEADER, with the
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# fields enclosed by brackets "[]" replaced with your own identifying
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# information: Portions Copyright [yyyy] [name of copyright owner]
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# CDDL HEADER END
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# incorporator - an utility to incorporate packages in a repo
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassuse Getopt::Long;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glasssub enumerate_packages {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass local ($repository, $publisher, @fmris) = @_;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass my @packages = ();
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass #printf "/usr/bin/pkg list -ng $repository @fmris\n";
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass open($fp, "-|", "/usr/bin/pkgrepo", "list", "-H", "-s", $repository,
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass "-p", $publisher, @fmris) ||
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass die "pkg: $!";
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass while (<$fp>) {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass # lines should be in the form:
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass # publisher package [r|o] version,5.12-branch:timestamp
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass # or lines should be in the form:
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass # publisher package [r|o] version-branch:timestamp
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass if ((/^(\S+)\s+(\S+)\s+\S?\s+([\d.]+),[\d.]+-([\d.]+):.+$/) ||
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass (/^(\S+)\s+(\S+)\s+\S?\s+([\d.]+)-([\d.]+):.+$/)) {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass my ($package) = ();
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $package->{publisher} = $1;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $package->{name} = $2;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $package->{version} = $3;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $package->{branch} = $4;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass if ($package->{name} !~ m/incorporation/) {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass push(@packages, $package);
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass }
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass } else {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass die "error: cannot handle: ", $_;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass }
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass }
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass #printf "returning %s\n", $_->{name} for (@packages);
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass return @packages;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass}
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glasssub print_incorporate {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass local (%package) = @_;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass my $facet = "facet.version-lock.$package->{name}";
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass printf "depend fmri=%s@%s-%s %s=true type=incorporate\n",
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $package->{name}, $package->{version}, $package->{branch},
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $facet;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass}
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassmy ($repository, $fmri, $summary, $description, $consolidation) = ();
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassmy %seen = ();
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass$consolidation = 'userland';
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav GlassGetOptions("R|repository=s" => \$repository, "v|version=s" => \$version,
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass "s|summary=s" => \$summary, "d|description=s" => \$description,
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass "p|package=s" => \$fmri, "f|fmri=s" => \@fmris,
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass "c|consolidation=s" => \$consolidation);
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass# print the incorporation
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass#
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassprintf "set name=pkg.fmri value=%s\n", $fmri;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassprintf "set name=pkg.summary value='%s'\n", $summary;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassprintf "set name=pkg.description value='%s'\n", $description;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassprintf "set name=org.opensolaris.consolidation value=%s\n",
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $consolidation;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassprintf "set name=pkg.depend.install-hold value=core-os.%s\n",
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $consolidation;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassprintf "set name=info.classification value='org.opensolaris.category.2008:Meta Packages/Incorporations'\n";
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass@packages = enumerate_packages($repository, $consolidation, @fmris);
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glassfor (@packages) {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass if ($seen->{$_->{name}} == 1) {
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass die "error: duplicate package ", $_->{name};
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass }
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass printf "depend fmri=pkg:/%s@%s-%s %s=true type=incorporate\n",
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $_->{name}, $_->{version}, $_->{branch},
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass "facet.version-lock.".$_->{name};
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass $seen->{$_->{name}} = 1;
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass}
ffa35f3c26be15ca573281e930814a837f2ef719Dav Glass