]>
Commit | Line | Data |
---|---|---|
f57c332f | 1 | /* |
31324d15 | 2 | * Copyright (c) 2000, 2001 Red Hat, Inc. |
f57c332f DD |
3 | * |
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. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by DJ Delorie <dj@cygnus.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | /* The purpose of this file is to run all the post-install scripts | |
17 | in their various forms. */ | |
18 | ||
b24c88b3 RC |
19 | #if 0 |
20 | static const char *cvsid = | |
21 | "\n%%% $Id$\n"; | |
22 | #endif | |
8507f105 | 23 | |
f57c332f DD |
24 | #include "win32.h" |
25 | ||
26 | #include <stdlib.h> | |
27 | #include <unistd.h> | |
28 | ||
29 | #include "state.h" | |
30 | #include "dialog.h" | |
31 | #include "find.h" | |
32 | #include "concat.h" | |
a351e48c | 33 | #include "mount.h" |
f57c332f DD |
34 | |
35 | #include "port.h" | |
36 | ||
37 | static char *sh = 0; | |
b24c88b3 | 38 | static const char *cmd = 0; |
f57c332f DD |
39 | static OSVERSIONINFO verinfo; |
40 | ||
41 | static void | |
b24c88b3 | 42 | run (const char *sh, const char *args, const char *file) |
f57c332f DD |
43 | { |
44 | BOOL b; | |
b24c88b3 | 45 | char cmdline[_MAX_PATH]; |
f57c332f DD |
46 | STARTUPINFO si; |
47 | PROCESS_INFORMATION pi; | |
48 | ||
49 | sprintf (cmdline, "%s %s %s", sh, args, file); | |
50 | memset (&pi, 0, sizeof (pi)); | |
51 | memset (&si, 0, sizeof (si)); | |
52 | si.cb = sizeof (si); | |
b24c88b3 | 53 | si.lpTitle = (char *) "Cygwin Setup Post-Install Script"; |
f57c332f DD |
54 | si.dwFlags = STARTF_USEPOSITION; |
55 | ||
56 | b = CreateProcess (0, cmdline, 0, 0, 0, | |
85b43844 | 57 | CREATE_NEW_CONSOLE, 0, get_root_dir (), &si, &pi); |
f57c332f DD |
58 | |
59 | if (b) | |
60 | WaitForSingleObject (pi.hProcess, INFINITE); | |
61 | } | |
62 | ||
63 | static void | |
64 | each (char *fname, unsigned int size) | |
65 | { | |
66 | char *ext = strrchr (fname, '.'); | |
67 | if (!ext) | |
68 | return; | |
bf74c544 | 69 | |
f57c332f DD |
70 | if (sh && strcmp (ext, ".sh") == 0) |
71 | { | |
72 | char *f2 = concat ("/etc/postinstall/", fname, 0); | |
73 | run (sh, "-c", f2); | |
74 | free (f2); | |
75 | } | |
bf74c544 | 76 | else if (cmd && strcmp (ext, ".bat") == 0) |
f57c332f | 77 | { |
a351e48c | 78 | char *f2 = backslash (cygpath ("/etc/postinstall/", fname, 0)); |
f57c332f DD |
79 | run (cmd, "/c", f2); |
80 | free (f2); | |
81 | } | |
bf74c544 DD |
82 | else |
83 | return; | |
84 | ||
31324d15 CF |
85 | /* if file exists then delete it otherwise just ignore no file error */ |
86 | remove (cygpath ("/etc/postinstall/", fname, ".done", 0)); | |
87 | ||
a351e48c CF |
88 | rename (cygpath ("/etc/postinstall/", fname, 0), |
89 | cygpath ("/etc/postinstall/", fname, ".done", 0)); | |
f57c332f DD |
90 | } |
91 | ||
b24c88b3 | 92 | static const char *shells[] = { |
f57c332f DD |
93 | "/bin/sh.exe", |
94 | "/usr/bin/sh.exe", | |
95 | "/bin/bash.exe", | |
96 | "/usr/bin/bash.exe", | |
97 | 0 | |
98 | }; | |
99 | ||
100 | void | |
101 | do_postinstall (HINSTANCE h) | |
102 | { | |
103 | next_dialog = 0; | |
104 | int i; | |
b24c88b3 | 105 | for (i = 0; shells[i]; i++) |
f57c332f | 106 | { |
a351e48c | 107 | sh = backslash (cygpath (shells[i], 0)); |
f57c332f DD |
108 | if (_access (sh, 0) == 0) |
109 | break; | |
110 | free (sh); | |
111 | sh = 0; | |
112 | } | |
113 | ||
114 | char old_path[_MAX_PATH]; | |
115 | GetEnvironmentVariable ("PATH", old_path, sizeof (old_path)); | |
116 | SetEnvironmentVariable ("PATH", | |
a351e48c | 117 | backslash (cygpath ("/bin;", |
b24c88b3 RC |
118 | get_root_dir (), "/usr/bin;", |
119 | old_path, 0))); | |
f57c332f | 120 | |
85b43844 CF |
121 | SetEnvironmentVariable ("CYGWINROOT", get_root_dir ()); |
122 | SetCurrentDirectory (get_root_dir ()); | |
f57c332f DD |
123 | |
124 | verinfo.dwOSVersionInfoSize = sizeof (verinfo); | |
125 | GetVersionEx (&verinfo); | |
126 | ||
127 | switch (verinfo.dwPlatformId) | |
128 | { | |
129 | case VER_PLATFORM_WIN32_NT: | |
130 | cmd = "cmd.exe"; | |
131 | break; | |
132 | case VER_PLATFORM_WIN32_WINDOWS: | |
133 | cmd = "command.com"; | |
134 | break; | |
135 | default: | |
136 | cmd = "command.com"; | |
137 | break; | |
138 | } | |
139 | ||
a351e48c | 140 | find (cygpath ("/etc/postinstall", 0), each); |
f57c332f | 141 | } |