Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- echo "\n(i) preparing files\n";
- if(file_exists($argv[1]))
- $mod = $argv[1];
- if(!isset($mod)){
- if(!isset($argv[1])) echo 'no file specified';
- else echo "file not found. '".$mod."'";
- exit(0);
- }
- function downloadFile($url, $output, $options = ''){
- system('wget --quiet '.$options.' "'.$url.'" -O "'.$output.'"');
- }
- function readJsonFile($file){
- $fp = fopen($file, "r");
- $jsonData = '';
- while($data=fgets($fp)) $jsonData.=$data;
- fclose($fp);
- return json_decode($jsonData);
- }
- if(!file_exists('/tmp/curseDownloader'))
- mkdir('/tmp/curseDownloader');
- $modname = basename($mod);
- copy($mod, '/tmp/curseDownloader/'.$modname);
- echo "\n(i) deflating files...";
- system('cd /tmp/curseDownloader/ && unzip -f "'.$modname.'" >> /dev/null && rm "'.$modname.'"');
- echo " [done]\n";
- echo "\n(i) loading manifest\n";
- $manifestFile = '/tmp/curseDownloader/manifest.json';
- if(!file_exists($manifestFile)){
- echo '(!) manifest not found :(';
- exit(0);
- }
- $manifest = readJsonFile($manifestFile);
- echo '(i) parsed json file for modpack '.$manifest->version."\n\n";
- if(!file_exists('/tmp/curseDownloader/mods'))
- mkdir('/tmp/curseDownloader/mods');
- if(!file_exists('/tmp/curseDownloader/manifest'))
- mkdir('/tmp/curseDownloader/manifest');
- $i=1;
- $cnt = count($manifest->files);
- $skippedFiles = Array();
- echo '(i) starting mod downloads...'."\n";
- foreach($manifest->files as $mod){
- $modManifestUrl = 'https://addons-ecs.forgesvc.net/api/v2/addon/'.$mod->projectID.'/file/'.$mod->fileID;
- $manifestFile = '/tmp/curseDownloader/manifest/'.$mod->projectID.'.json';
- if(!file_exists($manifestFile))
- downloadFile($modManifestUrl, $manifestFile);
- $modManifest = readJsonFile($manifestFile);
- $file = '/tmp/curseDownloader/mods/'.$modManifest->fileName;
- if(file_exists($file) && filesize($file) == $modManifest->fileLength){
- $skippedFiles[] = $modManifest->fileName;
- }
- else {
- if($mod->required == "true")
- echo ' [REQUIRED] ';
- echo 'download file ';
- printf('%'.strlen($cnt).'d/'.$cnt, $i);
- echo ' :: '.$modManifest->fileName;
- downloadFile($modManifest->downloadUrl, $file, '--continue --content-disposition');
- printf(' [%3d%%]'."\n", filesize($file)/$modManifest->fileLength * 100);
- }
- $i++;
- }
- if(count($skippedFiles) > 0)
- echo '(i) skipped '.count($skippedFiles).' existing files'."\n";
- if($manifest->overrides != 'overrides')
- echo var_dump($manifest->overrides);
- echo "\n".'(!) use minecraft version: '.$manifest->minecraft->version."\n";
- foreach($manifest->minecraft->modLoaders as $loader){
- echo ' + modloader '.$loader->id."\n";
- }
- echo "\n".'(i) cleaning up'."\n";
- exit(1)
- ?>
Add Comment
Please, Sign In to add comment