forked from LoneStryder/myimouto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
executable file
·117 lines (98 loc) · 2.44 KB
/
install.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
use Zend\Console\ColorInterface as Color;
/**
* Boot Rails
*/
require __DIR__ . '/config/boot.php';
/**
* Create console and migrator
*/
$c = new Rails\Console\Console();
$migrator = new Rails\ActiveRecord\Migration\Migrator();
/**
* Show splash
*/
$txColor = Color::LIGHT_WHITE;
$bgColor = Color::GREEN;
$c->put();
$c->put("====================", $txColor, $bgColor);
$c->put(" MyImouto installer ", $txColor, $bgColor);
$c->put("====================", $txColor, $bgColor);
$c->put();
/**
* Get data for admin account
*/
$c->put("Admin account", null, Color::BLUE);
$c->put("Please enter a name and password for the admin account.");
$c->write("Note: ", Color::RED);
$c->put("the password will be shown.");
list($adminName, $adminPass) = getAdminData($c);
/**
* Database
*/
$c->put("Database", null, Color::BLUE);
# Install database
$c->write("Creating tables......");
$migrator->loadSchema();
$c->put('done');
# Run migrations
$c->write("Running migrations...");
$migrator->run();
$c->put('done');
# Run seeds
$c->write("Seeding..............");
$migrator->runSeeds();
$c->put('done');
# Create user in database
$c->write("Creating admin account...");
Rails\ActiveRecord\ActiveRecord::connection()->executeSql(
'INSERT INTO users (created_at, name, password_hash, level, show_advanced_editing) VALUES (?, ?, ?, ?, ?)',
date('Y-m-d H:i:s'), $adminName, User::sha1($adminPass), 50, 1
);
Rails\ActiveRecord\ActiveRecord::connection()->executeSql(
'INSERT INTO user_blacklisted_tags VALUES (?, ?)',
1, implode("\r\n", CONFIG()->default_blacklists)
);
$c->put("done");
/**
* Create /public/data folders
*/
$c->put("\n");
$c->write("Creating /public/data folders...");
$dataPath = Rails::publicPath() . '/data';
$dirs = [
'avatars',
'image',
'import',
'jpeg',
'preview',
'sample'
];
if (!is_dir($dataPath)) {
mkdir($dataPath);
}
foreach ($dirs as $dir) {
$path = $dataPath . '/' . $dir;
if (!is_dir($path)) {
mkdir($path);
}
}
/**
* Finish
*/
$c->put();
$c->put("Installation finished.", Color::GREEN);
$c->put("You may delete this install.php file.");
$c->put();
function nullErrorHandler() {}
function getAdminData($c)
{
$adminName = $c->input("Account name: ");
$adminPass = $c->input("Password: ");
if ($c->confirm("Is the information correct? (y/n) ")) {
return [$adminName, $adminPass];
} else {
$c->put();
return getAdminData($c);
}
}