Menu

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

Download this file

214 lines (176 with data), 6.2 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
<?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 */
echo "\nCreating mount point for the CDROM...\n";
if (is_dir("/mnt/cdrom_fr_0507")) {
echo "Temporary directory for CD already exists!\n";
return 1;
}
/* Creating tempo directory for cdrom*/
if (mwexec("/bin/mkdir /mnt/cdrom_fr_0507")) {
echo "Can't create the temporary folder!\n";
return 1;
}
/* Monting the CDROM */
echo "Mount CDROM...\n";
if (mwexec("/sbin/mount_cd9660 /dev/$cdrom /mnt/cdrom_fr_0507")) {
echo "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 */
echo "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 */
fdisk_hd_install($harddrive);
if (mwexec("(/bin/echo y; /bin/echo y) | /sbin/fdisk -B -b /boot/mbr $harddrive")) {
echo "Can't fdisk the destination drive!\n";
return 1;
}
/* Must wait that the /dev is upatded with the new information */
echo "Waiting for system update...";
$devtotest="/dev/$harddrive". "s2";
$i=0;
while (!file_exists($devtotest)) {
sleep(1);
echo ".";
$i++;
if ($i==20) {
echo " System not updated after 20 seconds!\n";
return 1;
}
}
echo "\n";
echo "Creating BSD label...\n";
if (mwexec("/sbin/bsdlabel -B -w -b /boot/boot " . escapeshellarg($harddrive) ."s1 auto")) {
return 1;
}
if (mwexec("/sbin/bsdlabel -w " . escapeshellarg($harddrive) ."s2 auto")) {
return 1;
}
echo "Modify BSD label information...\n";
disks_bsdlabel($harddrive,"s1","4.2BSD");
disks_bsdlabel($harddrive,"s2","4.2BSD");
echo "Creating filesystem...\n";
if (mwexec("/sbin/newfs -U /dev/" . escapeshellarg($harddrive) . "s1")) {
return 1;
}
if (mwexec("/sbin/newfs -U /dev/" . escapeshellarg($harddrive) . "s2")) {
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....
echo "Installation...\n";
if (mwexec("/usr/bin/gunzip -S \"\" -c /mnt/cdrom_fr_0507/".get_product_name()."-generic-pc.gz | dd of=/dev/".escapeshellarg($harddrive)." bs=512 > /dev/null 2>&1"))
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")) {
echo "Can't create /tmp/configbak!\n";
return 1;
}
if (mwexec("/bin/mkdir /tmp/installdrive")) {
echo "Can't create /tmp/installdrive!\n";
return 1;
}
/* mounting the drive to be upgraded */
if (mwexec("/sbin/mount /dev/$disk /tmp/installdrive")) {
echo "Can't mount the drive to be upgraded!\n";
$result = 1;
}
/* Backuping the config file */
if (mwexec("cp -p /tmp/installdrive/conf/* /tmp/configbak")) {
echo "Can't backup the config file!\n";
return 1;
}
/* unmounting the drive to be upgraded */
if (mwexec("/sbin/umount -f /dev/$disk")) {
echo "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")) {
echo "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")) {
echo "Can't restore the config file!\n";
return 1;
}
/* unmount the upgraded drive */
if (mwexec("/sbin/umount -f /dev/$disk")) {
echo "Can't unmount the drive just upgraded!\n";
$result = 1;
}
return 0;
}
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.