Project

General

Profile

« Previous | Next » 

Revision e173dd74

Added by Phil Davis over 10 years ago

Code style for etc files

View differences:

etc/rc.initial.firmware_update
11 11
require("functions.inc");
12 12
echo ".";
13 13

  
14
if(isset($config['system']['firmware']['alturl']['enable']))
14
if(isset($config['system']['firmware']['alturl']['enable'])) {
15 15
	$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
16
else
16
} else {
17 17
	$updater_url = $g['update_url'];
18
}
18 19

  
19 20
$nanosize = "";
20 21
if ($g['platform'] == "nanobsd") {
21
	if (file_exists("/etc/nano_use_vga.txt"))
22
	if (file_exists("/etc/nano_use_vga.txt")) {
22 23
		$nanosize = "-nanobsd-vga-";
23
	else
24
	} else {
24 25
		$nanosize = "-nanobsd-";
26
	}
25 27

  
26 28
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
27 29
	$update_filename = "latest{$nanosize}.img.gz";
......
55 57
	case "1":
56 58
		echo "\nEnter the URL to the .tgz or .img.gz update file. \nType 'auto' to use {$autoupdateurl}\n> ";
57 59
		$url = chop(fgets($fp));
58
		if(!$url) { 
60
		if (!$url) {
59 61
			fclose($fp);
60 62
			die;
61 63
		}
62
		if($url == "auto") {
64
		if ($url == "auto") {
63 65
			$url = $autoupdateurl;
64 66
		}
65 67
		$status = does_url_exist($url);
66
		if($status) {
68
		if ($status) {
67 69
			conf_mount_rw();
68 70
			mark_subsystem_dirty('firmware');
69 71
			unlink_if_exists("/root/firmware.tgz");
70 72
			echo "\nFetching file... ";
71 73
			download_file_with_progress_bar($url, '/root/firmware.tgz');
72
			if(!file_exists("/root/firmware.tgz")) {
74
			if (!file_exists("/root/firmware.tgz")) {
73 75
				echo "Something went wrong during file transfer.  Exiting.\n\n";
74 76
				fclose($fp);
75 77
				clear_subsystem_dirty('firmware');
76 78
				die;
77 79
			}
78 80
			$status = does_url_exist("$url.sha256");
79
			if($status) { 
81
			if ($status) {
80 82
				echo "\nFetching sha256... ";
81 83
				download_file_with_progress_bar($url . ".sha256", '/root/firmware.tgz.sha256');
82 84
				echo "\n";
......
92 94
					die;
93 95
				}
94 96
			}
95
			if(file_exists("/root/firmware.tgz.sha256")) {
97
			if (file_exists("/root/firmware.tgz.sha256")) {
96 98
				$source_sha256 = trim(`cat /root/firmware.tgz.sha256 | awk '{ print \$4 }'`,"\r");
97 99
				$file_sha256 = trim(`sha256 /root/firmware.tgz | awk '{ print \$4 }'`,"\r");
98 100
				echo "URL sha256: $source_sha256\n";
99 101
				echo "Downloaded file sha256: $file_sha256\n";
100
				if($source_sha256 <> $file_sha256) {
102
				if ($source_sha256 <> $file_sha256) {
101 103
					echo "\n\nsha256 checksum does not match.  Cancelling upgrade.\n\n";
102 104
					unlink_if_exists("/root/firmware.tgz.sha256");
103 105
					fclose($fp);
......
107 109
				echo "\nsha256 checksum matches.\n";
108 110
				unlink_if_exists("/root/firmware.tgz.sha256");
109 111
			}
110
			if(strstr($url,"bdiff")) {
112
			if (strstr($url,"bdiff")) {
111 113
				echo "Binary DIFF upgrade file detected...\n";
112 114
				$type = "bdiff";
113
			} elseif(strstr($url,"nanobsd")) {
115
			} elseif (strstr($url,"nanobsd")) {
114 116
				echo "NanoBSD upgrade file detected...\n";
115 117
				$type = "nanobsd";
116 118
			} else {
......
123 125
	case "2":
124 126
		echo "\nEnter the complete path to the .tgz or .img.gz update file: ";
125 127
		$path = chop(fgets($fp));
126
		if(!$path) {
128
		if (!$path) {
127 129
			fclose($fp);
128 130
			die;
129 131
		}
130
		if(stristr($path,"bdiff"))
132
		if (stristr($path,"bdiff")) {
131 133
			$type = "bdiff";
132
		if(stristr($path,"nanobsd"))
133
			$type = "nanobsd";			
134
		if(file_exists($path)) {
134
		}
135
		if (stristr($path,"nanobsd")) {
136
			$type = "nanobsd";
137
		}
138
		if (file_exists($path)) {
135 139
			mark_subsystem_dirty('firmware');
136 140
			do_upgrade($path, $type);
137 141
			clear_subsystem_dirty('firmware');
......
144 148

  
145 149
function do_upgrade($path, $type) {
146 150
	global $g, $fp;
147
	
151

  
148 152
	$sigchk = verify_digital_signature($path);
149
	if ($sigchk == 1)
153
	if ($sigchk == 1) {
150 154
		$sig_warning = "The digital signature on this image is invalid.";
151
	else if ($sigchk == 2)
155
	} elseif ($sigchk == 2) {
152 156
		$sig_warning = "This image is not digitally signed.";
153
	else if (($sigchk == 3) || ($sigchk == 4))
157
	} elseif (($sigchk == 3) || ($sigchk == 4)) {
154 158
		$sig_warning = "There has been an error verifying the signature on this image.";
155
	if($sig_warning) {
159
	}
160
	if ($sig_warning) {
156 161
		$sig_warning = "\nWARNING! ACHTUNG! DANGER!\n\n{$sig_warning}\n\n" .
157 162
			"This means that the image you uploaded is not an official/supported image and\n" .
158 163
			"may lead to unexpected behavior or security compromises.\n\n" .
......
161 166
			"Do you want to install this image anyway at your own risk [n]?";
162 167
		echo $sig_warning;
163 168
		$command = strtoupper(chop(fgets($fp)));
164
		if(strtoupper($command) == "Y" or strtoupper($command) == "Y" or strtoupper($command) == "YES") {
169
		if (strtoupper($command) == "Y" or strtoupper($command) == "Y" or strtoupper($command) == "YES") {
165 170
			echo "\nContinuing upgrade...";
166 171
		} else {
167 172
			echo "\nUpgrade cancelled.\n\n";
......
170 175
	}
171 176
	mark_subsystem_dirty('firmwarelock');
172 177
	echo "\nOne moment please...\nInvoking firmware upgrade...";
173
	if($type == "bdiff")
178
	if ($type == "bdiff") {
174 179
		mwexec_bg("/etc/rc.firmware delta_update $path");
175
	elseif($type == "nanobsd")
180
	} elseif ($type == "nanobsd") {
176 181
		mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade $path");
177
	else
182
	} else {
178 183
		mwexec_bg("/etc/rc.firmware pfSenseupgrade $path");
184
	}
179 185
	sleep(10);
180
	while(is_subsystem_dirty('firmwarelock')) {
186
	while (is_subsystem_dirty('firmwarelock')) {
181 187
		sleep(1);
182 188
		echo ".";
183 189
	}

Also available in: Unified diff