diff --git a/SD/upgradeOS-part1.sh b/SD/upgradeOS-part1.sh index 89d7ff4b2..ac0842132 100755 --- a/SD/upgradeOS-part1.sh +++ b/SD/upgradeOS-part1.sh @@ -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=$( \ No newline at end of file +// 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; +} + +?> diff --git a/www/api/index.php b/www/api/index.php index a0d759c7d..29a99ff17 100644 --- a/www/api/index.php +++ b/www/api/index.php @@ -54,6 +54,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'); diff --git a/www/upgradeOS.php b/www/upgradeOS.php index c3966e34d..41cb29a22 100755 --- a/www/upgradeOS.php +++ b/www/upgradeOS.php @@ -93,7 +93,8 @@ } 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"); } @@ -108,15 +109,19 @@