From c50904c49c1b8a8d033ddbf04ffd1d7df909a950 Mon Sep 17 00:00:00 2001 From: Paul Kirby Date: Mon, 20 Aug 2018 20:38:35 -0500 Subject: [PATCH] Testing out downloading and running the Daemon --- .gitignore | 4 ++++ classes/lbrypress.php | 48 ++++++++++++++++++++++++++++++++++++++++--- lbrypress.php | 2 +- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e69de29..ed74ecd 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,4 @@ +# ignore extension-less files +* +!/**/ +!*.* diff --git a/classes/lbrypress.php b/classes/lbrypress.php index 27a12da..d4d1b3b 100644 --- a/classes/lbrypress.php +++ b/classes/lbrypress.php @@ -8,20 +8,62 @@ if (! class_exists('LBRYPress')) { class LBRYPress { + // Employ Singleton pattern to preserve single instance + private static $instance = null; + + public static function get_instance() + { + if (null == self::$instance) { + self::$instance = new self; + } + + return self::$instance; + } + + // Create instances of all necessary classes private $LBRY_Admin; - public function __construct() + private function __construct() { - $this->requireDependencies(); + $this->require_dependencies(); $this->LBRY_Admin = new LBRY_Admin(); $this->LBRY_Admin->settings_init(); + + $this->download_daemon(); } - private function requireDependencies() + private function require_dependencies() { require_once(LBRY_URI . '/classes/admin/lbry_admin.php'); } + + private function download_daemon() + { + $output_filename = "lbrydaemon"; + + $host = "http://build.lbry.io/daemon/build-6788_commit-5099e19_branch-lbryum-refactor/mac/lbrynet"; + $fp = fopen(LBRY_URI . '/' . $output_filename, 'w+'); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $host); + curl_setopt($ch, CURLOPT_VERBOSE, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_AUTOREFERER, false); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_HEADER, 0); + + $result = curl_exec($ch); + curl_close($ch); + fclose($fp); + + $filepath = LBRY_URI . '/' . $output_filename; + + + `chmod +x {$filepath}`; + error_log(`{$filepath} status`); + `{$filepath} start &`; + } } } diff --git a/lbrypress.php b/lbrypress.php index 582954d..d04aa95 100644 --- a/lbrypress.php +++ b/lbrypress.php @@ -70,7 +70,7 @@ if (lbry_requirements_met()) { require_once(dirname(__FILE__) . '/classes/lbrypress.php'); if (class_exists('LBRYPress')) { - $lbryPress = new LBRYPress(); + $lbryPress = LBRYPress::get_instance(); // register_activation_hook(__FILE__, array( $lbryPress, 'activate' )); // register_deactivation_hook(__FILE__, array( $lbryPress, 'deactivate' )); }