Revision d62bcdef
Added by Scott Ullrich almost 16 years ago
etc/rc.initial.firmware_update | ||
---|---|---|
1 |
#!/usr/local/bin/php -f |
|
2 |
|
|
3 |
<?php |
|
4 |
|
|
5 |
$g['booting'] = true; |
|
6 |
require("globals.inc"); |
|
7 |
|
|
8 |
echo "Starting the {$g['product_name']} console firmware update system"; |
|
9 |
|
|
10 |
require("functions.inc"); |
|
11 |
echo "."; |
|
12 |
require("config.inc"); |
|
13 |
echo "."; |
|
14 |
$g['booting'] = false; |
|
15 |
|
|
16 |
$d_fwupenabled_path = $g['varrun_path'] . "/fwup.enabled"; |
|
17 |
|
|
18 |
$fp = fopen('php://stdin', 'r'); |
|
19 |
|
|
20 |
echo ".\n\n"; |
|
21 |
|
|
22 |
$shell_active = true; |
|
23 |
|
|
24 |
echo "1) Update from a URL\n"; |
|
25 |
echo "2) Update from a local file\n"; |
|
26 |
echo "Q) Quit\n"; |
|
27 |
|
|
28 |
echo "\nPlease select an option to continue: "; |
|
29 |
|
|
30 |
$command = strtoupper(chop(fgets($fp))); |
|
31 |
|
|
32 |
switch ($command) { |
|
33 |
case "q": |
|
34 |
case "quit": |
|
35 |
echo "\n"; |
|
36 |
fclose($fp); |
|
37 |
die; |
|
38 |
break; |
|
39 |
case "1": |
|
40 |
echo "\nEnter the URL to the .tgz update file:\n> "; |
|
41 |
$url = chop(fgets($fp)); |
|
42 |
if(!$url) { |
|
43 |
fclose($fp); |
|
44 |
die; |
|
45 |
} |
|
46 |
$status = does_url_exist($url); |
|
47 |
if($status) { |
|
48 |
conf_mount_rw(); |
|
49 |
touch($d_fwupenabled_path); |
|
50 |
if(file_exists("/root/firmware.tgz")) |
|
51 |
unlink("/root/firmware.tgz"); |
|
52 |
echo "\nFetching file size...\n"; |
|
53 |
$file_size = exec("fetch -s \"$url\""); |
|
54 |
$file_size = trim($file_size, "\r"); |
|
55 |
echo "\nFile size: $file_size\n"; |
|
56 |
echo "\nFetching file...\n"; |
|
57 |
exec("fetch -1 -w15 -a -v -o /root/firmware.tgz \"$url\""); |
|
58 |
if($file_size <> filesize("/root/firmware.tgz")) { |
|
59 |
echo "\nFile size mismatch. Upgrade cancelled.\n\n"; |
|
60 |
fclose($fp); |
|
61 |
die; |
|
62 |
} |
|
63 |
if(!file_exists("/root/firmware.tgz")) { |
|
64 |
echo "Something went wrong during file transfer. Exiting.\n\n"; |
|
65 |
fclose($fp); |
|
66 |
die; |
|
67 |
} |
|
68 |
$status = does_url_exist("$url.md5"); |
|
69 |
if($status) { |
|
70 |
echo "\nFetching MD5...\n"; |
|
71 |
exec("fetch -1 -w15 -a -v -o /root/firmware.tgz.md5 \"$url.md5\""); |
|
72 |
} else { |
|
73 |
echo "\n\nWARNING.\n"; |
|
74 |
echo "\nCould not locate a MD5 file. We cannot verify the download once its done.\n\n"; |
|
75 |
sleep(15); |
|
76 |
} |
|
77 |
if(file_exists("/root/firmware.tgz.md5")) { |
|
78 |
$source_md5 = trim(`cat /root/firmware.tgz.md5 | awk '{ print \$4 }'`,"\r"); |
|
79 |
$file_md5 = trim(`md5 /root/firmware.tgz | awk '{ print \$4 }'`,"\r"); |
|
80 |
echo "URL MD5: $source_md5\n"; |
|
81 |
echo "Downloaded file MD5: $file_md5\n"; |
|
82 |
if($source_md5 <> $file_md5) { |
|
83 |
echo "\n\nMD5 checksum does not match. Cancelling upgrade.\n\n"; |
|
84 |
exec("rm -f /root/*.md5"); |
|
85 |
fclose($fp); |
|
86 |
die -1; |
|
87 |
} |
|
88 |
echo "\nMD5 checksum matches.\n"; |
|
89 |
exec("rm -f /root/*.md5"); |
|
90 |
} |
|
91 |
if(stristr($url,"bdiff")) |
|
92 |
$type = "bdiff"; |
|
93 |
if(stristr($url,"bdiff")) |
|
94 |
$type = "nanobsd"; |
|
95 |
if(file_exists("/root/firmware.tgz")) { |
|
96 |
do_upgrade("/root/firmware.tgz", $type); |
|
97 |
exit; |
|
98 |
} |
|
99 |
} else { |
|
100 |
echo "\nCould not download update.\n\n"; |
|
101 |
fclose($fp); |
|
102 |
die -1; |
|
103 |
} |
|
104 |
case "2": |
|
105 |
echo "\nEnter the complete path to the .tgz update file: "; |
|
106 |
$path = chop(fgets($fp)); |
|
107 |
if(!$path) { |
|
108 |
fclose($fp); |
|
109 |
die; |
|
110 |
} |
|
111 |
if(stristr($fp,"bdiff")) |
|
112 |
$type = "bdiff"; |
|
113 |
if(stristr($fp,"bdiff")) |
|
114 |
$type = "nanobsd"; |
|
115 |
if(file_exists($path)) { |
|
116 |
touch($d_fwupenabled_path); |
|
117 |
do_upgrade($path, $type); |
|
118 |
} else { |
|
119 |
echo "\nCould not find file.\n\n"; |
|
120 |
fclose($fp); |
|
121 |
die -1; |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
function check_for_kernel_file() { |
|
126 |
global $fp; |
|
127 |
$platform = file_get_contents("/etc/platform"); |
|
128 |
$platform = str_replace("\n", "", $platform); |
|
129 |
$platform = str_replace("\r", "", $platform); |
|
130 |
if($platform == "embedded" or $platform == "wrap" or $platform == "nanobsd") { |
|
131 |
exec("echo wrap > /boot/kernel/pfsense_kernel.txt"); |
|
132 |
echo "\n"; |
|
133 |
return; |
|
134 |
} |
|
135 |
if(!file_exists("/boot/kernel/pfsense_kernel.txt")) { |
|
136 |
echo "\nPlease select which kernel you would like to use:\n"; |
|
137 |
echo "\n1. Non SMP kernel"; |
|
138 |
echo "\n2. SMP kernel"; |
|
139 |
echo "\n3. Embedded kernel (no video or keyboard)"; |
|
140 |
echo "\n4. Developers kernel (slower performing, more debugging)\n"; |
|
141 |
echo "\nPlease enter a number [1-4]: "; |
|
142 |
$selection = strtoupper(chop(fgets($fp))); |
|
143 |
switch ($selection) { |
|
144 |
case "1": |
|
145 |
exec("echo UP > /boot/kernel/pfsense_kernel.txt"); |
|
146 |
break; |
|
147 |
case "2": |
|
148 |
exec("echo SMP > /boot/kernel/pfsense_kernel.txt"); |
|
149 |
break; |
|
150 |
case "3": |
|
151 |
exec("echo wrap > /boot/kernel/pfsense_kernel.txt"); |
|
152 |
break; |
|
153 |
case "4": |
|
154 |
exec("echo Developers > /boot/kernel/pfsense_kernel.txt"); |
|
155 |
break; |
|
156 |
} |
|
157 |
echo "\n"; |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
function do_upgrade($path, $type) { |
|
162 |
global $g; |
|
163 |
touch($g['varrun_path'] . "/firmware.lock"); |
|
164 |
check_for_kernel_file(); |
|
165 |
echo "\nOne moment please...\nInvoking firmware upgrade..."; |
|
166 |
if($type == "bdiff") |
|
167 |
mwexec_bg("/etc/rc.firmware delta_update $path"); |
|
168 |
elseif($type == "nanobsd") |
|
169 |
mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade $path"); |
|
170 |
else |
|
171 |
mwexec_bg("/etc/rc.firmware pfSenseupgrade $path"); |
|
172 |
sleep(10); |
|
173 |
while(file_exists("{$g['varrun_path']}/firmware.lock")) { |
|
174 |
sleep(1); |
|
175 |
echo "."; |
|
176 |
} |
|
177 |
echo "Done. Rebooting...\n\n"; |
|
178 |
unlink($g['varrun_path'] . "/firmware.lock"); |
|
179 |
} |
|
180 |
|
|
181 |
exec("rm -f /root/*.md5"); |
|
182 |
fclose($fp); |
|
183 |
|
|
184 |
?> |
Also available in: Unified diff
Adding new file from master