home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / cli-common / runtimes.d / mono
Encoding:
Text File  |  2009-08-19  |  3.1 KB  |  148 lines

  1. #!/usr/bin/perl
  2.  
  3. #
  4. # Setup
  5. #
  6.  
  7. # Directives
  8. use strict;
  9. use warnings;
  10.  
  11. # Modules
  12. use File::Basename;
  13.  
  14. # Figure out the mode
  15. my $mode = shift @ARGV;
  16.  
  17. if (!defined $mode)
  18. {
  19.     print STDERR "E: You must supply a mode\n";
  20.     print STDERR "E: Use: install, remove, or name\n";
  21.     exit 1;
  22. }
  23.  
  24. # Name is simply
  25. if ($mode eq "name")
  26. {
  27.     print "Mono\n";
  28.     exit 0;
  29. }
  30.  
  31. # This program gets the name of a file (ending in .installcligac) and
  32. # a list of assemblies to install, as full paths. The ones given are
  33. # the only ones that passed the white/blacklisting.
  34.  
  35. # Get the base file
  36. my $basename = shift @ARGV;
  37. my $cligac = "/usr/share/cli-common/packages.d/$basename.installcligac";
  38.  
  39. if (! -f $cligac)
  40. {
  41.     print STDERR "E: File does not exist: $cligac\n";
  42.     exit 1;
  43. }
  44.  
  45. # Get the base directory
  46. my $basedir = "/usr/share/cli-common/packages.d/";
  47.  
  48. # Removing is also simple
  49. if ($mode eq "remove")
  50. {
  51.     # Get the uninstall file
  52.     my $uninstall = "$basedir/$basename.mono";
  53.  
  54.     if (-f $uninstall)
  55.     {
  56.     # Go through the file
  57.     open UNINSTALL, "<$uninstall" or
  58.         die "E: Cannot open uninstall file ($!)";
  59.  
  60.     while (<UNINSTALL>)
  61.     {
  62.         my $assembly = $_;
  63.         chomp($assembly);
  64.         my $cmd = "/usr/bin/gacutil -u $assembly > /dev/null";
  65.         my $res = system($cmd);
  66.         if ($res > 0) {
  67.             print STDERR "W: removing assembly: $assembly failed!\n";
  68.         }
  69.     }
  70.  
  71.     close UNINSTALL;
  72.  
  73.     # Unlike the file
  74.     unlink($uninstall);
  75.     }
  76.  
  77.     # We are good
  78.     exit 0;
  79. }
  80.  
  81. # The only thing left should be "install"
  82. if ($mode ne "install")
  83. {
  84.     print STDERR "E: Unknown mode: $mode\n";
  85.     print STDERR "E: Use: install, remove or name\n";
  86.     exit 1;
  87. }
  88.  
  89.  
  90. # Open up our uninstall file
  91. open UNINSTALL, ">$basedir/$basename.mono"
  92.     or die "E: Cannot open uninstall: $basedir/$basename.mono";
  93.  
  94. # Go through the file
  95. open CLIGAC, "<$cligac" or die "E: Cannot open: $cligac ($!)";
  96.  
  97. while (@ARGV)
  98. {
  99.     # Get the assembly name
  100.     my $dll = shift @ARGV;
  101.     
  102.     # Make sure it is there
  103.     if (! -f $dll)
  104.     {
  105.     print STDERR "E: Assembly does not exist: $dll\n";
  106.     exit 1;
  107.     }
  108.     
  109.     # Figure out the mono's precise name
  110.     my $fullname = get_full_name($dll);
  111.     
  112.     # Write out the uninstall file
  113.     print UNINSTALL "$fullname\n";
  114.     
  115.     # Install the file. We use the "../../../.." to make it a
  116.     # relative path to this program (since gacutil doesn't like
  117.     # absolute paths). There isn't a problem of doing too many
  118.     # since we typically run from the root context.
  119.     my $cmd = "(cd `dirname $dll` && "
  120.         . "/usr/bin/gacutil -i `basename $dll`"
  121.        . " > /dev/null)";
  122.     system($cmd) == 0 or die "E: installing Assembly $dll failed\n";
  123. }
  124.  
  125. close CLIGAC;
  126. close UNINSTALL;
  127.  
  128. # Finish up successfully
  129. exit 0;
  130.  
  131. # Get the name of the assembly in a manner suitable for uninstall
  132. # using gacutil.
  133. sub get_full_name
  134. {
  135.     # Get the name
  136.     my $dll = shift;
  137.  
  138.     # Open a pipe to monop
  139.     my $cmd = "LANG=C /usr/bin/mono /usr/share/mono/MonoGetAssemblyName.exe $dll";
  140.     open PIPE, "$cmd |" or die "E: Cannot open pipe to assembly builder $dll";
  141.  
  142.     # This generate a single line that produces the desired results
  143.     $_ = <PIPE>;
  144.     chomp;
  145.      # assembly1, Version=1.0.0.0, Culture=en, PublicKeyToken=0123456789abcdef
  146.     return $_;
  147. }
  148.