31 lines
882 B
PHP
31 lines
882 B
PHP
|
<?php
|
||
|
|
||
|
include_once('./public/config.php');
|
||
|
|
||
|
// Create the database if it doesn't already exist
|
||
|
if (!file_exists(dirname(HOSTAS_DATABASE_PATH))) {
|
||
|
mkdir(
|
||
|
directory: dirname(HOSTAS_DATABASE_PATH),
|
||
|
recursive: true
|
||
|
);
|
||
|
|
||
|
// The SQLite driver can't write to a database unless its directory is
|
||
|
// writeable.
|
||
|
//
|
||
|
// See <https://stackoverflow.com/questions/3319112/sqlite-error-attempt-to-write-a-readonly-database-during-insert>
|
||
|
exec('chown ' . HOSTAS_UNIX_USER . ' ' . dirname(HOSTAS_DATABASE_PATH));
|
||
|
}
|
||
|
|
||
|
if (!file_exists(HOSTAS_DATABASE_PATH)) {
|
||
|
$conn = new SQLite3(HOSTAS_DATABASE_PATH);
|
||
|
echo "Creating the database..." . PHP_EOL;
|
||
|
$ddl = file_get_contents('./database.ddl');
|
||
|
$conn->exec($ddl);
|
||
|
|
||
|
// Make sure the right permissions are set
|
||
|
exec('chown ' . HOSTAS_UNIX_USER . ' ' . HOSTAS_DATABASE_PATH);
|
||
|
exec('chgrp ' . HOSTAS_UNIX_USER . ' ' . HOSTAS_DATABASE_PATH);
|
||
|
}
|
||
|
|
||
|
|