Skip to content

Commit

Permalink
修改安装方式
Browse files Browse the repository at this point in the history
Former-commit-id: a4e86c4
  • Loading branch information
shi-yang committed Jun 4, 2018
1 parent afd7190 commit 661696e
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 281 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nbproject
Thumbs.db

# composer vendor dir
/vendor
# /vendor

# composer itself is not needed
composer.phar
Expand Down
39 changes: 7 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@
安装过程
------------
1. 下载 `jnoj`
提供两种方法下载:
1. 运行命令:
~~~
git clone https://github.com/shi-yang/jnoj.git
~~~
2. 到 [https://github.com/shi-yang/jnoj/releases](https://github.com/shi-yang/jnoj/releases) 选择最新版本下载。
运行命令:
~~~
git clone https://github.com/shi-yang/jnoj.git
~~~
2. 配置 Web 端
1. 配置数据库信息
Expand All @@ -80,32 +78,11 @@
```
**注意:** Web 程序不会为你创建数据库,需要你自己手动创建该数据库。
2. 安装 Web 相关依赖
这里提供两种安装方法。一种是用 `composer` 来安装,另一种是通过压缩包来安装。
1. 使用 `composer` 来安装。这种方法因国内网络问题,安装时间漫长或无法安装。需要先下载安装 `composer`。然后执行
```bash
php composer.phar update
```
2. 通过安装包来安装。到 [https://github.com/shi-yang/jnoj/releases](https://github.com/shi-yang/jnoj/releases)
下载最新版的 `vendor.zip` 后,放在 `jnoj` 目录下,直接解压即可。然后依次运行下列命令修改目录权限:
```bash
chmod 777 runtime
chmod 777 web/assets
chmod 777 web/uploads
chmod 777 polygon/data
```
3. 导入数据库信息
运行 `./yii migrate`。根据提示输入管理员账号密码邮箱。
4. 启动 Socket 功能 (启动该功能是为了在发布公告时给前台用户弹窗提醒)
2. 执行安装命令
进入 jnoj 目录,在命令行运行 `./yii install` 来安装。安装过程会自动导入所需的 SQL 数据,并且需要你根据提示输入管理员的账号密码。
运行 `php socket.php start -d`
做好以上步骤后便使用 Web 端:
做好以上步骤后便可以使用 Web 端:
~~~
http://localhost/jnoj/web/
Expand All @@ -124,8 +101,6 @@
2. 将控制台切换到 `polygon` 目录(即运行 `cd polygon`命令),然后运行 `make` 命令
3. 运行 `sudo ./polygon` 命令
5. Web 端默认是开发者模式,如需部署到生产环境,请注释 `web/index.php` 文件的头两行代码
开发者支持
---------
Issues: [https://github.com/shi-yang/jnoj/issues](https://github.com/shi-yang/jnoj/issues)
Expand Down
30 changes: 0 additions & 30 deletions commands/HelloController.php

This file was deleted.

74 changes: 74 additions & 0 deletions commands/InstallController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace app\commands;

use yii\console\Controller;

class InstallController extends Controller
{
public function actionIndex()
{
echo "================================================\n";
echo " Jiangnan Online Judge Initialization Tool v1.0\n";
echo "================================================\n\n";
$root = str_replace('\\', '/', __DIR__ . '/..');
$env = [
'setWritable' => [
'runtime',
'web/assets',
'web/uploads',
'polygon/data',
'judge/data'
],
'setCookieValidationKey' => [
'config/web.php',
]
];
$callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable'];
foreach ($callbacks as $callback) {
if (!empty($env[$callback])) {
$this->$callback($root, $env[$callback]);
}
}

echo "\n================================================";
echo "\nRun: ./yii migrate";
echo "\n================================================\n";
passthru("./yii migrate");

echo "\n================================================";
echo "\nRun: php socket.php start -d";
echo "\n================================================\n";
passthru("php socket.php start -d");
echo "\nInitialization completed.\n\n";
}

private function setWritable($root, $paths)
{
foreach ($paths as $writable) {
echo " chmod 0777 $writable\n";
@chmod("$root/$writable", 0777);
}
}

private function setExecutable($root, $paths)
{
foreach ($paths as $executable) {
echo " chmod 0755 $executable\n";
@chmod("$root/$executable", 0755);
}
}

private function setCookieValidationKey($root, $paths)
{
foreach ($paths as $file) {
echo " generate cookie validation key in $file\n";
$file = $root . '/' . $file;
$length = 32;
$bytes = openssl_random_pseudo_bytes($length);
$key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
$content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($file));
file_put_contents($file, $content);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jnoj",
"description": "Jiangnan Online Judge",
"keywords": [
"online judge",
"online judge"
],
"homepage": "http://www.github.com/shi-yang/jnoj",
"type": "project",
Expand Down
Loading

0 comments on commit 661696e

Please sign in to comment.