Merge branch 'vendor/OPENSSL'
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / installer / fn_install.c
1 /*
2  * Copyright (c)2004 The DragonFly Project.  All rights reserved.
3  * 
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 
8  *   Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * 
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
14  *   distribution.
15  * 
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. 
19  * 
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. 
32  */
33
34 /*
35  * fn_install.c
36  * Installer Function : Install OS Files.
37  * $Id: fn_install.c,v 1.74 2006/04/18 19:43:48 joerg Exp $
38  */
39
40 #include <libgen.h>
41 #include <string.h>
42
43 #define SOURCES_CONF_FILE "/usr/local/share/dfuibe_installer/sources.conf"
44
45 #ifdef ENABLE_NLS
46 #include <libintl.h>
47 #define _(String) gettext (String)
48 #else
49 #define _(String) (String)
50 #endif
51
52 #include "libaura/mem.h"
53 #include "libaura/buffer.h"
54 #include "libaura/fspred.h"
55
56 #include "libdfui/dfui.h"
57 #include "libdfui/system.h"
58
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"
64
65 #include "flow.h"
66 #include "pathnames.h"
67 #include "fn.h"
68
69 static const char *pfs_mountpt[5] = {"/var", "/tmp", "/usr", "/home", NULL};
70
71 /*
72  * fn_install_os: actually put DragonFly on a disk.
73  */
74 void
75 fn_install_os(struct i_fn_args *a)
76 {
77         struct subpartition *sp;
78         struct commands *cmds;
79         struct command *cmd;
80         int i, seen_it, prefix, j;
81         FILE *sources_conf;
82         char line[256];
83         char cp_src[64][256];
84         char file_path[256];
85         int lines = 0;
86         long mfsbacked_size;
87
88         /* 
89          * If SOURCES_CONF_FILE exists, lets read in and 
90          * populate our copy sources.   If it does not exist
91          * simply set the list by hand.
92          */
93         if (!is_file("%s%s", a->os_root, SOURCES_CONF_FILE)) {
94                 i_log(a, "Using internal copy sources table.");
95                 strcpy(cp_src[0],"/COPYRIGHT");
96                 strcpy(cp_src[1],"/var");
97                 strcpy(cp_src[2],"/bin");
98                 strcpy(cp_src[3],"/boot");
99                 strcpy(cp_src[4],"/cdrom");
100                 strcpy(cp_src[5],"/dev");
101                 strcpy(cp_src[6],"/etc");
102                 strcpy(cp_src[7],"/libexec");
103                 strcpy(cp_src[8],"/lib");
104                 strcpy(cp_src[9],"/kernel");
105                 strcpy(cp_src[10],"/modules");
106                 strcpy(cp_src[11],"/root");
107                 strcpy(cp_src[12],"/sbin");
108                 strcpy(cp_src[13],"/sys");
109                 strcpy(cp_src[14],"/tmp");
110                 strcpy(cp_src[15],"/usr/bin");
111                 strcpy(cp_src[16],"/usr/games");
112                 strcpy(cp_src[17],"/usr/include");
113                 strcpy(cp_src[18],"/usr/lib");
114                 strcpy(cp_src[19],"/usr/local");
115                 strcpy(cp_src[20],"/usr/local/OpenOffice.org1.1.3");
116                 strcpy(cp_src[21],"/usr/X11R6");
117                 strcpy(cp_src[22],"/usr/libdata");
118                 strcpy(cp_src[23],"/usr/libexec");
119                 strcpy(cp_src[24],"/usr/obj");
120                 strcpy(cp_src[25],"/usr/sbin");
121                 strcpy(cp_src[26],"/usr/share");
122                 strcpy(cp_src[27],"/usr/src");
123                 strcpy(cp_src[28],"");
124         } else {
125                 snprintf(file_path, 256, "%s%s", a->os_root, SOURCES_CONF_FILE);
126                 sources_conf = fopen(file_path, "r");
127                 i_log(a, "Reading %s%s", a->os_root, SOURCES_CONF_FILE);
128                 while(fgets(line, 256, sources_conf) != NULL && lines < 63) {
129                         if(strlen(line)>0)
130                                 line[strlen(line)-1] = '\0';
131                         strlcpy(cp_src[lines], line, 256);
132                         i_log(a,"Adding %s to copy source table.", cp_src[lines]);
133                         lines++;
134                 }
135                 i_log(a,"Added %i total items to copy source table.", lines);
136                 strcpy(cp_src[lines], "");
137                 fclose(sources_conf);
138         }
139
140         cmds = commands_new();
141
142         /*
143          * If swap isn't mounted yet, mount it.
144          */
145         if (measure_activated_swap(a) == 0) {
146                 for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
147                     sp != NULL; sp = subpartition_next(sp)) {
148                         if (!subpartition_is_swap(sp))
149                                 continue;
150                         command_add(cmds, "%s%s %sdev/%s",
151                             a->os_root,
152                             cmd_name(a, "SWAPON"),
153                             a->os_root,
154                             subpartition_get_device_name(sp));
155                 }
156         }
157
158         /*
159          * Unmount anything already mounted on /mnt.
160          */
161         unmount_all_under(a, cmds, "%smnt", a->os_root);
162
163         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
164              sp != NULL; sp = subpartition_next(sp)) {
165                 if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
166                         command_add(cmds, "%s%s -p %smnt%s",
167                             a->os_root, cmd_name(a, "MKDIR"),
168                             a->os_root, subpartition_get_mountpoint(sp));
169                         if (use_hammer == 1) {
170                                 command_add(cmds, "%s%s %sdev/%s %smnt%s",
171                                     a->os_root, cmd_name(a, "MOUNT_HAMMER"),
172                                     a->os_root,
173                                     subpartition_get_device_name(sp),
174                                     a->os_root,
175                                     subpartition_get_mountpoint(sp));
176                         } else {
177                                 command_add(cmds, "%s%s %sdev/%s %smnt%s",
178                                     a->os_root, cmd_name(a, "MOUNT"),
179                                     a->os_root,
180                                     subpartition_get_device_name(sp),
181                                     a->os_root,
182                                     subpartition_get_mountpoint(sp));
183                         }
184                 }
185         }
186
187         /*
188          * Create mount points and mount subpartitions on them.
189          */
190         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
191              sp != NULL; sp = subpartition_next(sp)) {
192                 if (subpartition_is_swap(sp)) {
193                         /*
194                          * Set this subpartition as the dump device.
195                          */
196 #ifdef AUTOMATICALLY_ENABLE_CRASH_DUMPS
197                         if (subpartition_get_capacity(sp) < storage_get_memsize(a->s))
198                                 continue;
199
200                         command_add(cmds, "%s%s -v %sdev/%s",
201                             a->os_root, cmd_name(a, "DUMPON"),
202                             a->os_root,
203                             subpartition_get_device_name(sp));
204
205                         asprintf(&string, "/dev/%s",
206                             subpartition_get_device_name(sp));
207                         config_var_set(rc_conf, "dumpdev", string);
208                         free(string);
209                         config_var_set(rc_conf, "dumpdir", "/var/crash");
210 #endif
211                         continue;
212                 }
213         
214
215                 /*
216                  * Don't mount it if it's MFS-backed.
217                  */
218
219                 if (subpartition_is_mfsbacked(sp)) {
220                         continue;
221                 }
222                 if (use_hammer == 0) {
223                         /* / is already mounted */
224                         if (strcmp(subpartition_get_mountpoint(sp), "/") != 0) {
225                                 command_add(cmds, "%s%s -p %smnt%s",
226                                     a->os_root, cmd_name(a, "MKDIR"),
227                                     a->os_root,
228                                     subpartition_get_mountpoint(sp));
229                                 command_add(cmds, "%s%s %sdev/%s %smnt%s",
230                                     a->os_root, cmd_name(a, "MOUNT"),
231                                     a->os_root,
232                                     subpartition_get_device_name(sp),
233                                     a->os_root,
234                                     subpartition_get_mountpoint(sp));
235                         }
236                 }
237         }
238
239         if (use_hammer == 1) {
240                 /* Create PFS dir */
241                 command_add(cmds, "%s%s -p %smnt/pfs",
242                     a->os_root, cmd_name(a, "MKDIR"),
243                     a->os_root);
244
245                 /* mount null pfs */
246                 for (j = 0; pfs_mountpt[j] != NULL; j++) {
247                         command_add(cmds, "%s%s pfs-master %smnt/pfs%s",
248                             a->os_root, cmd_name(a, "HAMMER"),
249                             a->os_root, pfs_mountpt[j]);
250                         command_add(cmds, "%s%s -p %smnt%s",
251                             a->os_root, cmd_name(a, "MKDIR"),
252                             a->os_root, pfs_mountpt[j]);
253                         command_add(cmds, "%s%s %smnt/pfs%s %smnt%s",
254                             a->os_root, cmd_name(a, "MOUNT_NULL"),
255                             a->os_root, pfs_mountpt[j],
256                             a->os_root, pfs_mountpt[j]);
257                 }
258         }
259
260         /*
261          * Actually copy files now.
262          */
263
264         for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
265                 char *src, *dest, *dn, *tmp_dest;
266
267                 dest = cp_src[i];
268
269                 /*
270                  * If dest would be on an MFS-backed
271                  * mountpoint, don't bother copying it.
272                  */
273                 sp = subpartition_of(storage_get_selected_slice(a->s),
274                                      "%s%s", a->os_root, &dest[1]);
275                 if (sp != NULL && subpartition_is_mfsbacked(sp)) {
276                         continue;
277                 }
278
279                 /*
280                  * Create intermediate directories, if needed.
281                  */
282                 tmp_dest = aura_strdup(dest);
283                 dn = dirname(tmp_dest);
284                 if (is_dir("%s%s", a->os_root, &dn[1]) &&
285                     !is_dir("%smnt%s", a->os_root, dn)) {
286                         command_add(cmds, "%s%s -p %smnt%s",
287                             a->os_root, cmd_name(a, "MKDIR"),
288                             a->os_root, dn);
289                 }
290                 aura_free(tmp_dest, "directory name");
291
292                 /*
293                  * If a directory by the same name but with the suffix
294                  * ".hdd" exists on the installation media, cpdup that
295                  * instead.  This is particularly useful with /etc, which
296                  * may have significantly different behaviour on the
297                  * live CD compared to a standard HDD boot.
298                  */
299                 if (is_dir("%s%s.hdd", a->os_root, &dest[1]))
300                         asprintf(&src, "%s.hdd", &dest[1]);
301                 else
302                         asprintf(&src, "%s", &dest[1]);
303
304                 if (is_dir("%s%s", a->os_root, src) || is_file("%s%s", a->os_root, src)) {
305                         /*
306                          * Cpdup the chosen file or directory onto the HDD.
307                          * if it exists on the source.
308                          */
309                         cmd = command_add(cmds, "%s%s %s%s %smnt%s",
310                             a->os_root, cmd_name(a, "CPDUP"),
311                             a->os_root, src,
312                             a->os_root, dest);
313                         command_set_log_mode(cmd, COMMAND_LOG_QUIET);
314                 }
315         }
316
317         /*
318          * Now, because cpdup does not cross mount points,
319          * we must copy anything that the user might've made a
320          * seperate mount point for (e.g. /usr/libdata/lint.)
321          */
322         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
323              sp != NULL; sp = subpartition_next(sp)) {
324                 /*
325                  * If the subpartition is a swap subpartition or an
326                  * MFS-backed mountpoint, don't try to copy anything
327                  * into it.
328                  */
329                 if (subpartition_is_swap(sp) || subpartition_is_mfsbacked(sp))
330                         continue;
331
332                 /*
333                  * If the mountpoint doesn't even exist on the installation
334                  * medium, don't try to copy anything from it!  We assume
335                  * it's an empty subpartition for the user's needs.
336                  */
337                 if (!is_dir("%s%s", a->os_root, &subpartition_get_mountpoint(sp)[1]))
338                         continue;
339
340                 /*
341                  * Don't bother copying the mountpoint IF:
342                  * - we've already said to copy it, or something besides it
343                  *   (it's a prefix of something in cp_src); or
344                  * - we haven't said to copy it
345                  *   (nothing in cp_src is a prefix of it.)
346                  */
347                 seen_it = 0;
348                 prefix = 0;
349                 for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
350                         if (strncmp(subpartition_get_mountpoint(sp), cp_src[i],
351                             strlen(subpartition_get_mountpoint(sp))) == 0) {
352                                 seen_it = 1;
353                                 break;
354                         }
355                         if (strncmp(cp_src[i], subpartition_get_mountpoint(sp),
356                             strlen(cp_src[i])) == 0) {
357                                 prefix = 1;
358                         }
359                 }
360                 if (seen_it || !prefix)
361                         continue;
362
363                 /*
364                  * Otherwise, cpdup the subpartition.
365                  *
366                  * XXX check for .hdd-extended source dirs here, too,
367                  * eventually - but for now, /etc.hdd will never be
368                  * the kind of tricky sub-mount-within-a-mount-point
369                  * that this part of the code is meant to handle.
370                  */
371                 cmd = command_add(cmds, "%s%s %s%s %smnt%s",
372                     a->os_root, cmd_name(a, "CPDUP"),
373                     a->os_root, &subpartition_get_mountpoint(sp)[1],
374                     a->os_root, subpartition_get_mountpoint(sp));
375                 command_set_log_mode(cmd, COMMAND_LOG_QUIET);
376         }
377         
378         /*
379          * Create symlinks.
380          */
381
382         /*
383          * If the user has both /var and /tmp subparitions,
384          * symlink /var/tmp to /tmp.
385          */
386         if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") != NULL &&
387             subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) {
388                 command_add(cmds, "%s%s 1777 %smnt/tmp",
389                     a->os_root, cmd_name(a, "CHMOD"), a->os_root);
390                 command_add(cmds, "%s%s -rf %smnt/var/tmp",
391                     a->os_root, cmd_name(a, "RM"), a->os_root);
392                 command_add(cmds, "%s%s -s /tmp %smnt/var/tmp",
393                     a->os_root, cmd_name(a, "LN"), a->os_root);
394         }
395
396         /*
397          * If the user has /var, but no /tmp,
398          * symlink /tmp to /var/tmp.
399          */
400         if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") == NULL &&
401             subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) {
402                 command_add(cmds, "%s%s -rf %smnt/tmp",
403                     a->os_root, cmd_name(a, "RM"), a->os_root);
404                 command_add(cmds, "%s%s -s /var/tmp %smnt/tmp",
405                     a->os_root, cmd_name(a, "LN"), a->os_root);
406         }
407
408         /*
409          * If the user has /usr, but no /home,
410          * symlink /home to /usr/home.
411          */
412         if (subpartition_find(storage_get_selected_slice(a->s), "/home") == NULL &&
413             subpartition_find(storage_get_selected_slice(a->s), "/usr") != NULL) {
414                 command_add(cmds, "%s%s -rf %smnt/home",
415                     a->os_root, cmd_name(a, "RM"), a->os_root);
416                 command_add(cmds, "%s%s %smnt/usr/home",
417                     a->os_root, cmd_name(a, "MKDIR"), a->os_root);
418                 command_add(cmds, "%s%s -s /usr/home %smnt/home",
419                     a->os_root, cmd_name(a, "LN"), a->os_root);
420         }
421
422         /*
423          * XXX check for other possible combinations too?
424          */
425
426         /*
427          * Clean up.  In case some file didn't make it, use rm -f
428          */
429 #ifdef __DragonFly__
430         command_add(cmds, "%s%s -f %smnt/boot/loader.conf",
431             a->os_root, cmd_name(a, "RM"), a->os_root);
432 #endif
433         command_add(cmds, "%s%s -f %smnt/tmp/install.log",
434             a->os_root, cmd_name(a, "RM"), a->os_root);
435
436         /*
437          * Copy pristine versions over any files we might have installed.
438          * This allows the resulting file tree to be customized.
439          */
440         for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
441                 char *src, *dest, *dn, *tmp_dest;
442
443                 src = cp_src[i];
444                 dest = cp_src[i];
445
446                 /*
447                  * Get the directory that the desired thing to
448                  * copy resides in.
449                  */
450                 tmp_dest = aura_strdup(dest);
451                 dn = dirname(tmp_dest);
452
453                 /*
454                  * If this dir doesn't exist in PRISTINE_DIR
455                  * on the install media, just skip it.
456                  */
457                 if (!is_dir("%s%s%s", a->os_root, PRISTINE_DIR, dn)) {
458                         aura_free(tmp_dest, _("directory name"));
459                         continue;
460                 }
461
462                 /*
463                  * Create intermediate directories, if needed.
464                  */
465                 if (!is_dir("%smnt%s", a->os_root, dn)) {
466                         command_add(cmds, "%s%s -p %smnt%s",
467                             a->os_root, cmd_name(a, "MKDIR"),
468                             a->os_root, dn);
469                 }
470                 aura_free(tmp_dest, "directory name");
471
472                 /*
473                  * Cpdup the chosen file or directory onto the HDD.
474                  */
475                 cmd = command_add(cmds, "%s%s %s%s %smnt%s",
476                     a->os_root, cmd_name(a, "CPDUP"),
477                     a->os_root, src,
478                     a->os_root, dest);
479
480                 cmd = command_add(cmds,
481                     "%s%s %s%s%s %smnt%s",
482                     a->os_root, cmd_name(a, "CPDUP"),
483                     a->os_root, PRISTINE_DIR, src,
484                     a->os_root, dest);
485                 command_set_log_mode(cmd, COMMAND_LOG_QUIET);
486         }
487
488         /*
489          * Rebuild the user database, to get rid of any extra users
490          * from the LiveCD that aren't supposed to be installed
491          * (copying a pristine master.passwd isn't enough.)
492          */
493         command_add(cmds, "%s%s -p -d %smnt/etc %smnt/etc/master.passwd",
494             a->os_root, cmd_name(a, "PWD_MKDB"), a->os_root, a->os_root);
495
496         /* Create missing directories. */
497         command_add(cmds, "%s%s %smnt/proc",
498             a->os_root, cmd_name(a, "MKDIR"), a->os_root);
499         command_add(cmds, "%s%s %smnt/mnt",
500             a->os_root, cmd_name(a, "MKDIR"), a->os_root);
501
502         /* Write new fstab. */
503
504         command_add(cmds, "%s%s '%s' >%smnt/etc/fstab",
505             a->os_root, cmd_name(a, "ECHO"),
506             "# Device\t\tMountpoint\tFStype\tOptions\t\tDump\tPass#",
507             a->os_root);
508
509         for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
510              sp != NULL; sp = subpartition_next(sp)) {
511                 if (strcmp(subpartition_get_mountpoint(sp), "swap") == 0) {
512                         command_add(cmds, "%s%s '/dev/%s\t\tnone\t\tswap\tsw\t\t0\t0' >>%smnt/etc/fstab",
513                             a->os_root, cmd_name(a, "ECHO"),
514                             subpartition_get_device_name(sp),
515                             a->os_root);
516                 } else if (use_hammer == 0) {
517                         if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
518                                 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab",
519                                     a->os_root, cmd_name(a, "ECHO"),
520                                     subpartition_get_device_name(sp),
521                                     subpartition_get_mountpoint(sp),
522                                     a->os_root);
523                         } else if (subpartition_is_mfsbacked(sp)) {
524                                 mfsbacked_size = slice_get_capacity(storage_get_selected_slice(a->s)) * 2048;
525                                 command_add(cmds, "%s%s 'swap\t\t%s\t\t\tmfs\trw,-s%ld\t\t1\t1' >>%smnt/etc/fstab",
526                                         a->os_root, cmd_name(a, "ECHO"),
527                                         subpartition_get_mountpoint(sp),
528                                         mfsbacked_size,
529                                         a->os_root);
530                         } else {
531                                 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t2\t2' >>%smnt/etc/fstab",
532                                     a->os_root, cmd_name(a, "ECHO"),
533                                     subpartition_get_device_name(sp),
534                                     subpartition_get_mountpoint(sp),
535                                     a->os_root);
536                         }
537                 } else {
538                         if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
539                                 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\thammer\trw\t\t1\t1' >>%smnt/etc/fstab",
540                                     a->os_root, cmd_name(a, "ECHO"),
541                                     subpartition_get_device_name(sp),
542                                     subpartition_get_mountpoint(sp),
543                                     a->os_root);
544                         } else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
545                                 command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab",
546                                     a->os_root, cmd_name(a, "ECHO"),
547                                     subpartition_get_device_name(sp),
548                                     subpartition_get_mountpoint(sp),
549                                     a->os_root);
550                         }
551                 }
552         }
553         if (use_hammer == 1) {
554                 for (j = 0; pfs_mountpt[j] != NULL; j++) {
555                         command_add(cmds, "%s%s '/pfs%s\t\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab",
556                             a->os_root, cmd_name(a, "ECHO"),
557                             pfs_mountpt[j],
558                             pfs_mountpt[j],
559                             a->os_root);
560                 }
561         }
562
563         command_add(cmds, "%s%s '%s' >>%smnt/etc/fstab",
564             a->os_root, cmd_name(a, "ECHO"),
565             "proc\t\t\t/proc\t\tprocfs\trw\t\t0\t0",
566             a->os_root);
567
568         /* Backup the disklabel and the log. */
569         if (use_hammer == 0) {
570                 command_add(cmds, "%s%s %s > %smnt/etc/disklabel.%s",
571                     a->os_root, cmd_name(a, "DISKLABEL"),
572                     slice_get_device_name(storage_get_selected_slice(a->s)),
573                     a->os_root,
574                     slice_get_device_name(storage_get_selected_slice(a->s)));
575         } else {
576                 command_add(cmds, "%s%s %s > %smnt/etc/disklabel.%s",
577                     a->os_root, cmd_name(a, "DISKLABEL64"),
578                     slice_get_device_name(storage_get_selected_slice(a->s)),
579                     a->os_root,
580                     slice_get_device_name(storage_get_selected_slice(a->s)));
581         }
582
583         command_add(cmds, "%s%s %sinstall.log %smnt/var/log/install.log",
584             a->os_root, cmd_name(a, "CP"),
585             a->tmp, a->os_root);
586         command_add(cmds, "%s%s 600 %smnt/var/log/install.log",
587             a->os_root, cmd_name(a, "CHMOD"), a->os_root);
588
589         /* Customize stuff here */
590         if(is_file("%susr/local/bin/after_installation_routines.sh")) {
591                 command_add(cmds, "%susr/local/bin/after_installation_routines.sh",
592                 a->os_root, _("Running after installation custom routines..."));
593         }
594
595         /*
596          * Do it!
597          */
598         /* commands_preview(cmds); */
599         if (!commands_execute(a, cmds)) {
600                 inform(a->c, _("%s was not fully installed."), OPERATING_SYSTEM_NAME);
601                 a->result = 0;
602         } else {
603                 a->result = 1;
604         }
605         commands_free(cmds);
606
607         /*
608          * Unmount everything we mounted on /mnt.  This is done in a seperate
609          * command chain, so that partitions are unmounted, even if an error
610          * occurs in one of the preceding commands, or it is cancelled.
611          */
612         cmds = commands_new();
613         unmount_all_under(a, cmds, "%smnt", a->os_root);
614
615         /*
616          * Once everything is unmounted, if the install went successfully,
617          * make sure once and for all that the disklabel is bootable.
618          */
619         if (a->result) {
620                 if (use_hammer == 0) {
621                         command_add(cmds, "%s%s -B %s",
622                             a->os_root, cmd_name(a, "DISKLABEL"),
623                             slice_get_device_name(storage_get_selected_slice(a->s)));
624                 } else {
625                         command_add(cmds, "%s%s -B %s",
626                             a->os_root, cmd_name(a, "DISKLABEL64"),
627                             slice_get_device_name(storage_get_selected_slice(a->s)));
628                 }
629         }
630
631         if (!commands_execute(a, cmds))
632                 inform(a->c, _("Warning: subpartitions were not correctly unmounted."));
633
634         commands_free(cmds);
635 }
636