]>
cygwin.com Git - cygwin-apps/setup.git/blob - install.cc
2 * Copyright (c) 2000, 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 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* The purpose of this file is to intall all the packages selected in
17 the install list (in ini.h). Note that we use a separate thread to
18 maintain the progress dialog, so we avoid the complexity of
19 handling two tasks in one thread. We also create or update all the
20 files in /etc/setup/* and create the mount points. */
22 static char *cvsid
= "\n%%% $Id$\n";
30 #include <sys/types.h>
33 #include "zlib/zlib.h"
52 static HWND ins_dialog
= 0;
53 static HWND ins_action
= 0;
54 static HWND ins_pkgname
= 0;
55 static HWND ins_filename
= 0;
56 static HWND ins_pprogress
= 0;
57 static HWND ins_iprogress
= 0;
58 static HWND ins_diskfull
= 0;
59 static HANDLE init_event
;
61 static int total_bytes
= 0;
62 static int total_bytes_sofar
= 0;
63 static int package_bytes
= 0;
66 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
76 dialog_proc (HWND h
, UINT message
, WPARAM wParam
, LPARAM lParam
)
84 ins_action
= GetDlgItem (h
, IDC_INS_ACTION
);
85 ins_pkgname
= GetDlgItem (h
, IDC_INS_PKG
);
86 ins_filename
= GetDlgItem (h
, IDC_INS_FILE
);
87 ins_pprogress
= GetDlgItem (h
, IDC_INS_PPROGRESS
);
88 ins_iprogress
= GetDlgItem (h
, IDC_INS_IPROGRESS
);
89 ins_diskfull
= GetDlgItem (h
, IDC_INS_DISKFULL
);
90 SetEvent (init_event
);
93 return HANDLE_WM_COMMAND (h
, wParam
, lParam
, dialog_cmd
);
103 HWND ins_dialog
= CreateDialog (hinstance
, MAKEINTRESOURCE (IDD_INSTATUS
),
106 fatal ("create dialog");
107 ShowWindow (ins_dialog
, SW_SHOWNORMAL
);
108 UpdateWindow (ins_dialog
);
109 while (GetMessage (&m
, 0, 0, 0) > 0) {
110 TranslateMessage (&m
);
111 DispatchMessage (&m
);
115 static DWORD start_tics
;
124 init_event
= CreateEvent (0, 0, 0, 0);
125 thread
= CreateThread (0, 0, dialog
, 0, 0, &tid
);
126 WaitForSingleObject (init_event
, 10000);
127 CloseHandle (init_event
);
128 SendMessage (ins_pprogress
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
129 SendMessage (ins_iprogress
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
130 SendMessage (ins_diskfull
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
133 SetWindowText (ins_pkgname
, "");
134 SetWindowText (ins_filename
, "");
135 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) 0, 0);
136 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) 0, 0);
137 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) 0, 0);
138 ShowWindow (ins_dialog
, SW_SHOWNORMAL
);
139 SetForegroundWindow (ins_dialog
);
147 if (package_bytes
> 100)
149 perc
= bytes
/ (package_bytes
/ 100);
150 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) perc
, 0);
153 if (total_bytes
> 100)
155 perc
= (total_bytes_sofar
+ bytes
) / (total_bytes
/ 100);
156 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) perc
, 0);
161 badrename (char *o
, char *n
)
164 char *err
= strerror (errno
);
166 err
= "(unknown error)";
167 note (IDS_ERR_RENAME
, o
, n
, err
);
170 static char *standard_dirs
[] = {
190 hash::add_subdirs (char *path
)
193 for (nonp
= path
; *nonp
== '\\' || *nonp
== '/'; nonp
++);
194 for (pp
= path
+ strlen(path
) - 1; pp
>nonp
; pp
--)
195 if (*pp
== '/' || *pp
== '\\')
200 for (i
=0; standard_dirs
[i
]; i
++)
201 if (strcmp (standard_dirs
[i
]+1, path
) == 0)
215 if (_access (file
, 0) == 0)
220 static int num_installs
, num_uninstalls
;
223 uninstall_one (char *name
, int action
)
226 char line
[_MAX_PATH
];
228 gzFile lst
= gzopen (cygpath ("/etc/setup/",
233 SetWindowText (ins_pkgname
, name
);
234 SetWindowText (ins_action
, "Uninstalling...");
235 if (action
== ACTION_UPGRADE
|| action
== ACTION_REDO
)
236 log (0, "Uninstalling old %s", name
);
238 log (0, "Uninstalling %s", name
);
240 while (gzgets (lst
, line
, sizeof (line
)))
242 if (line
[strlen(line
)-1] == '\n')
243 line
[strlen(line
)-1] = 0;
245 dirs
.add_subdirs (line
);
247 char *d
= cygpath ("/", line
, NULL
);
248 DWORD dw
= GetFileAttributes (d
);
249 if (dw
!= 0xffffffff && !(dw
& FILE_ATTRIBUTE_DIRECTORY
))
251 log (LOG_BABBLE
, "unlink %s", d
);
257 remove (cygpath ("/etc/setup/", name
, ".lst.gz", 0));
259 dirs
.reverse_sort ();
261 while ((subdir
= dirs
.enumerate (subdir
)) != 0)
263 char *d
= cygpath ("/", subdir
, NULL
);
264 if (RemoveDirectory (d
))
265 log (LOG_BABBLE
, "rmdir %s", d
);
273 install_one (char *name
, char *file
, int file_size
, int action
, BOOL isSrc
)
276 char *local
= file
, *cp
, *fn
, *base
;
279 for (cp
=local
; *cp
; cp
++)
280 if (*cp
== '/' || *cp
== '\\' || *cp
== ':')
282 SetWindowText (ins_pkgname
, base
);
284 if (!exists (local
) && exists (base
))
288 note (IDS_ERR_OPEN_READ
, local
, "No such file");
292 gzFile lst
= gzopen (cygpath ("/etc/setup/",
296 package_bytes
= file_size
;
301 SetWindowText (ins_action
, "Installing...");
304 SetWindowText (ins_action
, "Upgrading...");
307 SetWindowText (ins_action
, "ReInstalling...");
311 log (0, "Installing %s", local
);
313 while (fn
= tar_next_file ())
318 gzprintf (lst
, "%s\n", fn
);
320 dest_file
= cygpath (isSrc
? "/usr/src/" : "/", fn
, NULL
);
322 SetWindowText (ins_filename
, dest_file
);
323 log (LOG_BABBLE
, "Installing file %s", dest_file
);
324 if (tar_read_file (dest_file
) != 0)
326 log (0, "Unable to install file %s", dest_file
);
330 progress (tar_ftell ());
336 total_bytes_sofar
+= file_size
;
339 int df
= diskfull (root_dir
);
340 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) df
, 0);
349 do_install (HINSTANCE h
)
354 num_installs
= 0, num_uninstalls
= 0;
356 next_dialog
= IDD_DESKTOP
;
358 mkdir_p (1, root_dir
);
360 for (i
=0; standard_dirs
[i
]; i
++)
362 char *p
= cygpath (standard_dirs
[i
], 0);
367 /* Create /var/run/utmp */
368 char *utmp
= cygpath ("/var/run/utmp", 0);
369 FILE *ufp
= fopen (utmp
, "wb");
374 dismiss_url_status_dialog ();
379 total_bytes_sofar
= 0;
381 int df
= diskfull (root_dir
);
382 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) df
, 0);
386 if (package
[i
].action
!= ACTION_SRC_ONLY
)
387 total_bytes
+= pi
.install_size
;
388 if (package
[i
].srcaction
== SRCACTION_YES
)
389 total_bytes
+= pi
.source_size
;
392 for (i
=0; i
<npackages
; i
++)
394 if (package
[i
].action
== ACTION_UNINSTALL
395 || ((package
[i
].action
== ACTION_UPGRADE
396 || package
[i
].action
== ACTION_REDO
) && pi
.install
))
398 uninstall_one (package
[i
].name
, package
[i
].action
);
399 uninstall_one (concat (package
[i
].name
, "-src", 0), package
[i
].action
);
402 if ((package
[i
].action
== ACTION_NEW
403 || package
[i
].action
== ACTION_UPGRADE
404 || package
[i
].action
== ACTION_REDO
405 || package
[i
].action
== ACTION_SRC_ONLY
)
409 if (package
[i
].action
!= ACTION_SRC_ONLY
)
410 e
+= install_one (package
[i
].name
, pi
.install
, pi
.install_size
, package
[i
].action
, FALSE
);
411 if (package
[i
].srcaction
== SRCACTION_YES
&& pi
.source
)
412 e
+= install_one (concat (package
[i
].name
, "-src", 0), pi
.source
, pi
.source_size
,
413 package
[i
].action
, TRUE
);
416 package
[i
].action
= ACTION_ERROR
;
420 } // end of big package loop
422 ShowWindow (ins_dialog
, SW_HIDE
);
424 char *odbn
= cygpath ("/etc/setup/installed.db", 0);
425 char *ndbn
= cygpath ("/etc/setup/installed.db.new", 0);
426 char *sdbn
= cygpath ("/etc/setup/installed.db.old", 0);
430 FILE *odb
= fopen (odbn
, "rt");
431 FILE *ndb
= fopen (ndbn
, "wb");
435 char *err
= strerror (errno
);
437 err
= "(unknown error)";
438 fatal (IDS_ERR_OPEN_WRITE
, ndb
, err
);
443 char line
[1000], pkg
[1000];
445 while (fgets (line
, 1000, odb
))
448 sscanf (line
, "%s", pkg
);
449 for (i
=0; i
<npackages
; i
++)
451 if (strcmp (pkg
, package
[i
].name
) == 0)
452 switch (package
[i
].action
)
456 case ACTION_UNINSTALL
:
458 case ACTION_SRC_ONLY
:
471 if (package
[i
].srcaction
== SRCACTION_YES
)
472 fprintf (ndb
, "%s %s %d %s %d\n", package
[i
].name
,
473 pi
.install
, pi
.install_size
,
474 pi
.source
, pi
.source_size
);
476 fprintf (ndb
, "%s %s %d\n", package
[i
].name
,
477 pi
.install
, pi
.install_size
);
485 if (odb
&& rename (odbn
, sdbn
))
486 badrename (odbn
, sdbn
);
489 if (rename (ndbn
, odbn
))
490 badrename (ndbn
, odbn
);
492 if (num_installs
== 0 && num_uninstalls
== 0)
494 exit_msg
= IDS_NOTHING_INSTALLED
;
497 if (num_installs
== 0)
499 exit_msg
= IDS_UNINSTALL_COMPLETE
;
504 remove_mount ("/usr");
505 remove_mount ("/usr/bin");
506 remove_mount ("/usr/lib");
507 remove_mount ("/var");
508 remove_mount ("/lib");
509 remove_mount ("/bin");
510 remove_mount ("/etc");
512 int istext
= (root_text
== IDC_ROOT_TEXT
) ? 1 : 0;
513 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
515 create_mount ("/", root_dir
, istext
, issystem
);
516 create_mount ("/usr/bin", cygpath ("/bin", 0), istext
, issystem
);
517 create_mount ("/usr/lib", cygpath ("/lib", 0), istext
, issystem
);
518 set_cygdrive_flags (istext
, issystem
);
521 exit_msg
= IDS_INSTALL_INCOMPLETE
;
523 exit_msg
= IDS_INSTALL_COMPLETE
;
This page took 0.0618 seconds and 6 git commands to generate.