secur32: Check for actual return value on invalid QuerySecurityPackageInfo call.
[wine] / tools / wineprefixcreate.in
1 #!/bin/sh
2 #
3 # Script to create the initial WINEPREFIX directory
4 #
5 # Copyright 1999 Ove Kåven
6 # Copyright 2004 Chris Morgan
7 # Copyright 2004 Alexandre Julliard
8 #
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
13 #
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #
23
24 usage()
25 {
26     echo "Usage: $0 [options]"
27     echo ""
28     echo "Options:"
29     echo "  -h, --help                 Display this message"
30     echo "      --prefix <dir>         Directory to create (default: \$WINEPREFIX or ~/.wine)"
31     echo "  -q, --quiet                Don't print status messages"
32     echo "  -w, --wait                 Wait for the wineserver to exit before returning"
33     echo ""
34 }
35
36 set -e
37
38 bindir=""
39 case "$0" in
40   */*)
41     # $0 contains a path, use it
42     bindir=`dirname "$0"`
43     ;;
44   *)
45     # no directory in $0, search in PATH
46     saved_ifs=$IFS
47     IFS=:
48     for d in $PATH
49     do
50       IFS=$saved_ifs
51       if [ -x "$d/$0" ]
52       then
53         bindir="$d"
54         break
55       fi
56     done
57     ;;
58 esac
59
60 bindir=`cd "$bindir" && pwd`
61 dlldir="$bindir/@bintodlldir@"
62 datadir="$bindir/@bintodatadir@"
63
64 do_wait=0
65 quiet=0
66
67 if [ ! -f "$dlldir/ntdll.dll.so" -a \
68      -x "$bindir/../server/wineserver" -a \
69      -f "$bindir/../dlls/ntdll/ntdll.dll.so" ]
70 then
71     # running from the wine source tree
72     topdir=`cd "$bindir/.." && pwd`
73     WINELOADER="$topdir/wine"
74     WINESERVER="$topdir/server/wineserver"
75     if [ -n "$LD_LIBRARY_PATH" ]
76     then
77         LD_LIBRARY_PATH="$topdir/libs/wine:$LD_LIBRARY_PATH"
78     else
79         LD_LIBRARY_PATH="$topdir/libs/wine"
80     fi
81     export LD_LIBRARY_PATH
82
83     # find the source directory
84     link=`readlink "$WINELOADER"`
85     if [ -z "$link" ]
86     then
87         topsrcdir="$topdir"
88     else
89         link=`dirname "$link"`
90         case "$link" in
91             /*) topsrcdir=`cd "$link/.." && pwd` ;;
92              *) topsrcdir=`cd "$topdir/$link/.." && pwd` ;;
93         esac
94     fi
95     dlldir="$topdir/programs"
96     datadir="$topsrcdir/tools"
97 fi
98
99 while [ $# -gt 0 ]
100 do
101     case "$1" in
102         -h|--help)
103             usage
104             exit 0
105             ;;
106         --prefix)
107             WINEPREFIX="$2"
108             shift 2
109             ;;
110         -q|--quiet)
111             quiet=1
112             shift
113             ;;
114         -w|--wait)
115             do_wait=1
116             shift
117             ;;
118         --use-wine-tree)
119             # ignored, autodetected now
120             shift 2
121             ;;
122         *)
123             echo "Unknown option $1"
124             usage
125             exit 1
126             ;;
127   esac
128 done
129
130 WINEPREFIX="${WINEPREFIX:-$HOME/.wine}"
131
132 if [ -d "$WINEPREFIX" ] || mkdir "$WINEPREFIX"; then :
133 else
134     echo "Could not create $WINEPREFIX, aborting"
135     exit 1
136 fi
137
138 WINEPREFIX=`cd "$WINEPREFIX" && pwd`
139
140 # Create the drive symlinks
141
142 if [ ! -d "$WINEPREFIX/dosdevices" ]
143 then
144     mkdir "$WINEPREFIX/dosdevices"
145     [ -d "$WINEPREFIX/drive_c" ] || mkdir "$WINEPREFIX/drive_c"
146     ln -s "../drive_c" "$WINEPREFIX/dosdevices/c:"
147     ln -s "/" "$WINEPREFIX/dosdevices/z:"
148 fi
149
150 CROOT="$WINEPREFIX/dosdevices/c:"
151
152 # Create the directory tree
153
154 for i in \
155     "$CROOT/windows" \
156     "$CROOT/windows/command" \
157     "$CROOT/windows/fonts" \
158     "$CROOT/windows/inf" \
159     "$CROOT/windows/system" \
160     "$CROOT/windows/system32" \
161     "$CROOT/windows/system32/drivers" \
162     "$CROOT/windows/temp"
163 do
164     [ -d "$i" ] || mkdir "$i"
165 done
166
167 # Copy the .inf script and run it
168
169 cp "$datadir/wine.inf" "$CROOT/windows/inf/wine.inf"
170 export WINEPREFIX
171 "${WINELOADER:-$bindir/wine}" rundll32.exe setupapi.dll,InstallHinfSection DefaultInstall 128 wine.inf
172
173 # Wait for the wineserver to finish
174
175 if [ $do_wait = 1 ]
176 then
177     "${WINESERVER:-$bindir/wineserver}" -w
178 fi
179
180 if [ $quiet = 0 ]
181 then
182     echo "$WINEPREFIX updated successfully."
183 fi