fix: install script migration
migrate install.sh script to install.php to make it a little easier to manage
This commit is contained in:
76
install.php
Executable file
76
install.php
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/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`;
|
||||
|
||||
22
install.sh
22
install.sh
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -f /var/www/html/.env ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "APP_ENV=prod" > .env
|
||||
echo "APP_DEBUG=0" >> .env
|
||||
|
||||
LENGTH=32
|
||||
|
||||
SECRET_KEY=$(openssl rand -base64 $LENGTH | tr -d '=' | tr -d '+' | tr -d '/' | tr -d ' ')
|
||||
TRIMMED_KEY=$(cut -c1-32 <<< $SECRET_KEY)
|
||||
echo "APP_SECRET=$TRIMMED_KEY" >> .env
|
||||
echo "DATABASE_URL=\"sqlite:////data/data.db\"" >> .env
|
||||
echo "MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0" >> .env
|
||||
|
||||
COMPOSER_ALLOW_SUPERUSER=1 composer update
|
||||
symfony console asset-map:compile
|
||||
symfony console doctrine:migrations:migrate --no-interaction
|
||||
|
||||
chown -R www-data:www-data /data
|
||||
Reference in New Issue
Block a user