2 * Copyright (c) 2001, Jan Nieuwenhuizen.
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 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
13 * Jan Nieuwenhuizen <janneke@gnu.org>
17 /* The purpose of this file is to provide functions for the invocation
18 of install scripts. */
21 static const char *cvsid
=
32 #include "io_stream.h"
35 static const char *cmd
= 0;
36 static OSVERSIONINFO verinfo
;
38 static const char *shells
[] = {
49 for (int i
= 0; shells
[i
]; i
++)
51 sh
= backslash (cygpath (shells
[i
], 0));
52 if (_access (sh
, 0) == 0)
58 char old_path
[_MAX_PATH
];
59 GetEnvironmentVariable ("PATH", old_path
, sizeof (old_path
));
60 SetEnvironmentVariable ("PATH",
61 backslash (cygpath ("/bin;",
62 get_root_dir (), "/usr/bin;",
65 SetEnvironmentVariable ("CYGWINROOT", get_root_dir ());
67 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
68 GetVersionEx (&verinfo
);
70 switch (verinfo
.dwPlatformId
)
72 case VER_PLATFORM_WIN32_NT
:
75 case VER_PLATFORM_WIN32_WINDOWS
:
85 run (const char *sh
, const char *args
, const char *file
)
88 char cmdline
[_MAX_PATH
];
90 PROCESS_INFORMATION pi
;
92 sprintf (cmdline
, "%s %s %s", sh
, args
, file
);
93 memset (&pi
, 0, sizeof (pi
));
94 memset (&si
, 0, sizeof (si
));
96 si
.lpTitle
= (char *) "Cygwin Setup Post-Install Script";
97 si
.dwFlags
= STARTF_USEPOSITION
;
99 b
= CreateProcess (0, cmdline
, 0, 0, 0,
100 CREATE_NEW_CONSOLE
, 0, get_root_dir (), &si
, &pi
);
103 WaitForSingleObject (pi
.hProcess
, INFINITE
);
107 run_script (char const *dir
, char const *fname
)
109 char *ext
= strrchr (fname
, '.');
113 if (sh
&& strcmp (ext
, ".sh") == 0)
115 char *f2
= concat (dir
, fname
, 0);
116 log (0, "running: %s -c %s", sh
, f2
);
120 else if (cmd
&& strcmp (ext
, ".bat") == 0)
122 char *f2
= backslash (cygpath (dir
, fname
, 0));
123 log (0, "running: %s /c %s", cmd
, f2
);
130 /* if file exists then delete it otherwise just ignore no file error */
131 io_stream::remove (concat ("cygfile://", dir
, fname
, ".done", 0));
133 io_stream::move (concat ("cygfile://", dir
, fname
, 0),
134 concat ("cygfile://", dir
, fname
, ".done", 0));
138 try_run_script (char const *dir
, char const *fname
)
140 if (io_stream::exists (concat ("cygfile://", dir
, fname
, ".sh", 0)))
141 run_script (dir
, concat (fname
, ".sh", 0));
142 if (io_stream::exists (concat ("cygfile://", dir
, fname
, ".bat", 0)))
143 run_script (dir
, concat (fname
, ".bat", 0));