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