Skip to content

Commit

Permalink
Reduce memory_usage, normalize formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
L00Cyph3r committed Aug 26, 2022
1 parent 3d81bf9 commit e6ffa1b
Showing 1 changed file with 36 additions and 49 deletions.
85 changes: 36 additions & 49 deletions download_latest.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,54 @@
#!/usr/bin/env php
<?php
$dir = dirname(__FILE__);
echo 'Cleaning up old installs' . PHP_EOL;
array_map('unlink', glob('*.tar.gz'));
array_map('unlink', glob('*.sha256'));

echo "Cleaning up old installs\n";
array_map('unlink', glob("*.tar.gz"));
array_map('unlink', glob("*.sha256"));
echo 'Downloading new version' . PHP_EOL;
$url = 'https://data.services.jetbrains.com/products/releases?code=PS&latest=true';
$latestRelease = file_get_contents($url);

echo "Downloading new version\n";
$url = "https://data.services.jetbrains.com/products/releases?code=PS&latest=true";
$result = curlDownload($url);
$data = json_decode($latestRelease, true);
$link = $data['PS'][0]['downloads']['linux']['link'];
$md5sum = $data['PS'][0]['downloads']['linux']['checksumLink'];

$data = json_decode($result, true);
$link = $data["PS"][0]["downloads"]["linux"]["link"];
$md5sum = $data["PS"][0]["downloads"]["linux"]["checksumLink"];

echo "Downloading $link\n";
echo 'Downloading $link' . PHP_EOL;

$filename = basename($link);
$checksumName = basename($md5sum);

curlDownload($link, $dir."/".$filename);
echo "Downloading $md5sum\n";
curlDownload($md5sum, $dir."/".$checksumName);
curlDownload($link, __DIR__ . '/' . $filename);
echo 'Downloading $md5sum' . PHP_EOL;
curlDownload($md5sum, __DIR__ . '/' . $checksumName);

echo "Verifying checksum";
$exitcode = "";
$output = "";
exec ("sha256sum -c $dir/$checksumName", $output, $exitcode);
echo 'Verifying checksum';
exec('sha256sum -c ' . escapeshellarg(__DIR__ . '/' . $checksumName), $output, $exitcode);

if ((int)$exitcode !== 0)
{
echo "Checksum failed!";
exit;
if ($exitcode !== 0) {
echo 'Checksum failed!';
exit(1);
}

shell_exec($dir."/update.sh");
echo "Download and update complete. Execute the following commands to build and update the new php version\n";
shell_exec(escapeshellcmd(__DIR__ . '/update.sh'));
echo 'Download and update complete. Execute the following commands to build and update the new php version' . PHP_EOL;

echo "Building latest version.. \n";
chdir ($dir);
exec("debuild -us -uc -b");
echo 'Building latest version...' . PHP_EOL;
chdir(__DIR__);
exec('debuild -us -uc -b');

$debname = str_replace("-","_",strtolower(basename($filename,".tar.gz"))."_all.deb");
echo "Build complete. Install the new version by using \n";
echo "sudo dpkg -i ../$debname";
$debname = str_replace('-', '_', strtolower(basename($filename, '.tar.gz')) . '_all.deb');
echo 'Build complete. Install the new version by using' . PHP_EOL;
echo 'sudo dpkg -i ../' . $debname;

function curlDownload($url, $destination = null)
function curlDownload($url, $destination)
{
$ch = curl_init();
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result=curl_exec($ch);

// Closing
curl_close($ch);
if ($destination)
{
$file = fopen($destination, "w+");
fputs($file, $result);
fclose($file);
}

return $result;
$file = fopen($destination, 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $file);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);

fclose($file);
curl_close($ch);
}

0 comments on commit e6ffa1b

Please sign in to comment.