File: add-chrome.pl

package info (click to toggle)
iceweasel 2.0.0.19-0etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 298,784 kB
  • ctags: 317,912
  • sloc: cpp: 1,796,902; ansic: 987,677; xml: 109,036; makefile: 47,777; asm: 35,201; perl: 26,983; sh: 20,879; cs: 6,232; java: 5,513; python: 3,249; pascal: 459; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (141 lines) | stat: -rw-r--r-- 3,119 bytes parent folder | download | duplicates (8)
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
#!/perl

use File::Path;
use Getopt::Std;
use IO::File;
use mozLock;

getopts("lxo:");

my $installedChromeFile = $ARGV[0];
my $disableJarPackaging = $ARGV[1];
my $chromeType = $ARGV[2];
my $pkgName = $ARGV[3];
my $jarFileName = $ARGV[4];

my $win32 = ($^O =~ /((MS)?win32)|msys|cygwin|os2/i) ? 1 : 0;
my $macos = ($^O =~ /MacOS|darwin/i) ? 1 : 0;
my $unix  = !($win32 || $macos) ? 1 : 0;

sub foreignPlatformFile
{
   my ($jarfile) = @_;
   
   if (!$win32 && index($jarfile, "-win") != -1) {
     return 1;
   }
   
   if (!$unix && index($jarfile, "-unix") != -1) {
     return 1; 
   }

   if (!$macos && index($jarfile, "-mac") != -1) {
     return 1;
   }

   return 0;
}

#print "add-chrome $installedChromeFile $disableJarPackaging $chromeType $pkgName $jarFileName\n";

my $nofilelocks = 0;
if (defined($::opt_l)) {
    $nofilelocks = 1;
}

if (defined($::opt_x)) {
    $win32 = 0;
    $macos = 0;
    $unix = 1;
}

my $force_os;
if (defined($::opt_o)) {
    $force_os = $::opt_o;
}

if (defined($force_os)) {
    $win32 = 0;
    $macos = 0;
    $unix = 0;
    if ($force_os eq "WINNT") {
	$win32 = 1;
    } elsif ($force_os eq "OS2") {
	$win32 = 1;
    } elsif ($force_os eq "Darwin") {
	$macos = 1;
    } else {
	$unix = 1;
    }
}

if ($jarFileName =~ /(.*)\.jar/) {
    $jarFileName = $1;
}

if (!foreignPlatformFile($jarFileName)) {

my $line;
if ($disableJarPackaging) {
    $line = "$chromeType,install,url,resource:/chrome/$jarFileName/$chromeType/$pkgName/";
}
else {
    $line = "$chromeType,install,url,jar:resource:/chrome/$jarFileName.jar!/$chromeType/$pkgName/";
}

my $lockfile = "$installedChromeFile.lck";
my $err;

mozLock($lockfile) if (!$nofilelocks);
$err = 0;
if (open(FILE, "<$installedChromeFile")) {
    while (<FILE>) {
        chomp;
        if ($_ eq $line) {
            # line already appears in installed-chrome.txt file
            # just update the mod date
            close(FILE) or $err = 1; 
	    if ($err) {
		mozUnlock($lockfile) if (!$nofilelocks);
		die "error: can't close $installedChromeFile: $!";
	    }
            my $now = time;
            utime($now, $now, $installedChromeFile) or $err = 1;
	    mozUnlock($lockfile) if (!$nofilelocks);
	    if ($err) {
		die "couldn't touch $installedChromeFile";
	    }
            print "+++ updating chrome $installedChromeFile\n+++\t$line\n";
            exit;
        }
    }
    close(FILE) or $err = 1;
    if ($err) {
	mozUnlock($lockfile) if (!$nofilelocks);
	die "error: can't close $installedChromeFile: $!";
    }
}
mozUnlock($lockfile) if (!$nofilelocks);

my $dir = $installedChromeFile;
if ("$dir" =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
    $dir = $1;
}
mkpath($dir, 0, 0755);

mozLock($lockfile) if (!$nofilelocks);
$err = 0;
open(FILE, ">>$installedChromeFile") or $err = 1;
if ($err) {
    mozUnlock($lockfile) if (!$nofilelocks);
    die "can't open $installedChromeFile: $!";
}
print FILE "$line\n";
close(FILE) or $err = 1;
mozUnlock($lockfile) if (!$nofilelocks);
if ($err) {
    die "error: can't close $installedChromeFile: $!";
}
print "+++ adding chrome $installedChromeFile\n+++\t$line\n";
}