File: mono.runtime-script

package info (click to toggle)
mono 1.2.2.1-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 142,720 kB
  • ctags: 256,408
  • sloc: cs: 1,495,736; ansic: 249,442; sh: 18,327; xml: 12,463; makefile: 5,046; perl: 1,248; asm: 635; yacc: 285; sql: 7
file content (146 lines) | stat: -rw-r--r-- 3,265 bytes parent folder | download | duplicates (2)
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
146
#!/usr/bin/perl

#
# Setup
#

# Directives
use strict;
use warnings;

# Modules
use File::Basename;

# Figure out the mode
my $mode = shift @ARGV;

if (!defined $mode)
{
    print STDERR "E: You must supply a mode\n";
    print STDERR "E: Use: install, remove, or name\n";
    exit 1;
}

# Name is simply
if ($mode eq "name")
{
    print "Mono\n";
    exit 0;
}

# This program gets the name of a file (ending in .installcligac) and
# a list of assemblies to install, as full paths. The ones given are
# the only ones that passed the white/blacklisting.

# Get the base file
my $basename = shift @ARGV;
my $cligac = "/usr/share/cli-common/packages.d/$basename.installcligac";

if (! -f $cligac)
{
    print STDERR "E: File does not exist: $cligac\n";
    exit 1;
}

# Get the base directory
my $basedir = "/usr/share/cli-common/packages.d/";

# Removing is also simple
if ($mode eq "remove")
{
    # Get the uninstall file
    my $uninstall = "$basedir/$basename.mono";

    if (-f $uninstall)
    {
	# Go through the file
	open UNINSTALL, "<$uninstall" or
	    die "E: Cannot open uninstall file ($!)";

	while (<UNINSTALL>)
	{
	    # Clean up the line and get the base directory
	    chomp;
		 my $cmd = "/usr/bin/mono /usr/lib/mono/1.0/gacutil.exe /u $_"
		 . " > /dev/null";
		 system($cmd) == 0 or
		 	print STDERR "W: removing Assembly $_ failed!\n";
	}

	close UNINSTALL;

	# Unlike the file
	unlink($uninstall);
    }

    # We are good
    exit 0;
}

# The only thing left should be "install"
if ($mode ne "install")
{
    print STDERR "E: Unknown mode: $mode\n";
    print STDERR "E: Use: install, remove, or name\n";
    exit 1;
}


# Open up our uninstall file
open UNINSTALL, ">$basedir/$basename.mono"
    or die "E: Cannot open uninstall: $basedir/$basename.mono";

# Go through the file
open CLIGAC, "<$cligac" or die "E: Cannot open: $cligac ($!)";

while (@ARGV)
{
    # Get the assembly name
    my $dll = shift @ARGV;
    
    # Make sure it is there
    if (! -f $dll)
    {
	print STDERR "E: Assembly does not exist: $dll\n";
	exit 1;
    }
    
    # Figure out the mono's precise name
    my $fullname = get_full_name($dll);
    
    # Write out the uninstall file
    print UNINSTALL "$fullname\n";
    
    # Install the file. We use the "../../../.." to make it a
    # relative path to this program (since gacutil doesn't like
    # absolute paths). There isn't a problem of doing too many
    # since we typically run from the root context.
    my $cmd = "(cd `dirname $dll` && "
    	. "/usr/bin/mono /usr/lib/mono/1.0/gacutil.exe /i `basename $dll`"
	   . " > /dev/null)";
    system($cmd) == 0 or die "E: installing Assembly $dll failed\n";
}

close CLIGAC;
close UNINSTALL;

# Finish up successfully
exit 0;

# Get the name of the assembly in a manner suitable for uninstall
# using gacutil.
sub get_full_name
{
    # Get the name
    my $dll = shift;

    # Open a pipe to monop
    my $cmd = "LANG=C /usr/bin/mono /usr/share/mono/MonoGetAssemblyName.exe $dll";
    open PIPE, "$cmd |" or die "E: Cannot open pipe to assembly builder $dll";

    # This generate a single line that produces the desired results
    $_ = <PIPE>;
    chomp;
	 # assembly1, Version=1.0.0.0, Culture=en, PublicKeyToken=0123456789abcdef
    return $_;
}