File: gac-package-install

package info (click to toggle)
cli-common 0.5.7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 208 kB
  • ctags: 11
  • sloc: perl: 913; sh: 53; makefile: 42
file content (145 lines) | stat: -rwxr-xr-x 2,855 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/perl

#
# Setup
#

# Directives
use strict;
use warnings;

# Modules
use File::Basename;

# This script gets the name of the package as the first parameter.  It
# parses the file given, figures out the black and white listing, then
# installs them as appropriate. If there is a second parameter, this
# is the only CLR installed.

#
# Handle the input file
#

# Get the package
my $pkg = $ARGV[0];
my $use_clr = $ARGV[1];
my $full = "/usr/share/cli-common/packages.d/$pkg";

# Make sure it exists
if ( ! -f "$full.installcligac" )
{
    print STDERR "! $full.installcligac doesn't exist!\n";
    exit 1;
}

# Parse the file
unless (open INPUT, "<$full.installcligac")
{
    print STDERR "! Cannot open $full.installcligac ($!)\n";
    exit 2;
}

my @dlls = ();
my %blacklist = ();
my %whitelist = ();

while (<INPUT>)
{
    # Clean up the line and ignore blanks and comments
    chomp;
    s/^\s+//;
    s/\s+$//;
    next if /^\#/;
    next if /^\s*$/;

    # Split on the space
    my @p = split(/\s+/);

    # Check the DLL
    my $dll = shift @p;

    if (! -f $dll)
    {
	print STDERR "! Assembly $dll does not exist\n";
	exit 3;
    }

    push @dlls, $dll;

    # Go through the listing
    while (@p)
    {
	# Get it
	my $p = shift @p;

	#print "D: List -> $dll: $p\n";

	# Add it to the appropriate list. The dll:$dll key is used for
	# sanity checking.
	if ($p =~ s/^-//)
	{
	    $blacklist{"$p:$dll"}++;
	    $blacklist{"dll:$dll"}++;
	}
	elsif ($p =~ s/^\+//)
	{
	    $whitelist{"$p:$dll"}++;
	    $whitelist{"dll:$dll"}++;
	}
    }
}

# Do some sanity checking
foreach my $dll (@dlls)
{
    if (defined($whitelist{"dll:$dll"}) && defined($blacklist{"dll:$dll"}))
    {
	print STDERR "! $dll has both a white- and blacklist.\n";
	print STDERR "!   Ignoring blacklist.\n";
    }
}

# Go through the installation targets
foreach my $clr (glob("/usr/share/cli-common/runtimes.d/*"))
{
    # Ignore temporary files
    next if $clr =~ /~$/;
    next if $clr =~ /^\./;

    # Get the "name"
    my $name = basename($clr);

    # Get the formal name
    my $formal = `$clr name`;
    $formal = $name if !defined $formal || $formal =~ /^\s*$/;
    chomp($formal);

    # Only use the one CLR if given
    next if (defined $use_clr && $name ne $use_clr);

    # Figure out the package list
    my @install = ();

    foreach my $dll (@dlls)
    {
	# Check the white list
	if (defined $whitelist{"dll:$dll"})
	{
	    next if (!defined $whitelist{"$name:$dll"});
	}
	elsif (defined $blacklist{"dll:$dll"})
	{
	    next if (defined $blacklist{"$name:$dll"});
	}

	# We are going to install this one
	push @install, $dll;
    }

    # Install it
    my $t = scalar(@install) . " assemblies";
    $t = "1 assembly" if (@install == 1);

    print STDOUT "* Installing $t from $pkg into $formal\n";
    system($clr, "install", $pkg, @install);
}