migrate install.sh script to install.php to make it a little easier to manage
77 lines
2.0 KiB
PHP
Executable File
77 lines
2.0 KiB
PHP
Executable File
#!/usr/local/bin/php
|
|
|
|
<?php
|
|
|
|
if (!file_exists('/var/www/html/.env')) {
|
|
die;
|
|
}
|
|
|
|
$cmd = getopt("", ["sqlite", "mysql", "mariadb", "pgsql"]);
|
|
|
|
$key = `openssl rand -base64 32 | tr -d '=' | tr -d '+' | tr -d '/' | tr -d ' '`;
|
|
$key = substr($key, 0, 32);
|
|
$database_url = null;
|
|
$getCreds = true;
|
|
$creds = null;
|
|
|
|
if (isset($cmd['sqlite'])) {
|
|
$database_url = "DATABASE_URL=\"sqlite:////data/data.db\"";
|
|
$getCreds = false;
|
|
} elseif (isset($cmd['mysql'])) {
|
|
$database_url = "DATABASE_URL=\"mysql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?charset=utf8&use_unicode=1\"";
|
|
} elseif (isset($cmd['mariadb'])) {
|
|
$database_url = "DATABASE_URL=\"mysql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?charset=utf8mb4\"";
|
|
} elseif (isset($cmd['pgsql'])) {
|
|
$database_url = "DATABASE_URL=\"postgresql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?sslmode=require\"";
|
|
}
|
|
|
|
if (is_null($database_url)) {
|
|
$getCreds = false;
|
|
die("When calling this make sure that you enter a database type");
|
|
}
|
|
|
|
if ($getCreds) {
|
|
$db_host = readline("DB Host: ");
|
|
$db_port = readline("DB Port: ");
|
|
$db_name = readline("DB Schema: ");
|
|
$db_user = readline("DB User: ");
|
|
|
|
print "DB Password: ";
|
|
// Disable echoing of input characters
|
|
system('stty -echo');
|
|
// Read the password from standard input
|
|
$db_password = trim(fgets(STDIN));
|
|
// Re-enable echoing of input characters
|
|
system('stty echo');
|
|
$creds = <<<CREDS
|
|
DB_HOST=$db_host
|
|
DB_PORT=$db_port
|
|
DB_NAME=$db_name
|
|
DB_USER=$db_user
|
|
DB_PASS=$db_password
|
|
|
|
CREDS;
|
|
}
|
|
|
|
$output = <<<EOF
|
|
APP_ENV=prod
|
|
APP_DEBUG=0
|
|
APP_SECRET=$key
|
|
MESSAGENER_TRANSPORT_DSN=doctrine://default?auto_setup=0
|
|
$creds$database_url
|
|
|
|
EOF;
|
|
|
|
file_put_contents('/var/www/html/.env', $output);
|
|
|
|
`COMPOSE_ALLOW_SUPERUSER=1 composer update`;
|
|
`symfony console asset-map:compile`;
|
|
|
|
if ($getCreds) {
|
|
`symfony console doctrine:database:create`;
|
|
}
|
|
|
|
`symfony console doctrine:migrations:migrate --no-interaction`;
|
|
`chown -R www-data:www-data /data`;
|
|
|