This commit is contained in:
Saeed Vaziry 2023-07-09 22:32:22 +02:00
parent c1056f11ec
commit 71c918f435
3 changed files with 27 additions and 36 deletions

View File

@ -1,28 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CreateDatabaseCommand extends Command
{
protected $signature = 'database:create';
protected $description = 'Create the database if it does not exist.';
public function handle(): void
{
$schemaName = config("database.connections.mysql.database");
config(["database.connections.mysql.database" => null]);
$query = "CREATE DATABASE IF NOT EXISTS $schemaName";
DB::statement($query);
config(["database.connections.mysql.database" => $schemaName]);
$this->info(sprintf("Database `%s` created successfully.", $schemaName));
}
}

View File

@ -8,19 +8,18 @@
class CreateUserCommand extends Command class CreateUserCommand extends Command
{ {
protected $signature = 'user:create {name} {email}'; protected $signature = 'user:create {name} {email} {password}';
protected $description = 'Create a new user'; protected $description = 'Create a new user';
public function handle(): void public function handle(): void
{ {
$password = Str::random(20);
User::create([ User::create([
'name' => $this->argument('name'), 'name' => $this->argument('name'),
'email' => $this->argument('email'), 'email' => $this->argument('email'),
'password' => bcrypt($password), 'password' => bcrypt($this->argument('password')),
]); ]);
$this->info("User created with password: {$password}"); $this->info("User created with password");
} }
} }

View File

@ -10,6 +10,16 @@ if [[ -z "${V_DOMAIN}" ]]; then
exit 1 exit 1
fi fi
if [[ -z "${V_ADMIN_EMAIL}" ]]; then
echo "Error: V_ADMIN_EMAIL environment variable is not set."
exit 1
fi
if [[ -z "${V_ADMIN_PASSWORD}" ]]; then
echo "Error: V_ADMIN_PASSWORD environment variable is not set."
exit 1
fi
apt remove needrestart -y apt remove needrestart -y
useradd -p $(openssl passwd -1 ${V_PASSWORD}) ${V_USERNAME} useradd -p $(openssl passwd -1 ${V_PASSWORD}) ${V_USERNAME}
@ -154,12 +164,19 @@ find /home/${V_USERNAME}/${V_DOMAIN} -type f -exec chmod 644 {} \;
cd /home/${V_USERNAME}/${V_DOMAIN} && git config core.fileMode false cd /home/${V_USERNAME}/${V_DOMAIN} && git config core.fileMode false
cd /home/${V_USERNAME}/${V_DOMAIN} && composer install --no-dev cd /home/${V_USERNAME}/${V_DOMAIN} && composer install --no-dev
cp .env.prod .env cp .env.prod .env
sed -i '' "s/{AP_URL}/http://${V_DOMAIN}/g" /home/${V_USERNAME}/${V_DOMAIN}/.env sed -i "s|APP_URL=.*|APP_URL=http://${V_DOMAIN}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
sed -i '' "s/{DB_NAME}/${V_DB_NAME}/g" /home/${V_USERNAME}/${V_DOMAIN}/.env sed -i "s|APP_URL=.*|DB_NAME=${V_DB_NAME}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
sed -i '' "s/{DB_USER}/${V_DB_USER}/g" /home/${V_USERNAME}/${V_DOMAIN}/.env sed -i "s|APP_URL=.*|DB_USER=${V_DB_USER}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
sed -i '' "s/{DB_PASS}/${V_DB_PASS}/g" /home/${V_USERNAME}/${V_DOMAIN}/.env sed -i "s|APP_URL=.*|DB_PASS=${V_DB_PASS}|" /home/${V_USERNAME}/${V_DOMAIN}/.env
php artisan key:generate php artisan key:generate
php artisan storage:link php artisan storage:link
php artisan migrate --force
php artisan user:create Vito ${V_ADMIN_EMAIL} ${V_ADMIN_PASSWORD}
openssl genpkey -algorithm RSA -out /home/${V_USERNAME}/${V_DOMAIN}/storage/ssh-private.pem
chmod 600 /home/${V_USERNAME}/${V_DOMAIN}/storage/ssh-private.pem
ssh-keygen -y -f /home/${V_USERNAME}/${V_DOMAIN}/storage/ssh-private.pem > /home/${V_USERNAME}/${V_DOMAIN}/storage/ssh-public.key
chown -R ${V_USERNAME}:${V_USERNAME} /home/${V_USERNAME}/${V_DOMAIN}/storage/ssh-private.pem
chown -R ${V_USERNAME}:${V_USERNAME} /home/${V_USERNAME}/${V_DOMAIN}/storage/ssh-public.key
# setup supervisor # setup supervisor
export V_WORKER_CONFIG=" export V_WORKER_CONFIG="
@ -191,3 +208,6 @@ echo "✅ SSH Password: ${V_PASSWORD}"
echo "✅ DB Name: ${V_DB_NAME}" echo "✅ DB Name: ${V_DB_NAME}"
echo "✅ DB Username: ${V_DB_USER}" echo "✅ DB Username: ${V_DB_USER}"
echo "✅ DB Password: ${V_DB_PASS}" echo "✅ DB Password: ${V_DB_PASS}"
echo "✅ Admin Email: ${V_ADMIN_EMAIL}"
echo "✅ Admin Password: ${V_ADMIN_PASSWORD}"
echo "✅ URL: http://${V_DOMAIN}"