]>
Commit | Line | Data |
---|---|---|
ae4c2043 | 1 | #! /usr/bin/perl |
2 | ||
3 | use strict; | |
4 | ||
5 | #- Define full path to unzip command | |
6 | my $UnzipCommand = "/usr/bin/unzip"; | |
7 | ||
8 | #- Define the default setup file | |
9 | my $SetupConf = "setup.ins"; | |
10 | ||
11 | #- Define the generated instdb.ins file | |
12 | my $InstDb = "instdb.ins"; | |
13 | ||
14 | #- Define destination directory | |
15 | my $DestDir = "/usr/lib/openoffice"; | |
16 | ||
17 | #- Define the zipfiles dir (will be the same as of setup.ins) | |
18 | my $SetupDir = "."; | |
19 | ||
20 | #- Define Product Version and Name | |
21 | my ($ProductName, $ProductVersion) = ("OpenOffice.org", "1.0.1"); | |
22 | ||
23 | sub dirname { local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' } | |
24 | sub cat_ { local *F; open F, $_[0] or return; my @l = <F>; wantarray() ? @l : join '', @l } | |
25 | sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } | |
26 | sub output { my $f = shift; local *F; open F, ">$f" or die "output in file $f failed: $!\n"; print F foreach @_; 1 } | |
27 | ||
28 | sub mkdir_p { | |
29 | my ($dir) = @_; | |
30 | if (-d $dir) { | |
31 | # nothing to do | |
32 | } elsif (-e $dir) { | |
33 | die "mkdir: error creating directory $dir: $dir is a file and i won't delete it\n"; | |
34 | } else { | |
35 | mkdir_p(dirname($dir)); | |
36 | mkdir($dir, 0755) or die "mkdir: error creating directory $dir: $!\n"; | |
37 | } | |
38 | 1; | |
39 | } | |
40 | ||
41 | while ( $ARGV[0] =~ /^-/ ) { | |
42 | $_ = shift; | |
43 | if (m/^-d(=(\S+))?/) { | |
44 | $DestDir = $2 || shift; | |
45 | } | |
46 | elsif (m/^-z(=(\S+))?/) { | |
47 | $UnzipCommand = $2 || shift; | |
48 | } | |
49 | elsif (m/^-i(=(\S+))?/) { | |
50 | $SetupConf = $2 || shift; | |
51 | $SetupDir = dirname $SetupConf; | |
52 | } | |
53 | elsif (m/^-o(=(\S+))?/) { | |
54 | $InstDb = $2 || shift; | |
55 | } | |
56 | elsif (m/^-pn(=(\S+))?/) { | |
57 | $ProductName = $2 || shift; | |
58 | } | |
59 | elsif (m/^-pv(=(\S+))?/) { | |
60 | $ProductVersion = $2 || shift; | |
61 | } | |
62 | else { | |
63 | die "$0: Unknown option $_\n"; | |
64 | } | |
65 | } | |
66 | ||
67 | die "$0: Can't open $SetupConf\n" | |
68 | if ( ! -r $SetupConf ); | |
69 | ||
70 | die "$UnzipCommand not found, please set the full path to the unzip command\n" | |
71 | if ( ! -x "$UnzipCommand" ); | |
72 | ||
73 | my @exclude_modules = ( "GID_MODULE_OPTIONAL_GNOME", | |
74 | "gid_Module_Optional_Kde", | |
75 | "gid_Module_Optional_Cde" ); | |
76 | ||
77 | my ($zipfile, $instdb); | |
78 | my $is_archive = 0; | |
79 | foreach (cat_("$SetupConf"), "EndOfFile\n") { | |
80 | if (/^\s*Installation/ ... /^\s*End/) { | |
81 | if (/^\s*ScriptVersion/) { | |
82 | $instdb .= "\tDestPath\t = \"$DestDir\";\n"; | |
83 | $instdb .= "\tSourcePath\t = \"$DestDir/program\";\n"; | |
84 | $instdb .= "\tMode\t\t = NETWORK;\n"; | |
85 | $instdb .= "\tInstallFromNet = NO;\n"; | |
86 | } | |
87 | } | |
88 | elsif (/^\s*Module\s+(\w+)\s*/ ... /^\s*End/) { | |
89 | my $module = $1; | |
90 | if (/^\s*Files/ || /^\s*Styles.+HIDDEN_ROOT/) { | |
91 | my $state = member($module, @exclude_modules) ? "NO" : "YES"; | |
92 | $instdb .= "\tInstalled\t = $state;\n"; | |
93 | } | |
94 | } | |
95 | elsif (/^\s*File/ ... /^\s*End/) { | |
96 | if (/^\s*End/) { | |
97 | if ($is_archive) { | |
98 | my @filelist; | |
99 | foreach (cat_("$UnzipCommand -l $zipfile |")) { | |
100 | push @filelist, { size => $1, name => $2 } | |
101 | if (/^\s+([0-9]+)\s+[-0-9]+\s+[:0-9]+\s+(.+)\s+/); | |
102 | } | |
103 | $instdb .= "\tContains\t = ("; | |
104 | my $n = 0; | |
105 | foreach my $e (@filelist) { | |
106 | if (++$n > 10) { | |
107 | $instdb .= ",\n\t\t\t\t\t"; | |
108 | $n = 1; | |
109 | } | |
110 | elsif ($n > 1) { | |
111 | $instdb .= ", "; | |
112 | } | |
113 | $instdb .= "\"$e->{name}:$e->{size}\""; | |
114 | } | |
115 | $instdb .= ");\n"; | |
116 | $is_archive = 0; | |
117 | } | |
118 | } | |
119 | elsif (/^\s*Styles\s*=\s*.*ARCHIVE/) { | |
120 | $is_archive = 1; | |
121 | } | |
122 | elsif (/^\s*PackedName\s*=\s*"(\w+)"/) { | |
123 | $zipfile = "$SetupDir/$1"; | |
124 | die "$0: zip file $zipfile not accessible" | |
125 | if ( ! -r "$zipfile" ); | |
126 | } | |
127 | } | |
128 | $instdb .= $_ if !/^EndOfFile/; | |
129 | } | |
130 | ||
131 | # Implant Product Name and Version | |
132 | $instdb =~ s/%PRODUCTNAME/$ProductName/g; | |
133 | $instdb =~ s/%PRODUCTVERSION/$ProductVersion/g; | |
134 | $instdb =~ s/"<productkey>"/"$ProductName $ProductVersion"/g; | |
135 | $instdb =~ s/"<installmode>"/"NETWORK"/g; | |
136 | ||
137 | output $InstDb, $instdb; |