81ddcc1060b00804b282244315dd45dec4789359
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / lua / install / 500_install_os.lua
1 -- $Id: 500_install_os.lua,v 1.39 2005/04/05 07:37:20 cpressey Exp $
2
3 require "gettext"
4 require "target_system"
5
6 return {
7     name = "install_os",
8     title = "Install OS",
9     action = function(fsm)
10         local spd, cmds
11
12         --
13         -- Final confirmation.
14         --
15         if App.ui:present({
16             id = "ready_to_install",
17             name = _("Ready to Install"),
18             short_desc = _(
19                 "Everything is now ready to install the actual files which "    ..
20                 "comprise the %s operating system "                             ..
21                 "on the selected partition of the selected disk.\n\n"           ..
22                 "Note that this process will take quite a while to finish. "    ..
23                 "You may wish to take a break now and come back to the "        ..
24                 "computer in a short while.", App.os.name),
25             actions = {
26                 {
27                     id = "ok",
28                     name = _("Begin Installing Files")
29                 },
30                 {
31                     id = "cancel",
32                     name = _("Return to %s", fsm:prev().title)
33                 }
34             }
35         }).action_id ~= "ok" then
36                 return fsm:prev()
37         end
38
39         --
40         -- If there is a target system mounted, unmount it before starting.
41         --
42         if App.state.target ~= nil and App.state.target:is_mounted() then
43                 if not App.state.target:unmount() then
44                         App.ui:inform(
45                             _("Warning: already-mounted target system could " ..
46                               "not be correctly unmounted first."))
47                         return fsm:current()
48                 end
49         end
50
51         --
52         -- Create a command chain.
53         --
54         cmds = CmdChain.new()
55
56         --
57         -- Activate swap, if there is none activated so far.
58         --
59         if App.state.storage:get_activated_swap() == 0 then
60                 for spd in App.state.sel_part:get_subparts() do
61                         if spd:get_fstype() == "swap" then
62                                 cmds:add{
63                                     cmdline = "${root}${SWAPON} ${root}dev/${dev}",
64                                     replacements = {
65                                         dev = spd:get_device_name()
66                                     }
67                                 }
68                         end
69                 end
70         end
71
72         --
73         -- Mount the target system.  This will create the
74         -- mountpoint directories the user asked for and
75         -- will mount their subpartitions on them.
76         --
77         App.state.target = TargetSystem.new(App.state.sel_part, "mnt")
78         if not App.state.target:create() then
79                 App.ui:inform(
80                     _("Could not create the skeletal target system.")
81                 )
82                 return fsm:current()
83         end
84         if not App.state.target:mount() then
85                 App.ui:inform(
86                     _("Could not mount the skeletal target system.")
87                 )
88                 return fsm:current()
89         end
90
91         --
92         -- Create the commands which will install the chosen directories
93         -- onto the target system.
94         --
95         App.state.target:cmds_install_srcs(cmds, App.load_conf("sources"))
96
97         --
98         -- If we were to copy /usr/local and /usr/X11R6 onto the HDD,
99         -- *all* packages installed on the LiveCD would be copied to
100         -- the HDD.  This may not be what the user wants.  So instead,
101         -- create an appropriate filesystem hierarchy under /usr/local
102         -- and /usr/X11R6 and populate them with only mandatory packages.
103         -- And first, remove the copied-over package database, as it is
104         -- inaccurate.
105         --
106         cmds:add(
107             "${root}${RM} -rf ${root}mnt/var/db/pkg",
108             "${root}${MKDIR} -p ${root}mnt/var/db/pkg",
109             "${root}${CHMOD} 755 ${root}mnt/var/db/pkg",
110             "${root}${MKDIR} -p ${root}mnt/usr/local",
111             "${root}${MTREE} -deU -f ${root}etc/mtree/BSD.local.dist -p ${root}mnt/usr/local",
112             "${root}${MKDIR} -p ${root}mnt/usr/X11R6",
113             "${root}${MTREE} -deU -f ${root}etc/mtree/BSD.x11-4.dist -p ${root}mnt/usr/X11R6"
114         )
115
116         --
117         -- Create symlinks.
118         --
119
120         --
121         -- If the user has both /var and /tmp subparitions,
122         -- symlink /var/tmp to /tmp.
123         --
124         if App.state.sel_part:get_subpart_by_mountpoint("/tmp") and
125            App.state.sel_part:get_subpart_by_mountpoint("/var") then
126                 cmds:add(
127                     "${root}${CHMOD} 1777 ${root}mnt/tmp",
128                     "${root}${RM} -rf ${root}mnt/var/tmp",
129                     "${root}${LN} -s /tmp ${root}mnt/var/tmp"
130                 )
131         end
132
133         --
134         -- If the user has /var, but no /tmp,
135         -- symlink /tmp to /var/tmp.
136         --
137         if not App.state.sel_part:get_subpart_by_mountpoint("/tmp") and
138            App.state.sel_part:get_subpart_by_mountpoint("/var") then
139                 cmds:add(
140                     "${root}${RM} -rf ${root}mnt/tmp",
141                     "${root}${LN} -s /var/tmp ${root}mnt/tmp"
142                 )
143         end
144
145         --
146         -- If the user has /usr, but no /home,
147         -- symlink /home to /usr/home.
148         --
149         if not App.state.sel_part:get_subpart_by_mountpoint("/home") and
150            App.state.sel_part:get_subpart_by_mountpoint("/usr") then
151                 cmds:add(
152                      "${root}${RM} -rf ${root}mnt/home",
153                      "${root}${MKDIR} ${root}mnt/usr/home",
154                      "${root}${LN} -s /usr/home ${root}mnt/home"
155                 )
156         end
157
158         --
159         -- Clean up.  In case some file didn't make it, use rm -f
160         --
161         if App.os == "DragonFly" then
162                 cmds:add("${root}${RM} -f ${root}mnt/boot/loader.conf")
163         end
164         cmds:set_replacements{
165             logfile = App.log_filename,
166             part = App.state.sel_part:get_device_name()
167         }
168         cmds:add("${root}${RM} -f ${root}mnt/tmp/${logfile}")
169
170         --
171         -- Create missing directories.
172         --
173         cmds:add(
174             "${root}${MKDIR} ${root}mnt/proc",
175             "${root}${MKDIR} ${root}mnt/mnt"
176         )
177
178         --
179         -- Write the fstab.
180         --
181         App.state.sel_part:cmds_write_fstab(cmds, "${root}mnt/etc/fstab")
182
183         --
184         -- If it was enabled and selected, write the crash device
185         -- in the user's new rc.conf file on the HDD.
186         --
187         if App.state.crash_device ~= nil then
188                 local cv = ConfigVars.new()
189
190                 cv:set("dumpdev", "/dev/" .. App.state.crash_device)
191                 cv:set("dumpdir", "/var/crash")
192                 cv:write(App.expander:expand("${root}mnt/etc/rc.conf"), "sh")
193         end
194
195         --
196         -- Install requested packages.
197         --
198         if App.state.sel_pkgs ~= nil then
199                 local pkg_name, selected
200                 local pkg_seen = {}
201                 local n, i = 0, 0
202                 local pr = App.ui:new_progress_bar{
203                     title = _("Calculating package dependencies...")
204                 }
205
206                 for pkg_name, selected in App.state.sel_pkgs do
207                         if selected then
208                                 n = n + 1
209                         end
210                 end
211
212                 pr:start()
213                 for pkg_name, selected in App.state.sel_pkgs do
214                         if selected then
215                                 Package.cmds_copy(
216                                     "mnt/", cmds, pkg_name, pkg_seen
217                                 )
218                                 i = i + 1
219                                 pr:set_amount((i * 100) / n)
220                                 pr:update()
221                         end
222                 end
223                 pr:stop()
224         end
225
226         --
227         -- Backup the disklabel and the log.
228         --
229         cmds:add(
230             "${root}${DISKLABEL} ${part} >${root}mnt/etc/disklabel.${part}",
231             "${root}${CP} ${tmp}${logfile} ${root}mnt/var/log/${logfile}",
232             "${root}${CHMOD} 600 ${root}mnt/var/log/${logfile}"
233         )
234
235         --
236         -- Do it!
237         --
238         if cmds:execute() then
239                 --
240                 -- If the install went successfully,
241                 -- make sure once and for all that the disklabel is bootable.
242                 --
243                 cmds = CmdChain.new()
244                 App.state.sel_part:cmds_install_bootstrap(cmds)
245                 if not cmds:execute() then
246                         App.ui:inform(
247                             _("Failed to make sure that the partition is bootable.")
248                         )
249                 end
250                 return fsm:next()
251         else
252                 App.ui:inform(
253                     _("%s was not fully installed.", App.os.name)
254                 )
255                 return fsm:current()
256         end
257     end
258 }