Last active
September 3, 2018 14:39
-
-
Save matheusfaustino/849893bfb8f2ed95bfdfadd113743d31 to your computer and use it in GitHub Desktop.
ShadowFox Updater Updater - update the updater of shadowfox (for linux 64, yet) https://github.com/overdodactyl/ShadowFox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$latestRelease = 'https://api.github.com/repos/SrKomodo/shadowfox-updater/releases/latest'; | |
$tempFilename = 'temp_shadowfox.tar.gz'; | |
$os = 'Linux_x64'; | |
$context = \stream_context_create([ | |
'http' => [ | |
'method' => 'GET', | |
'header' => 'Accept: application/vnd.github.v3+json', | |
'user_agent' => 'Shadowfox Updater Updater PHP', | |
'protocol_version' => 1.1, | |
] | |
]); | |
print 'listing repo...'.PHP_EOL; | |
$resp = \file_get_contents($latestRelease, false, $context); | |
$respJson = \json_decode($resp, true); | |
print 'finding file...'.PHP_EOL; | |
$failed = false; | |
foreach ($respJson['assets'] as $asset) { | |
if (\strpos($asset['name'], $os) !== false) { | |
print 'saving file...'.PHP_EOL; | |
$failed = \file_put_contents( | |
$tempFilename, | |
\file_get_contents($asset['browser_download_url'], false, $context) | |
); | |
break; | |
} | |
} | |
if (false === $failed) { | |
print 'no file saved...'.PHP_EOL; | |
return 0; | |
} | |
print 'extracting file...'.PHP_EOL; | |
try { | |
$tarFile = new PharData($tempFilename); | |
$tarFile->extractTo(__DIR__.'/', null, true); | |
print 'extracted.'.PHP_EOL; | |
} catch (\Exception $e) { | |
print $e->getMessage(); | |
} | |
unlink($tempFilename); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment