5 #- Define full path to unzip command
6 my $UnzipCommand = "/usr/bin/unzip";
8 #- Define the default setup file
9 my $SetupConf = "setup.ins";
11 #- Define the generated instdb.ins file
12 my $InstDb = "instdb.ins";
14 #- Define destination directory
15 my $DestDir = "/usr/lib/openoffice";
17 #- Define the zipfiles dir (will be the same as of setup.ins)
20 #- Define Product Version and Name
21 my ($ProductName, $ProductVersion) = ("OpenOffice.org", "1.0.1");
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 }
33 die "mkdir: error creating directory $dir: $dir is a file and i won't delete it\n";
35 mkdir_p(dirname($dir));
36 mkdir($dir, 0755) or die "mkdir: error creating directory $dir: $!\n";
41 while ( $ARGV[0] =~ /^-/ ) {
43 if (m/^-d(=(\S+))?/) {
44 $DestDir = $2 || shift;
46 elsif (m/^-z(=(\S+))?/) {
47 $UnzipCommand = $2 || shift;
49 elsif (m/^-i(=(\S+))?/) {
50 $SetupConf = $2 || shift;
51 $SetupDir = dirname $SetupConf;
53 elsif (m/^-o(=(\S+))?/) {
54 $InstDb = $2 || shift;
56 elsif (m/^-pn(=(\S+))?/) {
57 $ProductName = $2 || shift;
59 elsif (m/^-pv(=(\S+))?/) {
60 $ProductVersion = $2 || shift;
63 die "$0: Unknown option $_\n";
67 die "$0: Can't open $SetupConf\n"
68 if ( ! -r $SetupConf );
70 die "$UnzipCommand not found, please set the full path to the unzip command\n"
71 if ( ! -x "$UnzipCommand" );
73 my @exclude_modules = ( "GID_MODULE_OPTIONAL_GNOME",
74 "gid_Module_Optional_Kde",
75 "gid_Module_Optional_Cde" );
77 my ($zipfile, $instdb);
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";
88 elsif (/^\s*Module\s+(\w+)\s*/ ... /^\s*End/) {
90 if (/^\s*Files/ || /^\s*Styles.+HIDDEN_ROOT/) {
91 my $state = member($module, @exclude_modules) ? "NO" : "YES";
92 $instdb .= "\tInstalled\t = $state;\n";
95 elsif (/^\s*File/ ... /^\s*End/) {
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+/);
103 $instdb .= "\tContains\t = (";
105 foreach my $e (@filelist) {
107 $instdb .= ",\n\t\t\t\t\t";
113 $instdb .= "\"$e->{name}:$e->{size}\"";
119 elsif (/^\s*Styles\s*=\s*.*ARCHIVE/) {
122 elsif (/^\s*PackedName\s*=\s*"(\w+)"/) {
123 $zipfile = "$SetupDir/$1";
124 die "$0: zip file $zipfile not accessible"
125 if ( ! -r "$zipfile" );
128 $instdb .= $_ if !/^EndOfFile/;
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;
137 output $InstDb, $instdb;