安装引导脚本
This commit is contained in:
parent
a97df81a9e
commit
60cd53895d
3 changed files with 190 additions and 19 deletions
109
CloudreveInstaller/Installer.php
Normal file
109
CloudreveInstaller/Installer.php
Normal file
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
53
CloudreveInstaller/database_sample.php
Normal file
53
CloudreveInstaller/database_sample.php
Normal file
|
@ -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,
|
||||
];
|
|
@ -6,33 +6,42 @@
|
|||
"type": "project",
|
||||
"license": "GPL-3.0-only",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aaron",
|
||||
"email": "abslant@foxmail.com",
|
||||
"homepage": "https://aoaoao.me",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Qnner",
|
||||
"email": "admin@qnner.com",
|
||||
"homepage": "http://me.qnner.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "dune",
|
||||
"email": "rainaysann@gmail.com",
|
||||
"homepage": "https://github.com/rainays",
|
||||
"role": "Developer"
|
||||
}
|
||||
{
|
||||
"name": "Aaron",
|
||||
"email": "abslant@foxmail.com",
|
||||
"homepage": "https://aoaoao.me",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Qnner",
|
||||
"email": "admin@qnner.com",
|
||||
"homepage": "http://me.qnner.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "dune",
|
||||
"email": "rainaysann@gmail.com",
|
||||
"homepage": "https://github.com/rainays",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"ext-curl":"*",
|
||||
"ext-fileinfo":"*",
|
||||
"ext-gd":"*",
|
||||
"topthink/think-captcha":"1.*",
|
||||
"endroid/qrcode": "1.*",
|
||||
"aliyuncs/oss-sdk-php": "~2.0",
|
||||
"sabre/dav":"~3.2.0",
|
||||
"upyun/sdk": "^3.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"CloudreveInstaller\\Installer" : ""
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-install-cmd": [
|
||||
"CloudreveInstaller\\Installer::startInstall"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue