2 * Copyright (c)2004 The DragonFly Project. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * Neither the name of the DragonFly Project nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Installer Function : Install OS Files.
37 * $Id: fn_install.c,v 1.74 2006/04/18 19:43:48 joerg Exp $
43 #define SOURCES_CONF_FILE "/usr/local/share/dfuibe_installer/sources.conf"
47 #define _(String) gettext (String)
49 #define _(String) (String)
52 #include "libaura/mem.h"
53 #include "libaura/buffer.h"
54 #include "libaura/fspred.h"
56 #include "libdfui/dfui.h"
57 #include "libdfui/system.h"
59 #include "libinstaller/commands.h"
60 #include "libinstaller/confed.h"
61 #include "libinstaller/diskutil.h"
62 #include "libinstaller/functions.h"
63 #include "libinstaller/uiutil.h"
66 #include "pathnames.h"
69 static const char *pfs_mountpt[8] = {"/var", "/tmp", "/usr", "/home",
70 "/usr/obj", "/var/crash", "/var/tmp", NULL};
72 static const int pfs_nohistory[8] = {0, 0, 0, 0, 1, 1, 1};
75 handle_pfs(struct i_fn_args *a, struct commands *cmds)
80 * Create PFS root directory.
82 command_add(cmds, "%s%s -p %smnt/pfs",
83 a->os_root, cmd_name(a, "MKDIR"),
86 for (j = 0; pfs_mountpt[j] != NULL; j++) {
88 * We have a PFS for a subdirectory, e.g. /var/crash, so we
89 * need to create /pfs/var.crash
91 if (rindex(pfs_mountpt[j]+1, '/') != NULL) {
92 command_add(cmds, "%s%s pfs-master %smnt/pfs%s.%s",
93 a->os_root, cmd_name(a, "HAMMER"),
94 a->os_root, dirname(pfs_mountpt[j]),
95 basename(pfs_mountpt[j]));
96 command_add(cmds, "%s%s -p %smnt%s",
97 a->os_root, cmd_name(a, "MKDIR"),
98 a->os_root, pfs_mountpt[j]);
99 command_add(cmds, "%s%s %smnt/pfs%s.%s %smnt%s",
100 a->os_root, cmd_name(a, "MOUNT_NULL"),
101 a->os_root, dirname(pfs_mountpt[j]),
102 basename(pfs_mountpt[j]),
103 a->os_root, pfs_mountpt[j]);
104 if (pfs_nohistory[j] == 1)
105 command_add(cmds, "%s%s nohistory %smnt%s",
106 a->os_root, cmd_name(a, "CHFLAGS"),
107 a->os_root, pfs_mountpt[j]);
110 command_add(cmds, "%s%s pfs-master %smnt/pfs%s",
111 a->os_root, cmd_name(a, "HAMMER"),
112 a->os_root, pfs_mountpt[j]);
113 command_add(cmds, "%s%s -p %smnt%s",
114 a->os_root, cmd_name(a, "MKDIR"),
115 a->os_root, pfs_mountpt[j]);
116 command_add(cmds, "%s%s %smnt/pfs%s %smnt%s",
117 a->os_root, cmd_name(a, "MOUNT_NULL"),
118 a->os_root, pfs_mountpt[j],
119 a->os_root, pfs_mountpt[j]);
125 * fn_install_os: actually put DragonFly on a disk.
128 fn_install_os(struct i_fn_args *a)
130 struct subpartition *sp;
131 struct commands *cmds;
133 int i, seen_it, prefix, j;
136 char cp_src[64][256];
142 * If SOURCES_CONF_FILE exists, lets read in and
143 * populate our copy sources. If it does not exist
144 * simply set the list by hand.
146 if (!is_file("%s%s", a->os_root, SOURCES_CONF_FILE)) {
147 i_log(a, "Using internal copy sources table.");
148 strcpy(cp_src[0],"/COPYRIGHT");
149 strcpy(cp_src[1],"/var");
150 strcpy(cp_src[2],"/bin");
151 strcpy(cp_src[3],"/boot");
152 strcpy(cp_src[4],"/cdrom");
153 strcpy(cp_src[5],"/dev");
154 strcpy(cp_src[6],"/etc");
155 strcpy(cp_src[7],"/libexec");
156 strcpy(cp_src[8],"/lib");
157 strcpy(cp_src[9],"/kernel");
158 strcpy(cp_src[10],"/modules");
159 strcpy(cp_src[11],"/root");
160 strcpy(cp_src[12],"/sbin");
161 strcpy(cp_src[13],"/sys");
162 strcpy(cp_src[14],"/tmp");
163 strcpy(cp_src[15],"/usr/bin");
164 strcpy(cp_src[16],"/usr/games");
165 strcpy(cp_src[17],"/usr/include");
166 strcpy(cp_src[18],"/usr/lib");
167 strcpy(cp_src[19],"/usr/local");
168 strcpy(cp_src[20],"/usr/local/OpenOffice.org1.1.3");
169 strcpy(cp_src[21],"/usr/X11R6");
170 strcpy(cp_src[22],"/usr/libdata");
171 strcpy(cp_src[23],"/usr/libexec");
172 strcpy(cp_src[24],"/usr/obj");
173 strcpy(cp_src[25],"/usr/sbin");
174 strcpy(cp_src[26],"/usr/share");
175 strcpy(cp_src[27],"/usr/src");
176 strcpy(cp_src[28],"");
178 snprintf(file_path, 256, "%s%s", a->os_root, SOURCES_CONF_FILE);
179 sources_conf = fopen(file_path, "r");
180 i_log(a, "Reading %s%s", a->os_root, SOURCES_CONF_FILE);
181 while(fgets(line, 256, sources_conf) != NULL && lines < 63) {
183 line[strlen(line)-1] = '\0';
184 strlcpy(cp_src[lines], line, 256);
185 i_log(a,"Adding %s to copy source table.", cp_src[lines]);
188 i_log(a,"Added %i total items to copy source table.", lines);
189 strcpy(cp_src[lines], "");
190 fclose(sources_conf);
193 cmds = commands_new();
196 * If swap isn't mounted yet, mount it.
198 if (measure_activated_swap(a) == 0) {
199 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
200 sp != NULL; sp = subpartition_next(sp)) {
201 if (!subpartition_is_swap(sp))
203 command_add(cmds, "%s%s %sdev/%s",
205 cmd_name(a, "SWAPON"),
207 subpartition_get_device_name(sp));
212 * Unmount anything already mounted on /mnt.
214 unmount_all_under(a, cmds, "%smnt", a->os_root);
216 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
217 sp != NULL; sp = subpartition_next(sp)) {
218 if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
219 command_add(cmds, "%s%s -p %smnt%s",
220 a->os_root, cmd_name(a, "MKDIR"),
221 a->os_root, subpartition_get_mountpoint(sp));
222 if (use_hammer == 1) {
223 command_add(cmds, "%s%s %sdev/%s %smnt%s",
224 a->os_root, cmd_name(a, "MOUNT_HAMMER"),
226 subpartition_get_device_name(sp),
228 subpartition_get_mountpoint(sp));
230 command_add(cmds, "%s%s %sdev/%s %smnt%s",
231 a->os_root, cmd_name(a, "MOUNT"),
233 subpartition_get_device_name(sp),
235 subpartition_get_mountpoint(sp));
241 * Create mount points and mount subpartitions on them.
243 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
244 sp != NULL; sp = subpartition_next(sp)) {
245 if (subpartition_is_swap(sp)) {
247 * Set this subpartition as the dump device.
249 #ifdef AUTOMATICALLY_ENABLE_CRASH_DUMPS
250 if (subpartition_get_capacity(sp) < storage_get_memsize(a->s))
253 command_add(cmds, "%s%s -v %sdev/%s",
254 a->os_root, cmd_name(a, "DUMPON"),
256 subpartition_get_device_name(sp));
258 asprintf(&string, "/dev/%s",
259 subpartition_get_device_name(sp));
260 config_var_set(rc_conf, "dumpdev", string);
262 config_var_set(rc_conf, "dumpdir", "/var/crash");
269 * Don't mount it if it's MFS-backed.
272 if (subpartition_is_mfsbacked(sp)) {
275 if (use_hammer == 0) {
276 /* / is already mounted */
277 if (strcmp(subpartition_get_mountpoint(sp), "/") != 0) {
278 command_add(cmds, "%s%s -p %smnt%s",
279 a->os_root, cmd_name(a, "MKDIR"),
281 subpartition_get_mountpoint(sp));
282 command_add(cmds, "%s%s %sdev/%s %smnt%s",
283 a->os_root, cmd_name(a, "MOUNT"),
285 subpartition_get_device_name(sp),
287 subpartition_get_mountpoint(sp));
293 * Take care of HAMMER PFS.
299 * Actually copy files now.
302 for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
303 char *src, *dest, *dn, *tmp_dest;
308 * If dest would be on an MFS-backed
309 * mountpoint, don't bother copying it.
311 sp = subpartition_of(storage_get_selected_slice(a->s),
312 "%s%s", a->os_root, &dest[1]);
313 if (sp != NULL && subpartition_is_mfsbacked(sp)) {
318 * Create intermediate directories, if needed.
320 tmp_dest = aura_strdup(dest);
321 dn = dirname(tmp_dest);
322 if (is_dir("%s%s", a->os_root, &dn[1]) &&
323 !is_dir("%smnt%s", a->os_root, dn)) {
324 command_add(cmds, "%s%s -p %smnt%s",
325 a->os_root, cmd_name(a, "MKDIR"),
328 aura_free(tmp_dest, "directory name");
331 * If a directory by the same name but with the suffix
332 * ".hdd" exists on the installation media, cpdup that
333 * instead. This is particularly useful with /etc, which
334 * may have significantly different behaviour on the
335 * live CD compared to a standard HDD boot.
337 if (is_dir("%s%s.hdd", a->os_root, &dest[1]))
338 asprintf(&src, "%s.hdd", &dest[1]);
340 asprintf(&src, "%s", &dest[1]);
342 if (is_dir("%s%s", a->os_root, src) || is_file("%s%s", a->os_root, src)) {
344 * Cpdup the chosen file or directory onto the HDD.
345 * if it exists on the source.
347 cmd = command_add(cmds, "%s%s %s%s %smnt%s",
348 a->os_root, cmd_name(a, "CPDUP"),
351 command_set_log_mode(cmd, COMMAND_LOG_QUIET);
356 * Now, because cpdup does not cross mount points,
357 * we must copy anything that the user might've made a
358 * seperate mount point for (e.g. /usr/libdata/lint.)
360 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
361 sp != NULL; sp = subpartition_next(sp)) {
363 * If the subpartition is a swap subpartition or an
364 * MFS-backed mountpoint, don't try to copy anything
367 if (subpartition_is_swap(sp) || subpartition_is_mfsbacked(sp))
371 * If the mountpoint doesn't even exist on the installation
372 * medium, don't try to copy anything from it! We assume
373 * it's an empty subpartition for the user's needs.
375 if (!is_dir("%s%s", a->os_root, &subpartition_get_mountpoint(sp)[1]))
379 * Don't bother copying the mountpoint IF:
380 * - we've already said to copy it, or something besides it
381 * (it's a prefix of something in cp_src); or
382 * - we haven't said to copy it
383 * (nothing in cp_src is a prefix of it.)
387 for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
388 if (strncmp(subpartition_get_mountpoint(sp), cp_src[i],
389 strlen(subpartition_get_mountpoint(sp))) == 0) {
393 if (strncmp(cp_src[i], subpartition_get_mountpoint(sp),
394 strlen(cp_src[i])) == 0) {
398 if (seen_it || !prefix)
402 * Otherwise, cpdup the subpartition.
404 * XXX check for .hdd-extended source dirs here, too,
405 * eventually - but for now, /etc.hdd will never be
406 * the kind of tricky sub-mount-within-a-mount-point
407 * that this part of the code is meant to handle.
409 cmd = command_add(cmds, "%s%s %s%s %smnt%s",
410 a->os_root, cmd_name(a, "CPDUP"),
411 a->os_root, &subpartition_get_mountpoint(sp)[1],
412 a->os_root, subpartition_get_mountpoint(sp));
413 command_set_log_mode(cmd, COMMAND_LOG_QUIET);
421 * If the user has both /var and /tmp subparitions,
422 * symlink /var/tmp to /tmp.
424 if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") != NULL &&
425 subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) {
426 command_add(cmds, "%s%s 1777 %smnt/tmp",
427 a->os_root, cmd_name(a, "CHMOD"), a->os_root);
428 command_add(cmds, "%s%s -rf %smnt/var/tmp",
429 a->os_root, cmd_name(a, "RM"), a->os_root);
430 command_add(cmds, "%s%s -s /tmp %smnt/var/tmp",
431 a->os_root, cmd_name(a, "LN"), a->os_root);
435 * If the user has /var, but no /tmp,
436 * symlink /tmp to /var/tmp.
438 if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") == NULL &&
439 subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) {
440 command_add(cmds, "%s%s -rf %smnt/tmp",
441 a->os_root, cmd_name(a, "RM"), a->os_root);
442 command_add(cmds, "%s%s -s /var/tmp %smnt/tmp",
443 a->os_root, cmd_name(a, "LN"), a->os_root);
447 * If the user has /usr, but no /home,
448 * symlink /home to /usr/home.
450 if (subpartition_find(storage_get_selected_slice(a->s), "/home") == NULL &&
451 subpartition_find(storage_get_selected_slice(a->s), "/usr") != NULL) {
452 command_add(cmds, "%s%s -rf %smnt/home",
453 a->os_root, cmd_name(a, "RM"), a->os_root);
454 command_add(cmds, "%s%s %smnt/usr/home",
455 a->os_root, cmd_name(a, "MKDIR"), a->os_root);
456 command_add(cmds, "%s%s -s /usr/home %smnt/home",
457 a->os_root, cmd_name(a, "LN"), a->os_root);
461 * XXX check for other possible combinations too?
465 * Clean up. In case some file didn't make it, use rm -f
468 command_add(cmds, "%s%s -f %smnt/boot/loader.conf",
469 a->os_root, cmd_name(a, "RM"), a->os_root);
471 command_add(cmds, "%s%s -f %smnt/tmp/install.log",
472 a->os_root, cmd_name(a, "RM"), a->os_root);
475 * Copy pristine versions over any files we might have installed.
476 * This allows the resulting file tree to be customized.
478 for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
479 char *src, *dest, *dn, *tmp_dest;
485 * Get the directory that the desired thing to
488 tmp_dest = aura_strdup(dest);
489 dn = dirname(tmp_dest);
492 * If this dir doesn't exist in PRISTINE_DIR
493 * on the install media, just skip it.
495 if (!is_dir("%s%s%s", a->os_root, PRISTINE_DIR, dn)) {
496 aura_free(tmp_dest, _("directory name"));
501 * Create intermediate directories, if needed.
503 if (!is_dir("%smnt%s", a->os_root, dn)) {
504 command_add(cmds, "%s%s -p %smnt%s",
505 a->os_root, cmd_name(a, "MKDIR"),
508 aura_free(tmp_dest, "directory name");
511 * Cpdup the chosen file or directory onto the HDD.
513 cmd = command_add(cmds, "%s%s %s%s %smnt%s",
514 a->os_root, cmd_name(a, "CPDUP"),
518 cmd = command_add(cmds,
519 "%s%s %s%s%s %smnt%s",
520 a->os_root, cmd_name(a, "CPDUP"),
521 a->os_root, PRISTINE_DIR, src,
523 command_set_log_mode(cmd, COMMAND_LOG_QUIET);
527 * Rebuild the user database, to get rid of any extra users
528 * from the LiveCD that aren't supposed to be installed
529 * (copying a pristine master.passwd isn't enough.)
531 command_add(cmds, "%s%s -p -d %smnt/etc %smnt/etc/master.passwd",
532 a->os_root, cmd_name(a, "PWD_MKDB"), a->os_root, a->os_root);
534 /* Create missing directories. */
535 command_add(cmds, "%s%s %smnt/proc",
536 a->os_root, cmd_name(a, "MKDIR"), a->os_root);
537 command_add(cmds, "%s%s %smnt/mnt",
538 a->os_root, cmd_name(a, "MKDIR"), a->os_root);
540 /* Write new fstab. */
542 command_add(cmds, "%s%s '%s' >%smnt/etc/fstab",
543 a->os_root, cmd_name(a, "ECHO"),
544 "# Device\t\tMountpoint\tFStype\tOptions\t\tDump\tPass#",
547 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
548 sp != NULL; sp = subpartition_next(sp)) {
549 if (strcmp(subpartition_get_mountpoint(sp), "swap") == 0) {
550 command_add(cmds, "%s%s '/dev/%s\t\tnone\t\tswap\tsw\t\t0\t0' >>%smnt/etc/fstab",
551 a->os_root, cmd_name(a, "ECHO"),
552 subpartition_get_device_name(sp),
554 } else if (use_hammer == 0) {
555 if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
556 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab",
557 a->os_root, cmd_name(a, "ECHO"),
558 subpartition_get_device_name(sp),
559 subpartition_get_mountpoint(sp),
561 } else if (subpartition_is_mfsbacked(sp)) {
562 mfsbacked_size = slice_get_capacity(storage_get_selected_slice(a->s)) * 2048;
563 command_add(cmds, "%s%s 'swap\t\t%s\t\t\tmfs\trw,-s%ld\t\t1\t1' >>%smnt/etc/fstab",
564 a->os_root, cmd_name(a, "ECHO"),
565 subpartition_get_mountpoint(sp),
569 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t2\t2' >>%smnt/etc/fstab",
570 a->os_root, cmd_name(a, "ECHO"),
571 subpartition_get_device_name(sp),
572 subpartition_get_mountpoint(sp),
576 if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
577 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\thammer\trw\t\t1\t1' >>%smnt/etc/fstab",
578 a->os_root, cmd_name(a, "ECHO"),
579 subpartition_get_device_name(sp),
580 subpartition_get_mountpoint(sp),
582 } else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
583 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab",
584 a->os_root, cmd_name(a, "ECHO"),
585 subpartition_get_device_name(sp),
586 subpartition_get_mountpoint(sp),
593 * Take care of HAMMER PFS null mounts.
595 if (use_hammer == 1) {
596 for (j = 0; pfs_mountpt[j] != NULL; j++) {
597 if (rindex(pfs_mountpt[j]+1, '/') != NULL)
598 command_add(cmds, "%s%s '/pfs%s.%s\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab",
599 a->os_root, cmd_name(a, "ECHO"),
600 dirname(pfs_mountpt[j]),
601 basename(pfs_mountpt[j]),
605 command_add(cmds, "%s%s '/pfs%s\t\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab",
606 a->os_root, cmd_name(a, "ECHO"),
613 command_add(cmds, "%s%s '%s' >>%smnt/etc/fstab",
614 a->os_root, cmd_name(a, "ECHO"),
615 "proc\t\t\t/proc\t\tprocfs\trw\t\t0\t0",
618 /* Backup the disklabel and the log. */
619 if (use_hammer == 0) {
620 command_add(cmds, "%s%s %s > %smnt/etc/disklabel.%s",
621 a->os_root, cmd_name(a, "DISKLABEL"),
622 slice_get_device_name(storage_get_selected_slice(a->s)),
624 slice_get_device_name(storage_get_selected_slice(a->s)));
626 command_add(cmds, "%s%s %s > %smnt/etc/disklabel.%s",
627 a->os_root, cmd_name(a, "DISKLABEL64"),
628 slice_get_device_name(storage_get_selected_slice(a->s)),
630 slice_get_device_name(storage_get_selected_slice(a->s)));
633 command_add(cmds, "%s%s %sinstall.log %smnt/var/log/install.log",
634 a->os_root, cmd_name(a, "CP"),
636 command_add(cmds, "%s%s 600 %smnt/var/log/install.log",
637 a->os_root, cmd_name(a, "CHMOD"), a->os_root);
639 /* Customize stuff here */
640 if(is_file("%susr/local/bin/after_installation_routines.sh")) {
641 command_add(cmds, "%susr/local/bin/after_installation_routines.sh",
642 a->os_root, _("Running after installation custom routines..."));
648 /* commands_preview(cmds); */
649 if (!commands_execute(a, cmds)) {
650 inform(a->c, _("%s was not fully installed."), OPERATING_SYSTEM_NAME);
658 * Unmount everything we mounted on /mnt. This is done in a seperate
659 * command chain, so that partitions are unmounted, even if an error
660 * occurs in one of the preceding commands, or it is cancelled.
662 cmds = commands_new();
663 unmount_all_under(a, cmds, "%smnt", a->os_root);
666 * Once everything is unmounted, if the install went successfully,
667 * make sure once and for all that the disklabel is bootable.
670 if (use_hammer == 0) {
671 command_add(cmds, "%s%s -B %s",
672 a->os_root, cmd_name(a, "DISKLABEL"),
673 slice_get_device_name(storage_get_selected_slice(a->s)));
675 command_add(cmds, "%s%s -B %s",
676 a->os_root, cmd_name(a, "DISKLABEL64"),
677 slice_get_device_name(storage_get_selected_slice(a->s)));
681 if (!commands_execute(a, cmds))
682 inform(a->c, _("Warning: subpartitions were not correctly unmounted."));