2 # Copyright (C) 2009 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #----------------------------------------------------------------------
21 # This is a QEMU wrapper script that allows you to run a
22 # Windows-compiled guestfsd.exe (daemon) under Wine from a Linux main
23 # program. You need to read and understand all the instructions below
26 # To understand how to compile the daemon for Windows, please read:
27 # http://www.redhat.com/archives/libguestfs/2009-November/msg00255.html
29 # Adjust the Wine configuration so it can find the libraries, as
31 # http://fedoraproject.org/wiki/MinGW/Configure_wine
33 # On Fedora 13 there is a serious bug in Wine. See:
34 # https://bugzilla.redhat.com/show_bug.cgi?id=533806#c11
36 # If necessary, adjust the line 'guestfsd=...' below so it points to
37 # the correct location of the guestfsd.exe program. You can use an
38 # absolute path here if you want.
39 guestfsd=daemon/guestfsd.exe
41 # This script is a QEMU wrapper. It pretends to be qemu as far as
42 # libguestfs programs are concerned. Read this to understand the
43 # purpose of QEMU wrappers:
44 # http://libguestfs.org/guestfs.3.html#qemu_wrappers
46 # With this script, the qemu program is not actually run. Instead we
47 # pretend to be qemu, parse out the necessary parts of the long
48 # command line that libguestfs passes to qemu, and run the Windows
49 # daemon, under Wine, with the right command line. The Windows daemon
50 # then hopefully connects back to the libguestfs socket, and as far as
51 # the libguestfs program is concerned, it looks like a full appliance
54 # To use this script, you must set the environment variable
55 # LIBGUESTFS_QEMU=/path/to/contrib/guestfsd-in-wine.sh (ie. the path
58 # You can then run libguestfs test programs, and (hopefully!) they'll
59 # use the Windows guestfsd.exe, simulating calls using Wine.
61 # For example from the top build directory:
63 # LIBGUESTFS_QEMU=contrib/guestfsd-in-wine.sh fish/guestfish
65 # You might also need to set the environment variable LIBGUESTFS_PATH
66 # to point to an appliance. The appliance will never be used, but
67 # libguestfs needs to find one.
69 # Another suggested environment variable is LIBGUESTFS_DEBUG=1 which
70 # will give you must more detail about what is going on. Also look at
71 # the contents of the log file 'guestfsd-in-wine.log' after each run.
73 #----------------------------------------------------------------------
75 # Note that stdout & stderr messages will get eaten by libguestfs
76 # early on in the process. Therefore write log messages to
78 exec 5>>guestfsd-in-wine.log
79 echo "Environment:" >&5
80 printenv | grep LIBGUESTFS >&5
81 echo "Command line:" >&5
84 # We're called several times, first with -help and -version, and we
85 # have to pretend to be qemu! (At least enough to trick libguestfs).
86 if [ "$1" = "-help" ]; then
89 echo -- " -rtc-td-hack "
91 elif [ "$1" = "-version" ]; then
96 # The interesting parameter is -append.
98 while [ $# -gt 0 ]; do
99 if [ $1 = "-append" ]; then
105 echo "Append parameter:" >&5
108 # guestfs_vmchannel parameter.
109 vmchannel_param=$(echo "$append" | grep -Eo 'guestfs_vmchannel=[^[:space:]]+')
110 echo "Vmchannel parameter:" >&5
111 echo " $vmchannel_param" >&5
114 port=$(echo "$vmchannel_param" | grep -Eo '[[:digit:]]+$')
115 echo "Port number:" >&5
116 echo " $vmchannel_param" >&5
120 echo " $guestfsd -f -v -c tcp:localhost:$port" >&5
121 $guestfsd -f -v -c tcp:127.0.0.1:$port