Menu

[r887]: / trunk / etc / inc / install.inc  Maximize  Restore  History

Download this file

296 lines (245 with data), 9.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/*
system.inc
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2007 Olivier Cochard-Labbé <olivier@freenas.org>.
All rights reserved.
system_systime_set() function added by Paul Wheels (pwheels@users.sourceforge.net)
Based on m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("functions.inc");
require_once("util.inc");
/* Mount the CDROM return 0 if OK, 1 if error.
Called by install script. Return 0 if OK, 1 if not. */
function install_mount_cd($cdrom)
{
/* Part of install process: Mount the CDROM */
write_console("\nCreating mount point for the CDROM...\n");
if (is_dir("/mnt/cdrom_fr_0507")) {
write_console("Error: Temporary directory for CD already exists!\n");
return 1;
}
/* Creating tempo directory for cdrom*/
if (mwexec("/bin/mkdir /mnt/cdrom_fr_0507")) {
write_console("Error: Can't create the temporary folder!\n");
return 1;
}
/* Monting the CDROM */
write_console("Mount CDROM...\n");
if (mwexec("/sbin/mount_cd9660 /dev/{$cdrom} /mnt/cdrom_fr_0507")) {
write_console("Error: Can't mount the CDROM!\n");
return 1;
}
return 0;
}
/* Unmount CDROM and destination disk.
Called by install script. Return 0 if OK, 1 if not. */
function install_unmount_cd()
{
$result = 0;
/* Part of install process: Unmounting the disks: CDROM and destination drive */
write_console("Unmount CDROM...\n");
/* Unmounting disk */
if (mwexec("/sbin/umount /mnt/install_fr_0507")) {
$result = 1;
}
if (mwexec("/sbin/umount /mnt/cdrom_fr_0507")) {
$result = 1;
}
// Remove tempo directory
@rmdir ("/mnt/cdrom_fr_0507");
@rmdir ("/mnt/install_fr_0507");
return $result;
}
/* Create to partition on the destination hard drive.
Called by install script. Return 0 if OK, 1 if not. */
function install_init_halfdisk($harddrive)
{
/* Part of install process: Initialize the destination disk with 2 partitions */
/* Create the partitions */
install_fdisk($harddrive);
if (mwexec("(/bin/echo y; /bin/echo y) | /sbin/fdisk -B -b /boot/mbr {$harddrive}")) {
write_console("Error: Can't fdisk the destination drive '{$harddrive}'!\n");
return 1;
}
/* Must wait that the /dev is upatded with the new information */
write_console("Waiting for system update...");
$devtotest="/dev/{$harddrive}s2";
$i=0;
while (!file_exists($devtotest)) {
sleep(1);
write_console(".");
$i++;
if ($i==20) {
write_console(" System not updated after 20 seconds!\n");
return 1;
}
}
write_console("\n");
write_console("Creating BSD label...\n");
if (mwexec("/sbin/bsdlabel -B -w -b /boot/boot {$harddrive}s1 auto")) {
write_console("Error: Failed to label '{$harddrive}s1'!\n");
return 1;
}
if (mwexec("/sbin/bsdlabel -w {$harddrive}s2 auto")) {
write_console("Error: Failed to label '{$harddrive}s2'!\n");
return 1;
}
write_console("Modify BSD label information...\n");
install_bsdlabel($harddrive, "s1", "4.2BSD");
install_bsdlabel($harddrive, "s2", "4.2BSD");
write_console("Creating filesystem...\n");
if (mwexec("/sbin/newfs -U /dev/{$harddrive}s1")) {
write_console("Error: Failed to create filesystem on '/dev/{$harddrive}s1'!\n");
return 1;
}
if (mwexec("/sbin/newfs -U /dev/{$harddrive}s2")) {
write_console("Error: Failed to create filesystem on '/dev/{$harddrive}s2'!\n");
return 1;
}
return 0;
}
/* Install the IMG on the destination harddrive.
Called by install script. Return 0 if OK, 1 if not. */
function install_dd_image($harddrive)
{
/* Part of install process: dd image file on the destination disk */
// It's perhaps this brut method 'dd' that create some problem with BIOS configured on LBA or not mode....
write_console("Installation...\n");
if (mwexec("/usr/bin/gunzip -S \"\" -c /mnt/cdrom_fr_0507/".get_product_name()."-generic-pc.gz | dd of=/dev/{$harddrive} bs=512 > /dev/null 2>&1")) {
write_console("Error: Failed to dd image on '/dev/{$harddrive}'!\n");
return 1;
}
return 0;
}
/* Backup the configuration file on the hard drive/CF and unmount this drive
Called by install script. Return 0 if OK, 1 if not. */
function install_backupconfig($disk)
{
/* Creating tempo directory for the config file*/
if (mwexec("/bin/mkdir /tmp/configbak")) {
write_console("Error: Can't create /tmp/configbak!\n");
return 1;
}
if (mwexec("/bin/mkdir /tmp/installdrive")) {
write_console("Error: Can't create /tmp/installdrive!\n");
return 1;
}
/* mounting the drive to be upgraded */
if (mwexec("/sbin/mount /dev/{$disk} /tmp/installdrive")) {
write_console("Error: Can't mount the drive to be upgraded!\n");
$result = 1;
}
/* Backuping the config file */
if (mwexec("cp -p /tmp/installdrive/conf/* /tmp/configbak")) {
write_console("Error: Can't backup the config file!\n");
return 1;
}
/* unmounting the drive to be upgraded */
if (mwexec("/sbin/umount -f /dev/{$disk}")) {
write_console("Error: Can't unmount the drive to be upgraded during config backup process!\n");
$result = 1;
}
return 0;
}
function install_restoreconfig($disk)
{
/* Mount the upgraded drive in RW mode */
if (mwexec("/sbin/mount /dev/{$disk} /tmp/installdrive")) {
write_console("Error: Can't mount the drive just upgraded in RW mode!\n");
$result = 1;
}
/* Restoring the config file*/
if (mwexec("cp -p /tmp/configbak/* /tmp/installdrive/conf")) {
write_console("Error: Can't restore the config file!\n");
return 1;
}
/* unmount the upgraded drive */
if (mwexec("/sbin/umount -f /dev/{$disk}")) {
write_console("Error: Can't unmount the drive just upgraded!\n");
$result = 1;
}
return 0;
}
// Initialise HARD DRIVE for installation (creating 2 partition).
// Return 0 if successful, 1 if error
function install_fdisk($harddrive)
{
global $config, $g;
// Get disk informations.
$diskinfo = disks_get_diskinfo($harddrive);
// Setting partition size to 32Mb.
$part1_size_mbytes = 32;
$part1_size_bytes = $part1_size_mbytes * 1024 * 1024;
// Calculate partition sector sizes.
$part1_size_sectors = $part1_size_bytes / $diskinfo['sectorsize'];
$part2_size_sectors = $diskinfo['mediasize_sectors'] - $part1_size_sectors;
// Create fdisk config file (fdisk.conf).
$fd = fopen("{$g['varetc_path']}/fdisk.conf", "w");
if (!$fd) {
write_console("Error: Can't open fdisk.conf in install_fdisk().\n");
return 1;
}
$fdiskconf .= <<<EOD
g c{$diskinfo['cylinders']} h{$diskinfo['heads']} s{$diskinfo['sectors']}
p 1 165 1 $part1_size_sectors
p 2 165 $part1_size_sectors $part2_size_sectors
p 3 0 0 0
p 4 0 0 0
a 1
EOD;
fwrite($fd, $fdiskconf);
fclose($fd);
// Fdisk the disk.
mwexec("/sbin/fdisk -f {$g['varetc_path']}/fdisk.conf /dev/{$harddrive}");
return 0;
}
// Create disk label.
// Return none
function install_bsdlabel($harddrive,$partition,$type)
{
global $config, $g;
// Generating BSD Label table
passthru("/sbin/bsdlabel {$harddrive}{$partition} > {$g['tmp_path']}/label.tmp");
// put this file on a array
$tableau = file("{$g['tmp_path']}/label.tmp");
// Open this file in add mode
$handle = fopen("{$g['tmp_path']}/label.tmp", 'a');
while(list(,$val) = each($tableau)) {
// If the line contain the word "unused"
// Why did I replace 'a' with 'c' ? Must found the URL where I found this information
if (ereg ("unused",$val)) {
// Replacing c: by a:
// Why ??? Must found the web page where I see this method
$val = ereg_replace ("c:","a:", $val);
// Peplacing unused by $type
$val = ereg_replace ("unused",$type, $val);
// Adding this line add the end of the file
fwrite($handle, $val);
}
}
// Closing file
fclose($handle);
// Injecting this new partition table
passthru("/sbin/bsdlabel -R -B {$harddrive}{$partition} {$g['tmp_path']}/label.tmp");
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.