1 |
741fe28d
|
Scott Ullrich
|
#!/usr/local/bin/php -f
|
2 |
|
|
|
3 |
|
|
<?php
|
4 |
|
|
|
5 |
|
|
echo "Starting the pfSense console firmware update system";
|
6 |
|
|
|
7 |
|
|
echo ".";
|
8 |
|
|
require("globals.inc");
|
9 |
|
|
$g['booting'] = true;
|
10 |
|
|
require("functions.inc");
|
11 |
|
|
echo ".";
|
12 |
|
|
require("config.inc");
|
13 |
|
|
echo ".";
|
14 |
|
|
$g['booting'] = false;
|
15 |
|
|
|
16 |
|
|
$fp = fopen('php://stdin', 'r');
|
17 |
|
|
|
18 |
|
|
echo ".\n\n";
|
19 |
|
|
|
20 |
|
|
$shell_active = true;
|
21 |
|
|
|
22 |
|
|
echo "1) Update from a URL\n";
|
23 |
|
|
echo "2) Update from a local file\n";
|
24 |
|
|
echo "Q) Quit\n";
|
25 |
|
|
|
26 |
|
|
echo "\nPlease select an option to continue: ";
|
27 |
|
|
|
28 |
|
|
$command = strtoupper(chop(fgets($fp)));
|
29 |
|
|
|
30 |
|
|
switch ($command) {
|
31 |
|
|
case "q":
|
32 |
|
|
case "quit":
|
33 |
|
|
echo "\n";
|
34 |
5397d0eb
|
Scott Ullrich
|
fclose($fp);
|
35 |
741fe28d
|
Scott Ullrich
|
die;
|
36 |
|
|
break;
|
37 |
|
|
case "1":
|
38 |
|
|
echo "\nEnter the URL to the .tgz update file:\n> ";
|
39 |
|
|
$url = chop(fgets($fp));
|
40 |
5397d0eb
|
Scott Ullrich
|
if(!$url) {
|
41 |
|
|
fclose($fp);
|
42 |
b65aeb25
|
Scott Ullrich
|
die;
|
43 |
5397d0eb
|
Scott Ullrich
|
}
|
44 |
741fe28d
|
Scott Ullrich
|
$status = does_url_exist($url);
|
45 |
|
|
if($status) {
|
46 |
ceab1c91
|
Scott Ullrich
|
conf_mount_rw();
|
47 |
b55d122c
|
Scott Ullrich
|
echo "\nFetching file size...\n";
|
48 |
|
|
$file_size = exec("fetch -s \"$url\"");
|
49 |
|
|
$file_size = trim($file_size, "\r");
|
50 |
|
|
echo "\nFile size: $file_size\n";
|
51 |
b83c330b
|
Scott Ullrich
|
echo "\nFetching file...\n";
|
52 |
e892ac9a
|
Scott Ullrich
|
exec("fetch -1 -w15 -a -v -o /root/firmware.tgz \"$url\"");
|
53 |
|
|
if($file_size <> filesize("/root/firmware.tgz")) {
|
54 |
b55d122c
|
Scott Ullrich
|
echo "\nFile size mismatch. Upgrade cancelled.\n\n";
|
55 |
5397d0eb
|
Scott Ullrich
|
fclose($fp);
|
56 |
b55d122c
|
Scott Ullrich
|
die;
|
57 |
|
|
}
|
58 |
e892ac9a
|
Scott Ullrich
|
if(!file_exists("/root/firmware.tgz")) {
|
59 |
b55d122c
|
Scott Ullrich
|
echo "Something went wrong during file transfer. Exiting.\n\n";
|
60 |
5397d0eb
|
Scott Ullrich
|
fclose($fp);
|
61 |
b55d122c
|
Scott Ullrich
|
die;
|
62 |
|
|
}
|
63 |
b83c330b
|
Scott Ullrich
|
$status = does_url_exist("$url.md5");
|
64 |
|
|
if($status) {
|
65 |
|
|
echo "\nFetching MD5...\n";
|
66 |
e892ac9a
|
Scott Ullrich
|
exec("fetch -1 -w15 -a -v -o /root/firmware.tgz.md5 \"$url.md5\"");
|
67 |
35870220
|
Scott Ullrich
|
} else {
|
68 |
|
|
echo "\n\nWARNING.\n";
|
69 |
|
|
echo "\nCould not locate a MD5 file. We cannot verify the download once its done.\n\n";
|
70 |
|
|
sleep(15);
|
71 |
b83c330b
|
Scott Ullrich
|
}
|
72 |
e892ac9a
|
Scott Ullrich
|
if(file_exists("/root/firmware.tgz.md5")) {
|
73 |
|
|
$source_md5 = trim(`cat /root/firmware.tgz.md5 | awk '{ print \$4 }'`,"\r");
|
74 |
|
|
$file_md5 = trim(`md5 /root/firmware.tgz | awk '{ print \$4 }'`,"\r");
|
75 |
b55d122c
|
Scott Ullrich
|
echo "URL MD5: $source_md5\n";
|
76 |
|
|
echo "Downloaded file MD5: $file_md5\n";
|
77 |
b83c330b
|
Scott Ullrich
|
if($source_md5 <> $file_md5) {
|
78 |
|
|
echo "\n\nMD5 checksum does not match. Cancelling upgrade.\n\n";
|
79 |
5397d0eb
|
Scott Ullrich
|
fclose($fp);
|
80 |
9350a642
|
Scott Ullrich
|
exec("rm -f /root/*.md5");
|
81 |
b83c330b
|
Scott Ullrich
|
die -1;
|
82 |
|
|
}
|
83 |
|
|
echo "\nMD5 checksum matches.\n";
|
84 |
9350a642
|
Scott Ullrich
|
exec("rm -f /root/*.md5");
|
85 |
b83c330b
|
Scott Ullrich
|
}
|
86 |
e892ac9a
|
Scott Ullrich
|
if(file_exists("/root/firmware.tgz"))
|
87 |
|
|
do_upgrade("/root/firmware.tgz");
|
88 |
741fe28d
|
Scott Ullrich
|
} else {
|
89 |
|
|
echo "\nCould not download update.\n\n";
|
90 |
5397d0eb
|
Scott Ullrich
|
fclose($fp);
|
91 |
741fe28d
|
Scott Ullrich
|
die -1;
|
92 |
|
|
}
|
93 |
|
|
case "2":
|
94 |
|
|
echo "\nEnter the complete path to the .tgz update file: ";
|
95 |
|
|
$path = chop(fgets($fp));
|
96 |
5397d0eb
|
Scott Ullrich
|
if(!$path) {
|
97 |
|
|
fclose($fp);
|
98 |
b65aeb25
|
Scott Ullrich
|
die;
|
99 |
5397d0eb
|
Scott Ullrich
|
}
|
100 |
741fe28d
|
Scott Ullrich
|
if(file_exists($path)) {
|
101 |
|
|
do_upgrade($path);
|
102 |
|
|
} else {
|
103 |
|
|
echo "\nCould not find file.\n\n";
|
104 |
5397d0eb
|
Scott Ullrich
|
fclose($fp);
|
105 |
741fe28d
|
Scott Ullrich
|
die -1;
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
|
109 |
1fe14a9b
|
Scott Ullrich
|
function check_for_kernel_file() {
|
110 |
df6ec31b
|
Scott Ullrich
|
global $fp;
|
111 |
1fe14a9b
|
Scott Ullrich
|
if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
|
112 |
|
|
echo "\nPlease select which kernel you would like to use:\n";
|
113 |
|
|
echo "\n1. Non SMP kernel";
|
114 |
|
|
echo "\n2. SMP kernel";
|
115 |
|
|
echo "\n3. Embedded kernel (no video or keyboard)";
|
116 |
74fd3fa4
|
Scott Ullrich
|
echo "\n4. Developers kernel (slower performing, more debugging)\n";
|
117 |
1fe14a9b
|
Scott Ullrich
|
echo "\nPlease enter a number [1-4]: ";
|
118 |
|
|
$selection = strtoupper(chop(fgets($fp)));
|
119 |
|
|
switch ($selection) {
|
120 |
|
|
case "1":
|
121 |
|
|
touch("/boot/kernel/pfsense_kernel.txt");
|
122 |
|
|
break;
|
123 |
|
|
case "2":
|
124 |
|
|
exec("echo SMP > /boot/kernel/pfsense_kernel.txt");
|
125 |
|
|
break;
|
126 |
|
|
case "3":
|
127 |
|
|
exec("echo wrap > /boot/kernel/pfsense_kernel.txt");
|
128 |
|
|
break;
|
129 |
|
|
case "4":
|
130 |
|
|
exec("echo Developers > /boot/kernel/pfsense_kernel.txt");
|
131 |
|
|
break;
|
132 |
|
|
}
|
133 |
|
|
echo "\n";
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
|
137 |
741fe28d
|
Scott Ullrich
|
function do_upgrade($path) {
|
138 |
df6ec31b
|
Scott Ullrich
|
global $fp;
|
139 |
1fe14a9b
|
Scott Ullrich
|
check_for_kernel_file();
|
140 |
741fe28d
|
Scott Ullrich
|
echo "\nOne moment please... Invoking firmware upgrade...\n";
|
141 |
|
|
exec("/etc/rc.firmware pfSenseupgrade $path");
|
142 |
98a56ef7
|
Scott Ullrich
|
unlink_if_exists($path);
|
143 |
ccc1091a
|
Scott Ullrich
|
die;
|
144 |
741fe28d
|
Scott Ullrich
|
}
|
145 |
|
|
|
146 |
9350a642
|
Scott Ullrich
|
exec("rm -f /root/*.md5");
|
147 |
4ccb4974
|
Scott Ullrich
|
fclose($fp);
|
148 |
|
|
|
149 |
9350a642
|
Scott Ullrich
|
?>
|