Fixed: tools/wineconf and tools/wineinstall

Speeddymon speeddymon at yahoo.com
Mon Apr 15 11:35:09 CDT 2002


Hey guys, I'm new to the wine-patches list, but I
found a couple problems (at least on my setup) with
wineconf and wineinstall...

I'll tell you what I did to duplicate the problem...

1) I downloaded the 20020411 snapshot from ibiblio.org
2) as root, untarred/gzipped the snapshot to ~/wine-
     20020411
3) cd'ed to ~/wine-20020411
4) ran ./tools/wineinstall and was promptly told that
     i have to be a user
4) mv'ed ~/wine-20020411 to
/home/speeddy/wine-20020411
5) logged out and logged in as speeddy
6) tried to access /home/speeddy/wine-20020411
(~/wine-
     20020411) and was denied permission
7) chuser/chgrp'ed ~/wine-20020411 to speeddy/speeddy
8) entered the directory
9) ran ./tools/wineinstall

it ran as normal, and configured/compiled itself...got
all the way to justbefore it was supposed to install
the registry and then sat there for over 30 minutes...

I ctrl+c'ed it and did make uninstall, removed the dir
and went thru the install process again...same thing

So, I did some editing to the file to figure out
exactly where it was stopping at and found out that
it's stopping at:

if [ "$DOREG" = 'auto' ]
then {
>>  CROOT=`sed -n '/^\[Drive C\]$/,/^\[.*\]$/ 
     s/^Path=\(.*\)/\1/p' $CONF`  <<
  echo "Checking for real Windows registry..."

the line with the >> and <<

so I went to the top of the file and did a search for
CONF=...no matches...did a search for $CONF...that was
the only match (aside from $CONFARGS)

so I figured that the input file was supposed to be
~/.wine/config and typed in the sed command with all
the args/params exactly as shown (except that $CONF
was replaced with ~/.wine/config) and it
ran/exited...then I ran it again except with /dev/null
and it just sat there (as it did before) without
exiting...

so I changed $CONF in the file to $LCONF and re-ran
it...it actually finished that time, but there were
some things that didnt go as I had expected...

Oh, by the way, sorry for the long email...

It found my backup (Win98) drive and called it my real
drive C, which it wasn't (had win98, but i dont use
it), so i moved it down in my fstab and
re-tried...same thing...looked at wineconf and figured
out that it was because my win2k drive is ntfs and
wineconf doesn't check for that...so I added that
check as a separate if (so that it can setup the type
entry in the wine conf as win95 and not ntfs),
alexandre, if you dont want the check for that, go
ahead and take it out...  dont have a problem with
that

it also didnt find my cd-rom drive...that was due to
supermount, so I added a check for supermount drives
mounted on /cdrom and /mnt/cdrom and while i was doing
that I also noticed that there was a check if just the
mountpoint is /cdrom so i changed it to check for that
and no supermount...the supermount check is a separate
if (so it gets /dev/cdrom) someone that knows more
perl than i will have to correct the device for
supermount cd-roms, as it only works for 1 cd-rom the
way i wrote it...

then it didnt find my win2k registry (as if i dont
have enough to worry about)...no check for
$CROOT/WINNT/system32/config/system
(clean install of win2k),
but yet it does check for
$CROOT/windows/system32/config/system
(upgrade from win98/me)...hmmm

but that wasn't all....it still didnt find it, so I
was like "WTF?!"...$CROOT wasnt being set after all...
so I re-ran the sed script and (big surprise) it
returns null...

that turned out to be a problem because I didnt know
jack about sed before that time, but the man document
pointed me in the right direction (the info document)
where i was able to decrypt (with a lot of thinking)
what the stream script was saying and fix it...

this was the problem:

s/^Path=\(.*\)/\1/p

it needed to be:

s/^\"Path\" = \"\(.*\)\"/\1/p

note the inserted spaced and (escaped) quotes and
their positions...  sed couldn't find
'Path=(anything)' anywhere in the drive c section
(because it doesn't exist)
now it finds '"Path" = "(anything)"' in the drive c
section (like it should)

if anyone finds an unknown bug in my fixes, please let
me know so i can fix it...

Known Bugs:

wineconf check for supermount always gives cdrom's
device /dev/cdrom (instead of proper name for 2nd/3rd
cdrom)

-Dustin Navea

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
-------------- next part --------------
#!/usr/bin/perl -w

# This program generates wine.conf files on STDOUT.
# Copyright (C) 1996 Stephen Simmons
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# NOTES:
#
# This program examines the contents of the DOS filesystems and
# attempts to generate a sensible wine.conf file.  This is output
# to STDOUT.
# It reads /etc/fstab to find mounting locations of the hard disk drives
# It uses the correct algorithm for ordering DOS drives, with the
# exception of the case of multiple drive controller types, where I don't
# know what DOS's algorithm is.
# It uses find to find all of the win.ini files on any DOS partition
# and sorts them by age to guess which is part of the active Windows
# installation.
# It reads the autoexec.bat file (if found) and records all variable
# settings.   There are some inaccuracies in its determination.
# First, while variables are interpolated properly, no control
# structures are supported so calls and execs to other batch files are
# ignored, and all variable settings take effect regardless of whether
# they would in DOS (i,e., both if and else clauses are read).
# This is used to determine the path and temp directories.  Duplicate
# path directories and path directories that don't exist are thrown
# out.
# On failing to find C:\AUTOEXEC.BAT, wineconf finds all executables
# in the windows directory and subdirectories, and generates an
# optimized path statement encompassing all the executables.
# Then it also looks for \TEMP and \TMP on all drives taking the first
# one it finds.
# wineconf doesn't support floppy drives, network drives, printers,
# and serial device configuration is hardcoded and not configured for
# the machine it runs on.  Similarly, spy parameters are hard coded.

# It would make sense to incorporate much of the heuristic code in
# this program into a library to be shared with a dosemu configuration
# program, because it seems that at least some of the same stuff will
# be wanted.  The program needs to be cleaned up still.  A better tmp
# search algorithm could be written.  A fast option is planned.  Less
# Linux-dependence is desired.  Should look for devices independent
# of /etc/fstab; then sanity checks on /etc/fstab can be performed.

use Getopt::Long;
use File::Basename;
use strict;
use Carp;

GetOptions('windir=s', 'sysdir=s', 'thorough', 'debug:s', 'inifile=s') || &Usage;

print "WINE REGISTRY Version 2\n";
print ";; All keys relative to \\\\Machine\\\\Software\\\\Wine\\\\Wine\\\\Config\n\n";
&ReadFSTAB();
&FindWindowsDir();
&ReadAutoexecBat();
&StandardStuff();

sub Usage {
    print "Usage: $0 <options>\n";
#    print "-fstab <filename>    Location of alternate fstab file\n";
    print "-windir <filename>   Location of windows dir in DOS space\n";
    print "-thorough            Do careful analysis (default)\n";
    print "-sysdir <filename>   Location of systems dir in DOS space\n";
    print "-inifile <filename>  Path to the wine.ini file (by default './wine.ini')\n";
#    print "-tmpdir <filename>   Location of tmp directory\n";
    print "Generates (to STDOUT) a wine configuration file based on\n";
    print "/etc/fstab and searching around in DOS directories\n";
    print "The options above can override certain values\n";
    print "This should be considered ALPHA code\n";
    exit(0);
}

sub ReadFSTAB {
    $::opt_f = $::opt_f ? $::opt_f : '/etc/fstab';
    open(FSTAB, $::opt_f) || die "Cannot read $::opt_f\n";
    while(<FSTAB>) {
	next if /^\s*\#/;
	next if /^\s*$/;

	my ($device, $mntpoint, $type, @rest) = split(' ', $_);
	if ($device !~ m"^/dev/fd") {
	    if ($type eq "ntfs") {
		push(@::FatDrives, [$device, $mntpoint, 'win95']);
	    }
	    elsif ($type eq "msdos" || $type eq "vfat") {
		push(@::FatDrives, [$device, $mntpoint, $type]);
	    }
	    elsif ($type eq "iso9660" ||
		   ($mntpoint eq "/cdrom" && ! $type eq 'supermount') ||
		   ($device eq '/dev/cdrom' && $type eq 'auto') ) {
		push(@::CdromDrives, [$device, $mntpoint, 'win95']);
	    }
	    elsif ( ($mntpoint eq '/mnt/cdrom' || $mntpoint eq '/cdrom') 
		  && $type eq 'supermount') {
		push(@::CdromDrives, [ '/dev/cdrom', $mntpoint, 'win95']);
	    }
	}
    }
    if (!@::FatDrives) {
	warn "ERROR ($0): Cannot find any MSDOS drives.\n";
	warn "This does not mean you cannot run Wine, but $0\n";
	warn "cannot help you (yet)\n";
	exit(1);
    }
    push(@::UnixDrives, ['', '/tmp', 'hd']);
    push(@::UnixDrives, ['', '${HOME}', 'network']);
    my $MagicDrive = 'C';
    @::FatDrives = sort byDriveOrder @::FatDrives;
    @::CdromDrives = sort byCdOrder @::CdromDrives;
    foreach my $FatDrive (@::FatDrives) {
	print "[Drive $MagicDrive]\n";
	my $MntPoint = $FatDrive->[1];
	my $FileSys = $FatDrive->[2];
	print "\"Path\" = \"$MntPoint\"\n";
	print "\"Type\" = \"hd\"\n";
	print "\"Filesystem\" = \"$FileSys\"\n";
	print "\n";
	&RegisterDrive($MagicDrive, $FatDrive);
	if(!&IsMounted($FatDrive->[0])) {
	    warn "WARNING: DOS Drive $MagicDrive (" . $FatDrive->[0] . 
		") is not mounted\n";
	}
	$MagicDrive++;
    }
    foreach my $CdromDrive (@::CdromDrives) {
	print "[Drive $MagicDrive]\n";
	my $Device = $CdromDrive->[0];
	my $MntPoint = $CdromDrive->[1];
	my $FileSys = $CdromDrive->[2];
	print "\"Path\" = \"$MntPoint\"\n";
	print "\"Type\" = \"cdrom\"\n";
	print "\"Device\" = \"$Device\"\n";
	print "\"Filesystem\" = \"$FileSys\"\n";
	print "\n";
	&RegisterDrive($MagicDrive, $CdromDrive);
	$MagicDrive++;
    }
    foreach my $UnixDrive (@::UnixDrives) {
	print "[Drive $MagicDrive]\n";
	my $MntPoint = $UnixDrive->[1];
	my $Type = $UnixDrive->[2];
	print "\"Path\" = \"$MntPoint\"\n";
	print "\"Type\" = \"$Type\"\n";
	print "\"Filesystem\" = \"win95\"\n";
	print "\n";
	$MagicDrive++;
    }
}

sub FindWindowsDir {
    my($MagicDrive) = 'C';
    my(@FATD)=@::FatDrives;
    my(@wininis) = ();
    my ($winini);
    my ($ThisDrive);

    if (!$::opt_windir && !$::opt_fast && !$::opt_thorough) {
	$::opt_thorough++;
    }
    if ($::opt_windir) {
	$winini = &ToUnix($::opt_windir);
	if (!-e $winini) {
	    die "ERROR: Specified winini file does not exist\n";
	}
    }
    elsif ($::opt_fast) {
	die "-fast code can be implemented\n";
    }
    elsif ($::opt_thorough) {
	if ($::opt_debug) { print STDERR "DEBUG: Num FATD = ", $#FATD+1, "\n"; }
       foreach $ThisDrive (@FATD) {
	    my $MntPoint = $ThisDrive->[1];
	    push(@wininis, `find $MntPoint -iname win.ini -print`);
	}
	foreach $winini (@wininis) {
	    chomp $winini;
	}
	my ($winini_cnt) = $#wininis+1;
	if ($::opt_debug) { 
	    print STDERR "DEBUG: Num wininis found: $winini_cnt\n";}
	if ($winini_cnt > 1) {
	    warn "$winini_cnt win.ini files found:\n";
	    @wininis = sort byFileAge @wininis;
	    warn join("\n", @wininis), "\n";
	    $winini = $wininis[0];
	    warn "Using most recent one: $winini\n";
	}
	elsif ($winini_cnt == 0) {
	    die "ERROR: No win.ini found in DOS partitions\n";
	}
	else {
	    $winini = $wininis[0];
	}
    }
    else {
	die "ERROR: None of -windir, -fast, or -thorough set\n";
    }
    $::windir = &ToDos(dirname($winini));
    print "[wine]\n";
    print "\"windows\" = ", &marshall ($::windir), "\n";
    if ($::opt_sysdir) {
	print "\"system\" = ", &marshall ($::opt_sysdir), "\n";
    }
    else {
	print "\"system\" = ", &marshall ("$::windir\\SYSTEM"), "\n";
    }
}

# Returns 1 if the device is mounted; -1 if mount check failed; 0 if not
# mounted.
# This code is Linux specific, and needs to be broadened.
sub IsMounted {
    my($Device) = @_;
    if (-d "/proc") {
	if (-e "/proc/mounts") {
	    open(MOUNTS, "/proc/mounts") || 
		(warn "Cannot open /proc/mounts, although it exists\n" &&
		 return -1);
	    while(<MOUNTS>) {
		if (/^$Device/) { 
		    return 1; # Tested 1.4
		}
	    }
	    return 0; # Tested 1.4
	}
    }
    return -1;
}

sub RegisterDrive {
    my($DOSdrive, $Drive) = @_;
    $::DOS2Unix{$DOSdrive} = $Drive;
    $::Device2DOS{$Drive->[0]} = $DOSdrive;
    $::MntPoint2DOS{$Drive->[1]} = $DOSdrive;
    $::DOS2MntPoint{$DOSdrive} = $Drive->[1];
    $::DOS2Device{$DOSdrive} = $Drive->[0];
}

sub ReadAutoexecBat {
    if (!%::DOS2Unix) { &ReadFSTAB; }
    my($DriveC) = $::DOS2MntPoint{"C"};
    $DriveC =~ s%/$%%;
    my($path);
    if ($::opt_debug) { 
	print STDERR "DEBUG: Looking for $DriveC/autoexec.bat\n"; }
    if (-e "$DriveC/autoexec.bat") {
	# Tested 1.4
        open(AUTOEXEC, "$DriveC/autoexec.bat") || 
            die "Cannot read autoexec.bat\n";
        while(<AUTOEXEC>) {
	    s/\015//;
            if (/^\s*(set\s+)?(\w+)\s*[\s\=]\s*(.*)$/i) {
		my($varname) = $2;
	        my($varvalue) = $3;
		chomp($varvalue);
		$varname =~ tr/A-Z/a-z/;
		while ($varvalue =~ /%(\w+)%/) {
		    my $matchname = $1;
		    my $subname = $1;
		    $subname =~ tr/A-Z/a-z/;
		    if (($::opt_debug) && ($::opt_debug =~ /path/i)) {
			print STDERR "DEBUG: Found $matchname as $subname\n";
			print STDERR "DEBUG: Old varvalue:\n$varvalue\n";
			print STDERR "DEBUG: Old subname value:\n" .
			    $::DOSenv{$subname} . "\n";
		    }
		    if ($::DOSenv{$subname}) {
			$varvalue =~ s/\%$matchname\%/$::DOSenv{$subname}/;
		    }
		    else {
			warn "DOS environment variable $subname not\n"; 
			warn "defined in autoexec.bat. (Reading config.sys\n";
			warn "is not implemented.)  Using null value\n";
			$varvalue =~ s/%$matchname%//;
		    }
		    if (($::opt_debug) && ($::opt_debug =~ /path/i)) {
			print STDERR "DEBUG: New varvalue:\n$varvalue\n";
		    }
		}
		if ($::opt_debug) {
		    print STDERR "DEBUG: $varname = $varvalue\n";
		}
		$::DOSenv{$varname} = $varvalue;
            }
        }
	close(AUTOEXEC);
    }
    else {
	# Tested 1.4
	warn "WARNING: C:\\AUTOEXEC.BAT was not found.\n";
    }

    if ($::DOSenv{"path"}) {
	my @pathdirs = split(/\s*;\s*/, $::DOSenv{"path"});
	if (($::opt_debug) && ($::opt_debug =~ /path/i)) {
	    print STDERR "DEBUG (path): @pathdirs\n";
	}
	foreach my $pathdir (@pathdirs) {
	    if (-d &ToUnix($pathdir)) {
		if ($::DOSpathdir{$pathdir}++) {
		    warn "Ignoring duplicate DOS path entry $pathdir\n";
		}
		else {
		    if (($::opt_debug) && ($::opt_debug =~ /path/i)) {
			print STDERR "DEBUG (path): Found $pathdir\n";
		    }
		    push(@::DOSpathlist, $pathdir);
		}
	    }
	    else {
	        warn "Ignoring DOS path directory $pathdir, as it does not\n";
		warn "exist\n";
	    }
	}
	print "\"path\" = ", &marshall (join (";", @::DOSpathlist)), "\n";
    }
    else {
	# Code status: tested 1.4
	warn "WARNING: Making assumptions for PATH\n";
	warn "Will scan windows directory for executables and generate\n";
	warn "path from that\n";
	my $shellcmd = 'find ' . &ToUnix($::windir) . " -iregex '" .
	    '.*\.\(exe\|bat\|com\|dll\)' . "' -print";
	if ($::opt_debug) { 
	    print STDERR "DEBUG: autoexec.bat search command:\n $shellcmd\n";
	}
	push(@::DOScommand, `$shellcmd`);
	if ($::opt_debug && $::opt_debug =~ /autoexec/i) { 
	    print STDERR "DEBUG: autoexec.bat search results:\n\@DOS::command\n";
	}
	foreach my $command (@::DOScommand) {
	    $command =~ s%[^/]+$%%;
	    $::DOSexecdir{&ToDos($command)}++;
	}
	print "\"path\" = " .
	    &marshall (join(";", 
			    grep(s%\\$%%, 
				 sort {$::DOSexecdir{$b} <=> $::DOSexecdir{$a}}
				 (keys %::DOSexecdir)))) . "\n";
    }

    if ($::DOSenv{"temp"} && -d &ToUnix($::DOSenv{"temp"})) {
	print "\"temp\" = ", &marshall ($::DOSenv{"temp"}), "\n";
    }
    else {
        my $TheTemp;

        warn "WARNING: Making assumptions for TEMP\n";
	warn "Looking for \\TEMP and then \\TMP on every drive\n";
	# Watch out .. might pick CDROM drive :-)
	foreach my $DOSdrive (keys %::DOS2Unix) {
	    my $tmp = &ToUnix("$DOSdrive:\\temp");
	    if (-d $tmp) { $TheTemp = "$DOSdrive:\\temp"; last; }
	    $tmp = &ToUnix("$DOSdrive:\\tmp");
	    if (-d $tmp) { $TheTemp = "$DOSdrive:\\tmp"; last; }
	}
	$TheTemp = '/tmp' if (!$TheTemp && -d '/tmp');
	if ($TheTemp) {
	    warn "Using $TheTemp\n";
	    print "\"temp\" = ", &marshall ($TheTemp), "\n";
	}
	else {
	    warn "Using C:\\\n";
	    print "\"temp\" = ", &marshall ("C:\\"), "\n";
	}
    }
    print "\n";
}

# FNunix = &ToUnix(FNdos);
#   Converts DOS filenames to Unix filenames, leaving Unix filenames
#   untouched.
sub ToUnix {
    my($FNdos) = @_;
    my($FNunix);

    # Initialize tables if necessary.
    if (!%::DOS2Unix) { &ReadFSTAB; }

    # Determine which type of conversion is necessary
    if ($FNdos =~ /^([A-Z])\:(.*)$/) { # DOS drive specified
	$FNunix = $::DOS2MntPoint{$1} . "/$2";
    }
    elsif ($FNdos =~ m%\\%) { # DOS drive not specified, C: is default
	$FNunix = $::DOS2MntPoint{"C"} . "/$FNdos";
    }
    else { # Unix filename
	$FNunix = $FNdos;
    }
    1 while ($FNunix =~ s%\\%/%);    # Convert \ to /
    $FNunix =~ tr/A-Z/a-z/;          # Translate to lower case
    1 while ($FNunix =~ s%//%/%);    # Translate double / to /
    return $FNunix;
}

# FNdos = &ToDOS(FNunix)
#   Converts Unix filenames to DOS filenames
sub ToDos {
    my($FNunix) = @_;
    my(@MntList) = keys %::MntPoint2DOS;
    my ($TheMntPt, $FNdos);

    foreach my $MntPt (@MntList) { # Scan mount point list to see if path matches
	if ($FNunix =~ /^$MntPt/) {
	    $TheMntPt = $MntPt;
	    last;
	}
    }
    if (!$TheMntPt) {
	Carp("ERROR: $FNunix not found in DOS directories\n");
	exit(1);
    }
    $FNdos = $FNunix;
    $FNdos =~ s/^$TheMntPt//;
    $FNdos = $::MntPoint2DOS{$TheMntPt} . ":" . $FNdos;
    1 while($FNdos =~ s%/%\\%);
    return $FNdos;
}

sub InsertDefaultFile {
    my ($fileName, $tag) = @_;
    my $state = 0;

    if (open(DEFFILE, "$fileName")) {
       while (<DEFFILE>) {
	  $state = 0 if ($state == 1 && $_ =~ /^[ \t]*\#/o && index($_, "</$tag>") >= 0);
	  print $_ if ($state == 1);
	  $state = 1 if ($state == 0 && $_ =~ /^[ \t]*\#/o && index($_, "<$tag>" ) >= 0);
       }
       close(DEFFILE);
    } else {
       print STDERR "Cannot read $fileName\n";
    }
}

sub marshall {
    my ($s) = @_;
    $s =~ s/\\/\\\\/g;
    return "\"$s\"";
}


sub StandardStuff {
    if (!$::opt_inifile) {
	&InsertDefaultFile("./wine.ini", "wineconf");
    } else {
	&InsertDefaultFile($::opt_inifile, "wineconf");
    }
}

sub byFileAge {
    -M $a <=> -M $b;
}

sub byDriveOrder {
    my($DeviceA) = $a->[0];
    my($DeviceB) = $b->[0];

    # Primary drives come first, logical drives last
    # DOS User's Guide (version 6) p. 70, IBM version.
    # If both drives are the same type, sort alphabetically
    # This makes drive a come before b, etc.
    # It also makes SCSI drives come before IDE drives;
    # this may or may not be right :-(
    my($Alogical, $Blogical);
    if (substr($DeviceA, 3, 1) >= 5) { $Alogical++; }
    if (substr($DeviceB, 3, 1) >= 5) { $Blogical++; }
    if ($Alogical && !$Blogical) { return -1; }
    elsif ($Blogical && !$Alogical) { return 1; }
    else { return ($DeviceA cmp $DeviceB); }
}

sub byCdOrder {
    my($DeviceA) = $a->[0];
    my($DeviceB) = $b->[0];
    $DeviceA cmp $DeviceB;
}
-------------- next part --------------
#!/bin/bash
# WINE Installation script
# Can do almost everything from compiling to configuring...
#
# Copyright 1999 Ove Kåven
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# History:
# Mar 31 1999 - Ove Kåven
#  First version
# Dec 9 1999 - Ove Kåven
#  require Xpm
# Feb 25 2000 - Ove Kåven
#  auto-add /usr/local/lib to /etc/ld.so.conf
# Mar 2 2000 - Ove Kåven
#  source rather than grep config.cache
#  use sourced config.cache to start ldconfig
#  reconfigure if config.cache doesn't exist
# Mar 30 2000 - Ove Kåven
#  autoconfigure no-windows installs
#  do not install registry on real-windows installs
#  some support for binary package installs
#  set and tell user about LD_LIBRARY_PATH if necessary
#  set EXTRA_LD_LIBRARY_PATH in wine.conf
# Apr 9 2000 - Ove Kåven
#  make root's registry global (system-default)
# May 9 2000 - Ove Kåven
#  use ttydrv when running regapi, so we don't have to run from X
#  change debugger path in registry
# Oct 29 2000 - Ove Kåven
#  added --enable-opengl to default confargs
#  added conf_question, conf_yesno_answer, and conf_string_answer functions
#  added DEFCAT variable
# (later that day...)
#  added conf_reset_question function
#  added file existence checks to the registry copying
#  fixed problem with no-windows directory creation
#  some text reformatting from Eric Maryniak
# Jan 5 2000 - Chris Morgan
#  use default config file in /documentation/samples/config
#  replace .winerc with ~/.wine/config in printed text
#  added user question to convert .winerc file(if exists) or use the default
#    config file
#  add conf_question to allow root to install a local config file and
#    registry
# Jan 12 2000 - Chris Morgan
#  distinguish between creating local and global config files
#  display a message about the status of global config files
#  misc cleanups and reordering of questions
#  added check to see if wine is installed when we are running as a normal
#    user and print a message if wine cannot be found
# Feb 16 2002 - Adam D. Moss
#  Use config.status instead of config.cache to check whether we're
#    configured/compiled and to recreate the configuration
# Feb 20 2002 - Adam D. Moss
#  Partially revert previous changes, force configure to write an
#    old-style config.cache
# Mar 27 2002 - Chris Morgan
#  prevent the user from running wineinstall as root
#  add script commands so we su root for 'make install' and other commands
#    that require root access
#  add text to tell the user we need to run stuff as root so they don't 
#    think we are trying to pull something funny
# Apr 14 2002 - Dustin Navea
#  tools/wineconf: fix to find Win2k on ntfs partitions (still read-only 
#   tho)
#  tools/wineconf: fix to find non-supermount cd-rom drives (when mounted 
#   at /cdrom)
#  tools/wineconf: fix to find supermount cd-rom drives and give it proper 
#   device name (long as there is only 1 cd-rom)
#  Fix sed string when finding real-windows registry so it actually 
#   accesses a file (~/.wine/config) instead of null ($CONF?!)
#  Added search for clean-install (not upgrade) Win2k registry
#  (next day, after some sleep)
#  Fix sed string when finding real-windows registry to actually find 
#   windows partition name in [Drive C] section
#  it should now always find the windows partition and real-windows 
#  registry (if not, let me know)

#--- defaults (change these if you are a packager)
CONFARGS="--enable-opengl"    # configure args, e.g. --prefix=/usr --sysconfdir=/etc
prefix=/usr/local             # installation prefix
sysconfdir=$prefix/etc        # where wine.conf and global registry is supposed to be
bindir=$prefix/bin            # where winelib apps will be (or is) installed
libdir=$prefix/lib            # where libwine.so will be (or is) installed
exdir=documentation/samples   # where the example system.ini resides
GCONF=$sysconfdir/wine.conf   # default path of the wine.conf global config file
LCONF=~/.wine/config          # default path of the local config file
BINDIST=no                    # whether called from a binary package config script
DOGLOBALCONF=auto             # whether to autogenerate wine.conf
DOLOCALCONF=auto              # whether to autogenerate localconf
DOWCHK=auto                   # whether to autoconfigure existing-windows installation
DOWINE=auto                   # whether to autoconfigure no-windows installation
DOREG=auto                    # whether to install default registry
SYSREG=yes                    # whether to make root's registry global (system-default)
CONVCONF=no		      # whether we are converting an existing .winerc or not

# "make install" still installs the dlls into $libdir, but this may change in the future
# (DLLPATH should point to them if/when they are not in standard ld.so paths)
DLLPATH=$libdir/wine          # default path of the dll .so files (except libwine.so)

# having the Wine debugger launched automatically will be a plus for us
DEBUGGER=$bindir/winedbg      # the (installed) path of winedbg
HDEBUGGER=debugger/winedbg    # the (non-installed) path of winedbg

# this is only for existing-windows installs
WINECONF=tools/wineconf       # the path of wineconf perl script

# this is only for no-windows installs
WINEINI=$exdir/config         # the path of default wine config file (also used by wineconf)
WININI=/dev/null              # the path of default win.ini
SYSTEMINI=$exdir/system.ini   # the path of default system.ini
REGAPI=programs/regapi/regapi # the path of regapi winelib application
DEFREG=winedefault.reg        # the path of the registry file to be fed to regapi
# CROOT=/var/wine             # the path of the fake Drive C (asks user if not set)
DEFCAT=cat                    # program to cat $DEFREG with (some packages need zcat)
#--- end of defaults

# temporary files used by the installer
TMPCONF=/tmp/wineinstall.conf
TMPREG=/tmp/wineinstall.reg

# functions

function std_sleep {
  sleep 1
}

function conf_question {
  # parameters: $1 = importance, $2 = question-id, $3+ = message lines
  # the first two parameters can be used by e.g. debconf in debian packages
  # but here we just print the message
  shift 2
  echo
  local LINE="$1"
  while shift
  do {
    echo "$LINE"
    LINE="$1"
  }
  done
}

function conf_reset_question {
  # parameters: $1 = question-id
  # this is used to flush any cached answers and "already-displayed" flags
  shift # dummy command
}

function conf_yesno_answer {
  unset ANSWER
  while [ "$ANSWER" != 'yes' ] && [ "$ANSWER" != 'no' ]
  do {
    echo -n "$1"
    read ANSWER
  }
  done
}

function conf_string_answer {
  echo -n "$1"
  read ANSWER
}

function create_windows_directories {
  for tdir in "$CROOT/windows" "$CROOT/windows/system" \
              "$CROOT/windows/Start Menu" "$CROOT/windows/Start Menu/Programs" \
              "$CROOT/Common Files" "$CROOT/Program Files" \
              "$CROOT/windows/Profiles" "$CROOT/windows/Profiles/Administrator"
  do [ -d "$tdir" ] || mkdir "$tdir"
  done
  [ -f "$CROOT/windows/win.ini" ]    || cp "$WININI"    "$CROOT/windows/win.ini"
  [ -f "$CROOT/windows/system.ini" ] || cp "$SYSTEMINI" "$CROOT/windows/system.ini"
}

# startup...

echo "WINE Installer v0.72"
echo

if [ "$BINDIST" = 'no' ]
then {

if ! [ -f configure ]
then {
  echo "You're running this from the wrong directory."
  echo "Change to the Wine source's main directory and try again."
  exit 1
}
fi

if [ `whoami` == 'root' ]
then {
  echo "You are running wineinstall as root, this is not advisable. Please rerun as a user."
  echo "Aborting."
  exit 1
}
fi

# check whether RPM installed, and if it is, remove any old wine rpm.
hash rpm &>/dev/null
RET=$?
if [ $RET -eq 0 ]; then
  if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
    echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
    conf_yesno_answer "(yes/no) "
    if [ "$ANSWER" = 'yes' ]; then
      echo "We need to remove the rpm as root, please enter your root password"
      echo
      echo Starting wine rpm removal...
      su -c "rpm -e wine; RET=$?"
      if [ $RET -eq 0 ]; then
        echo Done.
      else
        echo "FAILED. Probably you aren't installing as root."
	echo "Expect problems (library conflicts with existing install etc.)."
      fi
    else
      echo "Sorry, I won't install Wine when an rpm version is still installed."
      echo "(Wine support suffered from way too many conflicts between RPM"
      echo "and source installs)"
      echo "Have a nice day !"
      exit 1
    fi 
  fi
fi

# check whether wine binary still available
if [ -n "`which wine`" ]; then
  echo "Warning !! wine binary (still) found, which may indicate"
  echo "a (conflicting) previous installation."
  echo "You might want to abort and uninstall Wine first."
  std_sleep
fi

# run the configure script, if necessary

if [ -f config.cache ] && [ -f Makefile ] && [ Makefile -nt configure ]
then {
  echo
  echo "I see that WINE has already been configured, so I'll skip that."
  std_sleep
  # load configure results
  . ./config.cache
}
else {
  echo "Running configure..."
  echo
  if ! ./configure -C $CONFARGS
  then {
    echo
    echo "Configure failed, aborting install."
    rm -f config.cache
    exit 1
  }
  fi
  # load configure results
  . ./config.cache
  # make sure X was found
  eval "$ac_cv_have_x"
  if [ "$have_x" != "yes" ]
  then {
    echo "Install the X development headers and try again."
    rm -f config.cache
    exit 1
  }
  fi
}
fi

# now do the compilation and install, we need to always do this because we 
# don't want the 'make install' command we might run to run 'make' as root
if [ `whoami` != 'root' ]
then {
  # ask the user if they want to build and install wine
  echo
  echo "We need to install wine as root user, do you want us to build wine,"
  echo "'su root' and install Wine?  Enter 'no' to continue without installing"
  conf_yesno_answer "(yes/no) "

  if [ "$ANSWER" = "yes" ]
  then {
    # start out with the basic command
    sucommand="make install"

    # if the user doesn't have $libdir in their ld.so.conf add this
    # to our sucommand string
    if [ -f /etc/ld.so.conf ] && ! grep -qs "$libdir" /etc/ld.so.conf
    then {
      echo
      echo "$libdir doesn't exist in your /etc/ld.so.conf, it will be added"
      echo "when we perform the install..."
      sucommand="echo $libdir>>/etc/ld.so.conf;ldconfig;$sucommand"
    }
    fi

    echo

    echo "Compiling WINE. Grab a lunch or two, rent a video, or whatever,"
    echo "in the meantime..."
    echo
    std_sleep

    # try to just make wine, if this fails 'make depend' and try to remake
    if ! { make; }
    then {
      if ! { make depend && make; }
      then {
        echo
        echo "Compilation failed, aborting install."
        exit 1
      }
      fi
    }
    fi
    echo

    echo "Performing 'make install' as root to install binaries, enter root password"

    std_sleep

    if ! su root -c"$sucommand"
    then {
      echo
      echo "Either you entered an incorrect password or we failed to run"
      echo "'$sucommand' correctly."
      echo "If you didn't enter an incorrect password then please report this"
      echo "error to wine-devel at winehq.com."
      echo
      echo "Installation failed, aborting."
      exit 1
    }
    fi

    echo

    # see if wine is installed on the users system, if not prompt them
    # and then exit
    if [ ! `which wine` ]
    then
      echo "Could not find wine on your system.  Run wineinstall as root to install wine"
      echo "before re-running wineinstall as a user."
      echo
      echo "Exiting wineinstall"
      exit 1;
    fi
  }
  else {
    # user didn't want to install wine so tell them about running from the
    # current directory and set some stuff up for them

    # setup to run from current directory
    DLLPATH="$PWD/dlls"
    if [ -z "$LD_LIBRARY_PATH" ]
    then LD_LIBRARY_PATH="$PWD:$DLLPATH"
    else LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD:$DLLPATH"
    fi
    export LD_LIBRARY_PATH
    DEBUGGER="$PWD/$HDEBUGGER"
    echo
    echo "NOTE! To run Wine without installing, you must set the environment variable"
    echo "LD_LIBRARY_PATH to $PWD:$DLLPATH"
    echo "in your logon scripts."
    echo
  }
  fi
}
else {
  echo "You are running wineinstall as root, this is not advisable. Please rerun as a user."
  echo "Aborting."
  exit 1
}
fi # [ `whoami` != 'root' ]

}
fi # BINDIST

# now check whether we should generate wine.conf
if [ -z "$DOGLOBALCONF" ]
then
  DOGLOBALCONF=auto
fi

if [ "$DOGLOBALCONF" = 'auto' ]
then {
  # see if we already have a system wine.conf
  if [ ! -f $GCONF ] && [ `whoami` = 'root' ]
  then
    DOGLOBALCONF=no
    echo "Creation of a global config file is not supported in wineinstall at this"
    echo "time.  When the configuration architecture is cleaned up this functionality"
    echo "will be restored to wineinstall."
    echo
  fi
}
fi

if [ "$DOLOCALCONF" = 'auto' ]
then {
  # see if the user is root, if so, explicitly ask them if they want a
  # local config file
  if [ `whoami` = 'root' ]
  then
    echo "You are running as root.  Do you want a local config file,"
    echo "file, ~/.wine/config, created?"
    conf_yesno_answer "(yes/no) "
    DOLOCALCONF="$ANSWER"
  else
    # if the user has an existing config file ask them if they want us to
    # overwrite it, otherwise just ask them if they want to create one
    if [ -f "$LCONF" ]
    then
      echo "Found existing $LCONF, do you want to overwrite this"
      echo "existing Wine configuration file?"
      conf_yesno_answer "(yes/no) "
      DOLOCALCONF="$ANSWER"
      echo
    else {
      echo "Create local config file ~/.wine/config?"
      conf_yesno_answer "(yes/no) "
      DOLOCALCONF="$ANSWER"
      echo
      if [ "$ANSWER" = 'no' ]
      then
        conf_question high need_root \
          "Aborting install. Try again as root to generate a system wine.conf."
        exit 1
      fi
    }
    fi
  fi
}
fi

# generate $TMPCONF from existing windows install, if any
if [ "$DOLOCALCONF" = 'yes' ]
then {
  if [ "$DOWCHK" = 'yes' ] || [ "$DOWCHK" = 'auto' ]
  then {
    echo -n "Searching for an existing Windows installation..."
    if ! $WINECONF -inifile "$WINEINI" > $TMPCONF 2>/dev/null
    then {
      rm -f $TMPCONF $TMPREG > /dev/null

      echo " not found. (no matching /etc/fstab mount entry found)"
      conf_question low do_without_windows \
       "Windows was not found on your system, so I assume you want" \
       "a Wine-only installation. Am I correct?"
      conf_yesno_answer "(yes/no) "
      if [ "$ANSWER" = 'no' ]
      then {
        conf_question high windows_not_found \
         "Aborting install. Make sure your Windows partition is mounted and try again," \
         "or create $LCONF manually by copying from $WINEINI and adapting the drive paths."
        exit 1
      }
      fi
      DOWINE=yes
    }
    else {
      echo " found."

      conf_reset_question windows_found
      conf_question low windows_found \
       "Created $LCONF using your existing Windows installation." \
       "You probably want to review the file, though."
      DOWINE=no
    }
    fi
  }
  elif [ "$DOWINE" = 'auto' ]
  then DOWINE=yes
  fi
}
elif [ "$DOWINE" = 'auto' ]
then 
  DOWINE=no
fi

# setup a no-windows installation, if necessary
if [ "$DOWINE" = 'yes' ]
then {
  # set an appropriate DCROOT
  if [ `whoami` != 'root' ]
  then DCROOT=~/c
  else DCROOT=/c
  fi

  if [ -f ~/.winerc ]
  then {
    conf_question medium convert_config \
     "I found the old version Wine config file, .winerc, in your " \
     "home directory.  I can convert this to the new format or use the" \
     "new default Wine config file. Convert?"
    conf_yesno_answer "(yes/no) "
    if [ "$ANSWER" = 'yes' ]
    then {
      WINEINI=~/.winerc
      CONVCONF=yes
    }
    fi
  }
  else {

    conf_question low drivec_path \
     "Configuring Wine without Windows." \
     "Some fake Windows directories must be created, to hold any .ini files, DLLs," \
     "start menu entries, and other things your applications may need to install." \
     "Where would you like your fake C drive to be placed?"
    while [ -z "$CROOT" ]
    do {
      conf_string_answer "(default is $DCROOT) "
      [ -z "$ANSWER" ] && ANSWER="$DCROOT"
      if ! [ -d "$ANSWER" ]
      then {
        if mkdir -p "$ANSWER"
        then CROOT="$ANSWER"
        else
          echo "Directory $ANSWER can't be created !"
          conf_reset_question drivec_path
        fi
      }
      else CROOT="$ANSWER"
      fi
    }
    done
    echo "Configuring Wine for a no-windows install in $CROOT..."
  
    create_windows_directories
  }
  fi

  # create $LCONF using the default config file $WINEINI  
  if [ "$DOLOCALCONF" = 'yes' ] && [ "$CONVCONF" = 'no' ]
  then {
    sed "s|\"Path\" = \"/c\"\$|\"Path\" = \"${CROOT}\"|" $WINEINI > $TMPCONF
    conf_reset_question default_config
    conf_question low default_config \
     "Created $LCONF using default Wine configuration." \
     "You probably want to review the file, though."
  }
  fi

  # now we really should install the registry
  if [ "$DOREG" = 'auto' ]
  then DOREG=yes
  fi
}
fi
echo

#install the local config file $LCONF
if [ "$DOLOCALCONF" = 'yes' ]
then
  if [ ! -w ~/.wine ]
  then
    mkdir ~/.wine
  fi

  if [ "$CONVCONF" = 'no' ]
  then
    cp $TMPCONF $LCONF > /dev/null
  fi
else
  DOREG=no
fi      

#install the global config file $GCONF
if [ "$DOGLOBALCONF" = 'yes' ]
then
  if [ ! -f $sysconfdir ]
  then
    mkdir -p $sysconfdir
  fi

  cp $TMPCONF $GCONF > /dev/null
fi

# check whether we need to install default registry
# (not to be done if windows registry exists)
if [ "$DOREG" = 'auto' ]
then {
  CROOT=`sed -n '/^\[Drive C\]$/,/^\[.*\]$/ s/^\"Path\" = \"\(.*\)\"/\1/p' $LCONF`
  echo "Checking for real Windows registry..."
  if [ -f "$CROOT/windows/system.dat" ]
  then DOREG=no
  elif [ -f "$CROOT/windows/system32/config/system" ]
  then DOREG=no
  elif [ -f "/windows/WINNT/system32/config/system" ]
  then DOREG=no
  else DOREG=yes
  fi
  if [ "$DOREG" = 'yes' ]
  then echo "Not found, default Wine registry will be installed."
  else echo "Windows registry found, will not install default Wine registry."
  fi
  echo
}
fi

# install default registry entries
if [ "$DOREG" = 'yes' ]
then {
  if [ "$BINDIST" = 'no' ]
  then {
    echo "Compiling regapi..."
    (cd programs/regapi; make)
    echo
  }
  fi
  echo "Preparing to install default Wine registry entries..."

  # edit config files so we don't have to run regapi under X
  if [ "$CONVCONF" = 'yes' ]
  then
    mv $WINEINI $WINEINI.new
    sed "s/GraphicsDriver=.*/GraphicsDriver=ttydrv/" $WINEINI.new > $WINEINI
  else
    mv $LCONF $LCONF.new
    sed "s/\"GraphicsDriver\" = .*/\"GraphicsDriver\" = \"ttydrv\"/" $LCONF.new > $LCONF
  fi

  # create a temporary wineinstall.reg with fixed debugger path
  $DEFCAT $DEFREG | sed "s|debugger/winedbg|${DEBUGGER}|" > $TMPREG

  echo "Installing default Wine registry entries..."
  echo
  if ! $REGAPI setValue < $TMPREG > /dev/null
  then {
    rm -f $TMPREG
    echo "Registry install failed."
    conf_reset_question regapi_error
    conf_question high regapi_error
    exit 1
  }
  else {
    # if we are converting from a .winerc file, running regapi once
    # will ONLY convert .winerc -> ~/.wine/config, it will not import the
    # registry data.  so if we are converting we need to run regapi twice
    if [ "$CONVCONF" = 'yes' ]
    then
      if ! $REGAPI setValue < $TMPREG > /dev/null
      then
        rm -f $TMPREG
        echo "Registry install failed."
        conf_reset_question regapi_error
        conf_question high regapi_error
        exit 1
      else
        echo
        echo "Registry entries successfully installed."
      fi
    else
      echo
      echo "Registry entries successfully installed."
    fi
  }
  fi
  rm -f $TMPREG
  if [ "$SYSREG" = 'auto' ]
  then SYSREG=yes
  fi

  # if we converted we need to change the graphics driver back and
  # restore the original .winerc file
  if [ "$CONVCONF" = 'yes' ]
  then
     mv $WINEINI.new $WINEINI
  fi

  sed "s/\"GraphicsDriver\" = .*/\"GraphicsDriver\" = \"x11drv\"/" $LCONF > $LCONF.new
  mv $LCONF.new $LCONF
}
fi

# make root's registry global, if desired
if [ `whoami` = 'root' ] && [ "$DOREG" = 'yes' ] && [ "$SYSREG" = 'yes' ]
then {
  [ -d ~/.wine ] || mkdir ~/.wine
  if ! [ -f $sysconfdir/wine.userreg ]
  then {
    echo "Linking root's user registry hive to the global registry..."
    [ -f ~/.wine/wine.userreg ] && cp ~/.wine/wine.userreg $sysconfdir/wine.userreg
    ln -sf $sysconfdir/wine.userreg ~/.wine/wine.userreg
  }
  fi
  if ! [ -f $sysconfdir/wine.systemreg ]
  then {
    echo "Linking root's system registry hive to the global registry..."
    [ -f ~/.wine/system.reg ] && cp ~/.wine/system.reg $sysconfdir/wine.systemreg
    ln -sf $sysconfdir/wine.systemreg ~/.wine/system.reg
  }
  fi
}
fi

# cleanup any temporary files that may remain
if [ -f $TMPCONF ]
then rm -f $TMPCONF
fi
if [ -f $TMPREG ]
then rm -f $TMPREG
fi


# it's a wrap
echo
echo "Installation complete for now. Good luck (this is still alpha software)."
echo "If you have problems with WINE, please read the documentation first,"
echo "as many kinds of potential problems are explained there."

exit 0


More information about the wine-patches mailing list