This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
solder
executable file
·150 lines (120 loc) · 3.64 KB
/
solder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env php
<?php
use GuzzleHttp\Client;
use Symfony\Component\Console\Helper\ProgressBar;
if (file_exists(__DIR__.'/vendor/autoload.php'))
{
require __DIR__.'/vendor/autoload.php';
}
else
{
require __DIR__.'/../../autoload.php';
}
function solder_path()
{
if (isset($_SERVER['HOME']))
{
return $_SERVER['HOME'].'/.solder-toolbelt';
}
else
{
return $_SERVER['HOMEDRIVE'].$_SERVER['HOMEPATH'].'.solder-toolbelt';
}
}
function solder_config()
{
if( !is_file(solder_path().'/Solder.json') ) {
throw new \InvalidArgumentException("Solder has not been initialized.");
}
return json_decode(file_get_contents(solder_path().'/Solder.json'));
}
function downloadFile($srcName, $dstName, $output, $md5 = false, $chunkSize = 1024)
{
$host = parse_url($srcName);
$host = $host['scheme'] . '://' . $host['host'];
$output->write("Connecting to $host... ");
$head = array_change_key_case(get_headers($srcName, TRUE));
if (($handle = fopen($srcName, 'rb')) === false) {
throw new \Exception('Cannot open remote file');
}
$output->writeln($head[0]);
$filesize = $head['content-length'];
$humanFilesize = human_filesize($filesize, 1);
$output->writeln("Length: $filesize ($humanFilesize) [{$head['content-type']}]");
$output->writeln("Saving to: `$dstName`");
if (($fp = fopen($dstName, 'w')) === false) {
throw new \Exception('Cannot write to local file');
}
$output->writeln('');
$progress = new ProgressBar($output, $filesize);
$progress->start();
$bytesCount = 0;
while (!feof($handle)) {
$data = fread($handle, $chunkSize);
fwrite($fp, $data, strlen($data));
$bytesCount += strlen($data);
$progress->setProgress($bytesCount);
}
$progress->finish();
$output->writeln('');
$output->writeln('');
$hash = md5_file($dstName);
$checksum = '';
if( $md5 ) {
$checksum = ($md5 == $hash ? 'OK' : 'FAIL');
}
$output->writeln("$hash `$dstName` saved [$bytesCount/$filesize] $checksum");
fclose($fp);
fclose($handle);
}
function unpackFile($zipFile, $output, $extractTo = false)
{
$zip = new \ZipArchive;
if( $extractTo == false ) {
$extractTo = dirname($zipFile);
}
$output->writeln("unpacking $zipFile to $extractTo");
$zip->open($zipFile);
$zip->extractTo($extractTo);
$zip->close();
$zip = null;
unlink($zipFile);
}
function human_filesize($bytes, $decimals = 2)
{
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
function slug($str, $replace=array(), $delimiter='-')
{
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}
function displayServerInfo($output)
{
$apiClient = new Client();
$appConfig = solder_config();
$technicSolder = $apiClient->get($appConfig->api)->json();
if(isset($technicSolder['error'])) {
throw new \Exception($technicSolder['error']);
}
$output->writeln('<comment>Server:</comment>');
$output->writeln(" <info>{$technicSolder['api']}</info> {$technicSolder['version']}");
$output->writeln(" <info>url</info> {$appConfig->api}");
$apiClient = null;
$appConfig = null;
$technicSolder = null;
}
$app = new Symfony\Component\Console\Application('Solder Toolbelt', '0.2.2');
$app->add(new Indemnity83\SolderToolbelt\ConfigCommand);
$app->add(new Indemnity83\SolderToolbelt\InitCommand);
$app->add(new Indemnity83\SolderToolbelt\ModCommand);
$app->add(new Indemnity83\SolderToolbelt\ModpackCommand);
$app->run();