]>
Commit | Line | Data |
---|---|---|
904d24fe DD |
1 | /* |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
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 manage all the desktop setup, such | |
17 | as start menu, batch files, desktop icons, and shortcuts. Note | |
18 | that unlike other do_* functions, this one is called directly from | |
19 | install.cc */ | |
20 | ||
8507f105 DD |
21 | static char *cvsid = "\n%%% $Id$\n"; |
22 | ||
904d24fe | 23 | #include "win32.h" |
ad09bcd9 | 24 | #include <shlobj.h> |
904d24fe DD |
25 | |
26 | #include <stdio.h> | |
27 | #include <stdlib.h> | |
28 | #include <unistd.h> | |
29 | ||
30 | #include "resource.h" | |
31 | #include "msg.h" | |
32 | #include "state.h" | |
33 | #include "concat.h" | |
34 | #include "mkdir.h" | |
35 | #include "dialog.h" | |
36 | ||
37 | #include "port.h" | |
38 | ||
39 | extern "C" { | |
40 | void make_link_2 (char *exepath, char *args, char *icon, char *lname); | |
41 | }; | |
42 | ||
3a8e3956 DD |
43 | static OSVERSIONINFO verinfo; |
44 | ||
45 | /* Lines starting with '@' are conditionals - include 'N' for NT, | |
46 | '5' for Win95, '8' for Win98, '*' for all, like this: | |
47 | echo foo | |
48 | @N8 | |
49 | echo NT or 98 | |
50 | @* | |
51 | */ | |
52 | ||
53 | static char *etc_profile[] = { | |
a6100861 | 54 | "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"", |
e0c3d906 DD |
55 | "unset DOSDRIVE", |
56 | "unset DOSDIR", | |
57 | "unset TMPDIR", | |
58 | "unset TMP", | |
59 | "", | |
e0c3d906 DD |
60 | "USER=`id -un`", |
61 | "", | |
62 | "# Set up USER's home directory", | |
63 | "if [ -z \"$HOME\" ]; then", | |
64 | " HOME=/home/$USER", | |
65 | "fi", | |
66 | "", | |
67 | "if [ ! -d $HOME ]; then", | |
68 | " mkdir -p $HOME", | |
69 | "fi", | |
70 | "", | |
71 | "export HOME USER", | |
72 | "", | |
73 | "for i in /etc/profile.d/*.sh ; do", | |
74 | " if [ -f $i ]; then", | |
75 | " . $i", | |
76 | " fi", | |
77 | "done", | |
78 | "", | |
bf1d5889 | 79 | "export MAKE_MODE=unix", |
e0c3d906 DD |
80 | "export PS1='\033]0;\\w\a", |
81 | "\033[32m\\u@\\h \033[33m\\w\033[0m", | |
82 | "$ '", | |
83 | "", | |
84 | "cd $HOME", | |
e92c4436 DD |
85 | "", |
86 | "test -f ./.profile && . ./.profile", | |
87 | "test -f ./.bashrc && . ./.bashrc", | |
e0c3d906 DD |
88 | 0 |
89 | }; | |
90 | ||
84d58d4c | 91 | #define COMMAND9XARGS "/E:4096 /c" |
904d24fe DD |
92 | #define COMMAND9XEXE "\\command.com" |
93 | ||
94 | static char *batname; | |
95 | static char *iconname; | |
96 | ||
904d24fe DD |
97 | static void |
98 | make_link (char *linkpath, char *title, char *target) | |
99 | { | |
84d58d4c | 100 | char argbuf[_MAX_PATH]; |
904d24fe DD |
101 | char *fname = concat (linkpath, "/", title, ".lnk", 0); |
102 | ||
103 | if (_access (fname, 0) == 0) | |
104 | return; /* already exists */ | |
105 | ||
106 | msg ("make_link %s, %s, %s\n", fname, title, target); | |
107 | ||
108 | mkdir_p (0, fname); | |
109 | ||
84d58d4c | 110 | char *exepath, *args; |
904d24fe DD |
111 | |
112 | /* If we are running Win9x, build a command line. */ | |
904d24fe DD |
113 | if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) |
114 | { | |
904d24fe DD |
115 | exepath = target; |
116 | args = ""; | |
117 | } | |
118 | else | |
119 | { | |
120 | char *pccmd; | |
121 | char windir[MAX_PATH]; | |
122 | ||
123 | GetWindowsDirectory (windir, sizeof (windir)); | |
904d24fe | 124 | exepath = concat (windir, COMMAND9XEXE, 0); |
84d58d4c DD |
125 | sprintf (argbuf, "%s %s", COMMAND9XARGS, target); |
126 | args = argbuf; | |
904d24fe DD |
127 | } |
128 | ||
84d58d4c | 129 | msg ("make_link_2 (%s, %s, %s, %s)", exepath, args, iconname, fname); |
904d24fe DD |
130 | make_link_2 (exepath, args, iconname, fname); |
131 | } | |
132 | ||
133 | static void | |
134 | start_menu (char *title, char *target) | |
135 | { | |
136 | char path[_MAX_PATH]; | |
137 | LPITEMIDLIST id; | |
24e259bb DD |
138 | int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0; |
139 | SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id); | |
904d24fe DD |
140 | SHGetPathFromIDList (id, path); |
141 | strcat (path, "/Cygnus Solutions"); | |
142 | make_link (path, title, target); | |
143 | } | |
144 | ||
145 | static void | |
146 | desktop_icon (char *title, char *target) | |
147 | { | |
148 | char path[_MAX_PATH]; | |
149 | LPITEMIDLIST id; | |
24e259bb DD |
150 | int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0; |
151 | SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id); | |
904d24fe DD |
152 | SHGetPathFromIDList (id, path); |
153 | make_link (path, title, target); | |
154 | } | |
155 | ||
156 | static void | |
157 | make_cygwin_bat () | |
158 | { | |
84d58d4c | 159 | batname = backslash (concat (root_dir, "/cygwin.bat", 0)); |
904d24fe DD |
160 | |
161 | /* if the batch file exists, don't overwrite it */ | |
162 | if (_access (batname, 0) == 0) | |
163 | return; | |
164 | ||
165 | FILE *bat = fopen (batname, "wt"); | |
166 | if (!bat) | |
167 | return; | |
168 | ||
169 | fprintf (bat, "@echo off\n\n"); | |
170 | ||
904d24fe | 171 | fprintf (bat, "%.2s\n", root_dir); |
bf1d5889 | 172 | fprintf (bat, "chdir %s\n\n", backslash (concat (root_dir+2, "/bin", 0))); |
904d24fe DD |
173 | |
174 | fprintf (bat, "bash --login -i\n"); | |
175 | ||
176 | fclose (bat); | |
904d24fe DD |
177 | } |
178 | ||
e0c3d906 DD |
179 | static void |
180 | make_etc_profile () | |
181 | { | |
182 | char *fname = concat (root_dir, "/etc/profile", 0); | |
183 | ||
184 | /* if the file exists, don't overwrite it */ | |
185 | if (_access (fname, 0) == 0) | |
186 | return; | |
187 | ||
3a8e3956 DD |
188 | char os; |
189 | switch (verinfo.dwPlatformId) | |
190 | { | |
191 | case VER_PLATFORM_WIN32_NT: | |
192 | os = 'N'; | |
193 | break; | |
194 | case VER_PLATFORM_WIN32_WINDOWS: | |
195 | if (verinfo.dwMinorVersion == 0) | |
196 | os = '5'; | |
197 | else | |
198 | os = '8'; | |
199 | break; | |
200 | default: | |
201 | os = '?'; | |
202 | break; | |
203 | } | |
204 | msg ("os is %c", os); | |
205 | ||
e0c3d906 DD |
206 | FILE *p = fopen (fname, "wb"); |
207 | if (!p) | |
208 | return; | |
209 | ||
3a8e3956 | 210 | int i, allow=1; |
e0c3d906 | 211 | for (i=0; etc_profile[i]; i++) |
3a8e3956 DD |
212 | { |
213 | if (etc_profile[i][0] == '@') | |
214 | { | |
215 | allow = 0; | |
216 | msg ("profile: %s", etc_profile[i]); | |
217 | for (char *cp = etc_profile[i]+1; *cp; cp++) | |
218 | if (*cp == os || *cp == '*') | |
219 | allow = 1; | |
220 | msg ("allow is %d\n", allow); | |
221 | } | |
222 | else if (allow) | |
223 | fprintf (p, "%s\n", etc_profile[i]); | |
224 | } | |
225 | ||
226 | fclose (p); | |
227 | } | |
228 | ||
f57c332f DD |
229 | static int |
230 | uexists (char *path) | |
231 | { | |
232 | char *f = concat (root_dir, path, 0); | |
233 | int a = _access (f, 0); | |
234 | free (f); | |
235 | if (a == 0) | |
236 | return 1; | |
237 | return 0; | |
238 | } | |
239 | ||
3a8e3956 | 240 | static void |
f57c332f | 241 | make_passwd_group () |
3a8e3956 DD |
242 | { |
243 | if (verinfo.dwPlatformId != VER_PLATFORM_WIN32_NT) | |
244 | return; | |
245 | ||
f57c332f DD |
246 | if (uexists ("/etc/passwd") && uexists ("/etc/group")) |
247 | return; | |
248 | ||
249 | char *fname = concat (root_dir, "/etc/postinstall/passwd-grp.bat", 0); | |
3a8e3956 DD |
250 | mkdir_p (0, fname); |
251 | ||
252 | FILE *p = fopen (fname, "wb"); | |
253 | if (!p) | |
254 | return; | |
255 | ||
f57c332f DD |
256 | if (!uexists ("/etc/passwd")) |
257 | fprintf (p, "bin\\mkpasswd -l > etc\\passwd\n"); | |
258 | if (!uexists ("/etc/group")) | |
259 | fprintf (p, "bin\\mkgroup -l > etc\\group\n"); | |
e0c3d906 DD |
260 | |
261 | fclose (p); | |
262 | } | |
263 | ||
904d24fe DD |
264 | static void |
265 | save_icon () | |
266 | { | |
84d58d4c | 267 | iconname = backslash (concat (root_dir, "/cygwin.ico", 0)); |
904d24fe DD |
268 | |
269 | HRSRC rsrc = FindResource (NULL, "CYGWIN.ICON", "FILE"); | |
270 | if (rsrc == NULL) | |
271 | { | |
272 | fatal ("FindResource failed"); | |
273 | } | |
274 | HGLOBAL res = LoadResource (NULL, rsrc); | |
275 | char *data = (char *) LockResource (res); | |
276 | int len = SizeofResource (NULL, rsrc); | |
277 | ||
278 | FILE *f = fopen (iconname, "wb"); | |
279 | if (f) | |
280 | { | |
281 | fwrite (data, 1, len, f); | |
282 | fclose (f); | |
283 | } | |
284 | } | |
285 | ||
286 | void | |
287 | do_desktop (HINSTANCE h) | |
288 | { | |
f57c332f DD |
289 | next_dialog = IDD_S_POSTINSTALL; |
290 | ||
904d24fe DD |
291 | CoInitialize (NULL); |
292 | ||
3a8e3956 DD |
293 | verinfo.dwOSVersionInfoSize = sizeof (verinfo); |
294 | GetVersionEx (&verinfo); | |
295 | ||
904d24fe DD |
296 | save_icon (); |
297 | ||
298 | make_cygwin_bat (); | |
e0c3d906 | 299 | make_etc_profile (); |
f57c332f | 300 | make_passwd_group (); |
904d24fe DD |
301 | |
302 | start_menu ("Cygwin 1.1 Bash Shell", batname); | |
303 | ||
304 | desktop_icon ("Cygwin", batname); | |
305 | } |