Skip to content

Commit

Permalink
Check size of fppos file before upgrading and remove partial downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
darylc authored and dkulp committed Oct 9, 2023
1 parent b801e68 commit 4129ee6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
19 changes: 19 additions & 0 deletions SD/upgradeOS-part1.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/bin/bash

FPPOS=`/usr/bin/basename $1`
GITHUBSIZE=`curl -fsSL http://127.0.0.1/api/git/releases/sizes | grep ${FPPOS} | awk -F, '{print $2}'`
OURSIZE=`/usr/bin/stat -c %s $1`

if ! [[ $GITHUBSIZE =~ ^-?[0-9]+$ ]];
then
echo "Couldn't get fppos size from Github, attempting upgrade anyway"
else
if [ "$OURSIZE" -lt "$GITHUBSIZE" ];
then
echo "Download size seems too small. Our size: $OURSIZE, Github size: $GITHUBSIZE deleting $1"
echo "Please try to download the fppos again"
rm $1
exit 1;
else
echo "fppos size matches Github, continuing"
fi
fi

mount $1 /mnt

ORIGTYPE=$(</etc/fpp/platform)
Expand Down
41 changes: 40 additions & 1 deletion www/api/controllers/git.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,43 @@ function GitOSReleases()
return json($rc);
}

?>
// GET http://fpp/api/git/releases/sizes
// Returns fppos file sizes
// Should re-write this to call GetOSReleases() and parse instead of hitting github directly.
function GitOSReleaseSizes()
{
global $settings;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.github.com/repos/FalconChristmas/fpp/releases?per_page=100");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0");
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 4000);
$request_content = curl_exec($curl);
curl_close($curl);

$rc = "";

if ($request_content != false) {
$data = json_decode($request_content, true);
foreach ($data as $r) {
if (isset($r["assets"]) && $settings['OSImagePrefix'] != "") {
foreach ($r["assets"] as $file) {
$name = $file["name"];
if (endsWith($name, ".fppos") && startsWith($name, $settings['OSImagePrefix'])) {
$rc = $rc . $name . "," . $file["size"] . "\n";
}
}
}
}

} else {
$rc = "Error: " . curl_error($curl) . "\n";
}

return $rc;
}

?>
1 change: 1 addition & 0 deletions www/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

dispatch_get('/git/originLog', 'GetGitOriginLog');
dispatch_get('/git/releases/os', 'GitOSReleases');
dispatch_get('/git/releases/sizes', 'GitOSReleaseSizes');
dispatch_get('/git/reset', 'GitReset');
dispatch_get('/git/status', 'GitStatus');

Expand Down
12 changes: 9 additions & 3 deletions www/upgradeOS.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
copy("$fppDir/SD/upgradeOS-part1.sh", $TMP_FILE);
chmod($TMP_FILE, 0775);
#system($SUDO . " stdbuf --output=L --error=L $TMP_FILE /home/fpp/media/upload/$baseFile");
system($SUDO . " $TMP_FILE /home/fpp/media/upload/$baseFile");
$return_code = 0;
system($SUDO . " $TMP_FILE /home/fpp/media/upload/$baseFile",$return_code);
} else {
echo ("Skipping update\n");
}
Expand All @@ -96,14 +97,19 @@
</body>
</html>
<?
} else {
} else if ($applyUpdate && ($return_code == 0)) {
echo "==========================================================================\n";
echo "Rebooting.....Close this window and refresh the screen. It might take a minute or so for FPP to reboot\n";
} else {
echo "==========================================================================\n";
echo "FPP UPGRADE FAILED\n";
echo "==========================================================================\n";
}
while (@ob_end_flush());
flush();
session_write_close();

if ($applyUpdate) {
if ($applyUpdate && ($return_code == 0)) {
sleep(3);
system($SUDO . " shutdown -r now");
}
Expand Down

0 comments on commit 4129ee6

Please sign in to comment.