parent
a97df81a9e
commit
60cd53895d
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CloudreveInstaller;
|
||||||
|
|
||||||
|
use Composer\Script\Event;
|
||||||
|
|
||||||
|
class Installer{
|
||||||
|
|
||||||
|
public static function startInstall(Event $event){
|
||||||
|
$version = json_decode(file_get_contents("application/version.json"),true)["version"];
|
||||||
|
$ioContext = $event->getIO();
|
||||||
|
$welcomMsg = "
|
||||||
|
___ _ _
|
||||||
|
/ __\ | ___ _ _ __| |_ __ _____ _____
|
||||||
|
/ / | |/ _ \| | | |/ _` | '__/ _ \ \ / / _ \
|
||||||
|
/ /___| | (_) | |_| | (_| | | | __/\ V / __/
|
||||||
|
\____/|_|\___/ \__,_|\__,_|_| \___| \_/ \___|
|
||||||
|
|
||||||
|
Ver $version
|
||||||
|
================================================
|
||||||
|
";
|
||||||
|
$ioContext->write($welcomMsg);
|
||||||
|
$sqlInfo = self::getSqlInformation($event);
|
||||||
|
$ioContext->write("");
|
||||||
|
$siteUrl=$ioContext->ask("The full-url to access to your Cloudreve (e.g. https://pan.aoaoao.me/ , 'http' must be included in the front and '/' must be included at the end):");
|
||||||
|
$ioContext->write("");
|
||||||
|
if(!file_exists('mysql.sql')){
|
||||||
|
$ioContext->writeError("[Error] The file mysql.sql not exist.\nInstaller will exit.To retry, run 'composer install'");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$sqlSource = file_get_contents('mysql.sql');
|
||||||
|
$sqlSource = str_replace("https://cloudreve.org/", $siteUrl, $sqlSource);
|
||||||
|
$mysqli = @new \mysqli($sqlInfo["hostname"], $sqlInfo["username"], $sqlInfo["password"], $sqlInfo["database"], $sqlInfo["hostport"]);
|
||||||
|
$ioContext->write("=======================");
|
||||||
|
$ioContext->write("Starting import sql file...");
|
||||||
|
if ($mysqli->multi_query($sqlSource)) {
|
||||||
|
$ioContext->write("Writing complete.");
|
||||||
|
$ioContext->write("Writing database.php...");
|
||||||
|
if(file_exists('application/database.php')){
|
||||||
|
$ioContext->writeError("[Error] The file database.php already exist.\nInstaller will exit.To retry, run 'composer install'");
|
||||||
|
$ioContext->write("=======================");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
self::writrConfig($event,$sqlInfo);
|
||||||
|
$ioContext->write("=======================");
|
||||||
|
}else{
|
||||||
|
$ioContext->writeError("[Error] Writing failed.Installer will exit. To retry, run 'composer install'");
|
||||||
|
$ioContext->write("=======================");
|
||||||
|
}
|
||||||
|
$ioContext->write("");
|
||||||
|
$ioContext->write("Congratulations! Cloudreve has benn install successfully.");
|
||||||
|
$ioContext->write("");
|
||||||
|
$ioContext->write("Here's some informatioin about yor Cloudreve:");
|
||||||
|
$ioContext->write("Homepage: $siteUrl");
|
||||||
|
$ioContext->write("Admin Panel: ".$siteUrl."Admin");
|
||||||
|
$ioContext->write("Default username: admin@cloudreve.org");
|
||||||
|
$ioContext->write("Default password: admin");
|
||||||
|
$ioContext->write("");
|
||||||
|
$ioContext->write("=======================");
|
||||||
|
$ioContext->write("IMPORTANT! You may still have to configure the URL Rewrite to set everthing to work.");
|
||||||
|
$ioContext->write("Refer to the install manual for more informatioin.");
|
||||||
|
$ioContext->write("=======================");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function writrConfig(Event $event,$sqlInfo){
|
||||||
|
$ioContext = $event->getIO();
|
||||||
|
try {
|
||||||
|
$fileContent = file_get_contents("CloudreveInstaller/database_sample.php");
|
||||||
|
$replacement = array(
|
||||||
|
'{hostname}' => $sqlInfo["hostname"],
|
||||||
|
'{database}' => $sqlInfo["database"],
|
||||||
|
'{username}' => $sqlInfo["username"],
|
||||||
|
'{password}' => $sqlInfo["password"],
|
||||||
|
'{hostport}' => $sqlInfo["hostport"],
|
||||||
|
);
|
||||||
|
$fileContent = strtr($fileContent,$replacement);
|
||||||
|
file_put_contents('application/database.php',$fileContent);
|
||||||
|
}catch (Exception $e) {
|
||||||
|
$ioContext->writeError("[Error] Writing failed.Installer will exit. To retry, run 'composer install'");
|
||||||
|
}
|
||||||
|
$ioContext->write("Writing complete.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSqlInformation(Event $event){
|
||||||
|
$ioContext = $event->getIO();
|
||||||
|
$hostname=$ioContext->ask("Input the hostname of your MySQL server (Default:127.0.0.1):","127.0.0.1");
|
||||||
|
$database=$ioContext->ask("The database name:","127.0.0.1");
|
||||||
|
$username=$ioContext->ask("The username of your MySQL server (Default:root):","root");
|
||||||
|
$password=$ioContext->askAndHideAnswer("The password of your MySQL server:");
|
||||||
|
$hostport=$ioContext->ask("The hostport of your MySQL server (Default:3306):","3306");
|
||||||
|
$mysqli = @new \mysqli($hostname, $username, $password, $database, $hostport);
|
||||||
|
if ($mysqli->connect_error) {
|
||||||
|
$ioContext->writeError("[Error] Cannot connect to MySQL server, Message:".$mysqli->connect_error);
|
||||||
|
$ioContext->write("");
|
||||||
|
$ioContext->write("Please confirm your connection informatioin:");
|
||||||
|
@$mysqli->close();
|
||||||
|
return self::getSqlInformation($event);
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
"hostname" => $hostname,
|
||||||
|
"database" => $database,
|
||||||
|
"username" => $username,
|
||||||
|
"password" => $password,
|
||||||
|
"hostport" => $hostport,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
return [
|
||||||
|
// 数据库类型
|
||||||
|
'type' => 'mysql',
|
||||||
|
// 服务器地址
|
||||||
|
'hostname' => '{hostname}',
|
||||||
|
// 数据库名
|
||||||
|
'database' => '{database}',
|
||||||
|
// 用户名
|
||||||
|
'username' => '{username}',
|
||||||
|
// 密码
|
||||||
|
'password' => '{password}',
|
||||||
|
// 端口
|
||||||
|
'hostport' => '{hostport}',
|
||||||
|
// 连接dsn
|
||||||
|
'dsn' => '',
|
||||||
|
// 数据库连接参数
|
||||||
|
'params' => [],
|
||||||
|
// 数据库编码默认采用utf8
|
||||||
|
'charset' => 'utf8',
|
||||||
|
// 数据库表前缀
|
||||||
|
'prefix' => 'sd_',
|
||||||
|
// 数据库调试模式
|
||||||
|
'debug' => true,
|
||||||
|
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
|
||||||
|
'deploy' => 0,
|
||||||
|
// 数据库读写是否分离 主从式有效
|
||||||
|
'rw_separate' => false,
|
||||||
|
// 读写分离后 主服务器数量
|
||||||
|
'master_num' => 1,
|
||||||
|
// 指定从服务器序号
|
||||||
|
'slave_no' => '',
|
||||||
|
// 是否严格检查字段是否存在
|
||||||
|
'fields_strict' => true,
|
||||||
|
// 数据集返回类型
|
||||||
|
'resultset_type' => 'array',
|
||||||
|
// 自动写入时间戳字段
|
||||||
|
'auto_timestamp' => false,
|
||||||
|
// 时间字段取出后的默认时间格式
|
||||||
|
'datetime_format' => 'Y-m-d H:i:s',
|
||||||
|
// 是否需要进行SQL性能分析
|
||||||
|
'sql_explain' => false,
|
||||||
|
];
|
Loading…
Reference in new issue