-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdashdupdate
executable file
·87 lines (75 loc) · 3.21 KB
/
dashdupdate
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
#!/usr/bin/php
<?php
/*
This file is part of Dash Ninja.
https://github.com/elbereth/dashninja-ctl
Dash Ninja is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Dash Ninja is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dash Ninja. If not, see <http://www.gnu.org/licenses/>.
*/
require_once("dmn.functions.inc.php");
function tempdir($prefix='php') {
$tempfile=tempnam(sys_get_temp_dir(),$prefix);
if (file_exists($tempfile)) { unlink($tempfile); }
mkdir($tempfile);
if (is_dir($tempfile)) { return $tempfile; }
}
function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
xecho("dashd auto updater (testnet) v1.0\n");
xecho("Retrieving current latest binary date and size: ");
$test = get_headers("https://dashpay.atlassian.net/builds/browse/DASHL-DEV/latest/artifact/JOB1/gitian-linux-dash-dist/dash-0.12.0-linux64.tar.gz", 1);
echo $test["Last-Modified"]."\n";
$datanew = sha1(serialize(array("Last-Modified" => $test["Last-Modified"],
"Content-Length" => $test["Content-Length"])));
xecho("Retrieving current binary date and size: ");
$dataold = file_get_contents(DMN_DIR."dashdupdate.php.lasthash");
echo "OK\n";
if ($datanew != $dataold) {
file_put_contents(DMN_DIR."/dashdupdate.php.lasthash",$datanew);
xecho("Stopping testnet nodes... ");
passthru(DMN_DIR."/dmnctl stop testnet");
passthru(DMN_DIR."/dmnctl stop testnet p2pool");
xecho("Reseting data (not the blockchain/wallet)... ");
passthru(DMN_DIR."/dmnreset test tdmn01",$output);
passthru(DMN_DIR."/dmnreset test tdmn02");
passthru(DMN_DIR."/dmnreset test tdmn03");
passthru(DMN_DIR."/dmnreset test tdmn04");
passthru(DMN_DIR."/dmnreset test tp2pool");
xecho("Getting new binary: ");
$tmpdir = tempdir("dashdupdater");
$curdir = getcwd();
chdir($tmpdir);
passthru("wget -q https://dashpay.atlassian.net/builds/browse/DASHL-DEV/latest/artifact/JOB1/gitian-linux-dash-dist/dash-0.12.0-linux64.tar.gz");
echo "OK... Untar: ";
passthru("tar xvf dash-0.12.0-linux64.tar.gz");
echo "OK... Version: ";
$fnam = $tmpdir."/dash-0.12.0/bin/dashd";
$versionraw = dmn_dashdversion($fnam);
echo $versionraw."... Moving: ";
$fnamnew = "/opt/dashd/0.12/dashd-$versionraw";
rename($fnam,$fnamnew);
echo "OK... Submitting to DB: ";
passthru("dmnctl version $fnamnew $versionraw 1 1");
echo "OK\n";
chdir($curdir);
delTree($tmpdir);
xecho("Starting testnet nodes with re-index... ");
unlink("/home/dash-ninja/cache/dashninja_cmd_getnodes_1");
passthru(DMN_DIR."/dmnctl start testnet masternode reindex");
passthru(DMN_DIR."/dmnctl start testnet p2pool reindex");
echo "OK\n";
}
?>