aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/install
blob: 61ffcb658ee97ff7bac689e5c7c24c5682d77d87 (plain) (blame)
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
#!/usr/bin/php
<?php
require_once __DIR__. '/../vendor/autoload.php';

use Symfony\Component\Yaml\Yaml;

$parameters = Yaml::parse(file_get_contents('app/config/parameters.yml'));

echo 'Okay, you want to install wallabag, let\'s go!';
echo "\r\n";

function executeQuery($handle, $sql, $params) {
    try
    {
        $query = $handle->prepare($sql);
        $query->execute($params);
        return $query->fetchAll();
    }
    catch (Exception $e)
    {
        return false;
    }
}

$configFile      = 'app/config/config.inc.php';
$dbFile          = 'app/db/poche.sqlite';
$username        = 'wallabag';
$password        = 'wallabag';
$salt            = $parameters['parameters']['secret'];
$defaultLanguage = 'en_EN.UTF8';

if (!copy('app/config/config.inc.default.php', $configFile)) {
    die('Installation aborted, impossible to create ' . $configFile . ' file. Maybe you don\'t have write access to create it.');
}

$content = file_get_contents($configFile);
$content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content);
file_put_contents($configFile, $content);

if (!copy('bin/poche.sqlite', $dbFile)) {
    die('Impossible to create ' . $dbFile . ' file.');
}

chmod($dbFile, 0777);

$dbPath = 'sqlite:' . realpath('') . '/' . $dbFile;

$handle = new PDO($dbPath);

$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$saltedPassword = sha1($password . $username . $salt);

$sql    = "INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, '')";
$params = array($username, $saltedPassword, $username);
$query  = executeQuery($handle, $sql, $params);

$idUser = (int)$handle->lastInsertId('users_id_seq');

$sql    = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
$params = array($idUser, 'pager', '10');
$query  = executeQuery($handle, $sql, $params);

$sql    = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
$params = array($idUser, 'language', $defaultLanguage);
$query  = executeQuery($handle, $sql, $params);

echo 'wallabag is now installed';
echo "\r\n";
echo 'Just execute `php app/console server:run` for using wallabag:';
echo "\r\n";
echo 'http://localhost:8000';