summaryrefslogtreecommitdiffstats
path: root/bin/install.php
blob: a312b63f2b8cc11fa7092c127f50ec45e8b2c1b3 (plain)
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
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2014-08-14 
 */

try {
    require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoLoader.php';

    $application = new Application_Cli();
    $isInstalled = true;

    try {
        $verifyInstallation = $application->getVerifyInstallationCommand();
        $verifyInstallation->verify();
        $verifyInstallation->execute();
    } catch (Exception $exception) {
        $isInstalled = false;
    }

    if ($isInstalled) {
        throw new Exception(
            'already installed'
        );
    }

    $command = $application->getInstallCommand();
    try {
        $command->verify();
    } catch (Exception $exception) {
        throw new Exception(implode("\n", $command->getUsage()));
    }
    $command->execute();

    $command->getOutput()->addLine();
    $command->getOutput()->addLine('please execute install.php and remove the file afterwards');
    $command->getOutput()->addLine();
    $command->getOutput()->addLine('done');

    foreach ($command->getOutput()->toArray() as $line) {
        echo $line . PHP_EOL;
    }
} catch (Exception $exception) {
    echo 'error occurred' . PHP_EOL;
    echo '----------------' . PHP_EOL;
    echo 'Usage:' . PHP_EOL . basename(__FILE__) . ' ' . $exception->getMessage() . PHP_EOL;
    exit(1);
}