Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my($install_dir) = $ARGV[0];
- my($install_dir_logical) = 'C:';
- my($scriptname) = 'install_script.iss';
- if(!-d $install_dir) {
- print "Usage: $0 [install dir]\n";
- exit 1;
- }
- my $defaultdirname;
- my $defaultdirname_logical;
- my $current_subkey = '<None>';
- my $setup_section = 0;
- my $files_section = 0;
- my $registry_section = 0;
- sub eval_check {
- my($check) = @_;
- my(%atoms) = (
- 'IsWinXP' => 1,
- 'IsVISTA' => 0,
- 'IsWindows7' => 0,
- 'IsWindows32' => 1,
- 'IsWindows64' => 0,
- );
- $check =~ s@\band\b@&&@gi;
- while(my($key, $value) = each(%atoms)) {
- $check =~ s@\b$key\b@$value@egi;
- }
- eval $check;
- }
- sub esc_chars {
- # will change, for example, a!!a to a\!\!a
- $_[0] =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'" ])/\\$1/g;
- return $_[0];
- }
- sub any_case {
- my($filename) = @_;
- $filename =~ s@([a-zA-Z])@"[".lc($1).uc($1)."]"@ge;
- $filename;
- }
- open(SCRIPT, '<', $scriptname) or die "$scriptname not found";
- print "#/bin/sh -x\n";
- while(defined(my $line = <SCRIPT>)) {
- $line =~ s/[\n\r]+$//;
- # print STDERR "# $line\n";
- if($line =~ /^\[.*\]$/) {
- if($registry_section) {
- print "EOF\n";
- }
- $setup_section = $files_section = $registry_section = 0;
- $setup_section = 1 if $line eq '[Setup]';
- $files_section = 1 if $line eq '[Files]';
- $registry_section = 1 if $line eq '[Registry]';
- if($registry_section) {
- print "cat > install.reg <<EOF\nREGEDIT4\n";
- }
- }
- if($setup_section && $line =~ /^DefaultDirName=(.*)$/) {
- $defaultdirname = $defaultdirname_logical = $1;
- $defaultdirname =~ s@\\@/@g;
- $defaultdirname =~ s@{pf}@$install_dir."/Program Files"@e;
- $defaultdirname_logical =~ s@\{pf\}@${install_dir_logical}."\\Program Files"@e;
- }
- if($files_section && $line =~ /^Source: "(.*?)"; DestDir: "(.*?)"; (?:Components: "(.*?)"; )?(?:Flags: (.*))?$/) {
- my($source, $destdir, $components, $flags) = ($1, $2, $3, $4);
- $flags = '' unless defined $flags;
- if($flags !~ /dontcopy/) {
- $source =~ s@\\@/@g;
- if(-f $source) {
- $destdir =~ s@\\@/@g;
- $destdir =~ s@\{tmp\}@$install_dir."/windows/temp"@e;
- $destdir =~ s@\{app\}@$defaultdirname@e;
- my($source_filename) = $source;
- $source_filename =~ s@^.*/@@g;
- my($target) = "$destdir/$source_filename";
- if(!-f $target || $flags !~ /onlyifdoesntexist/) {
- print "mkdir -p ".esc_chars($destdir)."\n";
- print "cp -av ".any_case(esc_chars($source))." ".esc_chars($target)."\n";
- }
- }
- elsif ($flags !~ /skipifsourcedoesntexist/) {
- die "Source file $source missing";
- }
- }
- }
- if($registry_section && $line =~ /^Root: (.*?); Subkey: "(.*?)"; ValueName: "(.*?)"; ValueType: (.*?); ValueData: "(.*?)"; Components: "(.*?)"; (?:Check: "(.*?)"; )?Flags: (.*)$/) {
- my($root, $subkey, $valuename, $valuetype, $valuedata, $components, $check, $flags) = ($1, $2, $3, $4, $5, $6, $7);
- $check = '' unless defined $check;
- if($check eq '' || eval_check($check)) {
- my(%root_map) = (
- 'HKLM' => 'HKEY_LOCAL_MACHINE',
- 'HKLM64' => 'HKEY_LOCAL_MACHINE',
- 'HKCU' => 'HKEY_CURRENT_CONFIG',
- );
- die "Don't know how to handle registry root $root" if !exists $root_map{$root};
- my $full_subkey = "$root_map{$root}\\$subkey";
- if($current_subkey ne $full_subkey) {
- print "\n[$full_subkey]\n";
- $current_subkey = $full_subkey;
- }
- my(%value_map) = (
- 'String' => sub { "\"$_[0]\"" },
- 'Dword' => sub { $_[0] =~ s/^\$//; "dword:$_[0]" },
- );
- die "Don't know how to handle registry value type $valuetype" if !exists $value_map{$valuetype};
- $valuename =~ s@\{tmp\}@${install_dir_logical}."\\windows\\temp"@e;
- $valuename =~ s@\{app\}@$defaultdirname_logical@e;
- $valuedata =~ s@\{tmp\}@${install_dir_logical}."\\windows\\temp"@e;
- $valuedata =~ s@\{app\}@$defaultdirname_logical@e;
- print "\"$valuename\"=".(&{$value_map{$valuetype}}($valuedata))."\n";
- }
- }
- }
- close(SCRIPT);
- print "echo \"Don't forget to import install.reg in your environment with regedit\"";
Add Comment
Please, Sign In to add comment