31 Opensource FIX

This commit is contained in:
2025-11-24 22:00:00 -03:00
parent 4935d4abff
commit 1dd676c628
2 changed files with 13 additions and 16 deletions

View File

@@ -9,19 +9,16 @@ function installpostgre()
$db_user = 'dragoncore30'; // default user $db_user = 'dragoncore30'; // default user
$db_name = 'dragoncore'; // default db name $db_name = 'dragoncore'; // default db name
// If config already exists, load existing password (and user if needed) // If config already exists, load existing password (and user/db if needed)
if (file_exists($configPath)) { if (file_exists($configPath)) {
include $configPath; // defines $db_pass, $db_user, $db_name, etc. include $configPath; // defines $db_pass, $db_user, $db_name, etc.
if (isset($db_pass)) { if (isset($db_pass)) {
$password = $db_pass; $password = $db_pass;
} }
if (isset($db_user)) { // if you ever want to override db_user/db_name from config, you can:
$db_user = $db_user; // if (isset($db_user)) $db_user = $db_user;
} // if (isset($db_name)) $db_name = $db_name;
if (isset($db_name)) {
$db_name = $db_name;
}
} }
// If no password loaded from config, generate a new one // If no password loaded from config, generate a new one
@@ -36,20 +33,20 @@ function installpostgre()
echo 'sudo apt update' . "\n"; echo 'sudo apt update' . "\n";
echo 'sudo apt install postgresql postgresql-contrib -y' . "\n"; echo 'sudo apt install postgresql postgresql-contrib -y' . "\n";
#$pgVersion = exec('pg_config --version | awk \'{print $NF}\' | cut -d\'.\' -f1-2');
#echo 'sudo cp /etc/postgresql/' . $pgVersion . '/main/pg_hba.conf /etc/postgresql/' . $pgVersion . '/main/pg_hba.conf.bak' . "\n";
#echo 'sudo sh -c "echo \'host all all 127.0.0.1/32 md5\' > /etc/postgresql/' . $pgVersion . '/main/pg_hba.conf"' . "\n";
echo 'sudo systemctl restart postgresql' . "\n"; echo 'sudo systemctl restart postgresql' . "\n";
// DB + user + basic grants
echo 'sudo -u postgres psql -c "CREATE DATABASE ' . $db_name . ';"' . "\n"; echo 'sudo -u postgres psql -c "CREATE DATABASE ' . $db_name . ';"' . "\n";
echo 'sudo -u postgres psql -c "CREATE USER ' . $db_user . ' WITH PASSWORD \'' . $password . '\';"' . "\n"; echo 'sudo -u postgres psql -c "CREATE USER ' . $db_user . ' WITH PASSWORD \'' . $password . '\';"' . "\n";
echo 'sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ' . $db_name . ' TO ' . $db_user . ';"' . "\n"; echo 'sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ' . $db_name . ' TO ' . $db_user . ';"' . "\n";
echo 'sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA public TO ' . $db_user . ';"' . "\n"; echo 'sudo -u postgres psql -d ' . $db_name . ' -c "GRANT USAGE, CREATE ON SCHEMA public TO ' . $db_user . ';"' . "\n";
// *** Change owner of all tables in public to $db_user *** // OPTIONAL: make dragoncore2 the owner of everything that was owned by dragoncore in this DB
echo "sudo -u postgres psql -d {$db_name} -c 'DO \$\$ DECLARE r RECORD; BEGIN FOR r IN SELECT tablename FROM pg_tables WHERE schemaname = ''public'' LOOP EXECUTE ''ALTER TABLE public.'' || quote_ident(r.tablename) || '' OWNER TO {$db_user}''; END LOOP; END \$\$;'" . "\n"; echo 'sudo -u postgres psql -d ' . $db_name . ' -c "REASSIGN OWNED BY dragoncore TO ' . $db_user . ';"' . "\n";
// *** Change owner of all sequences in public to $db_user *** // Also give full privileges on all existing tables/sequences (nice to have)
echo "sudo -u postgres psql -d {$db_name} -c 'DO \$\$ DECLARE r RECORD; BEGIN FOR r IN SELECT sequencename FROM pg_sequences WHERE schemaname = ''public'' LOOP EXECUTE ''ALTER SEQUENCE public.'' || quote_ident(r.sequencename) || '' OWNER TO {$db_user}''; END LOOP; END \$\$;'" . "\n"; echo 'sudo -u postgres psql -d ' . $db_name . ' -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ' . $db_user . ';"' . "\n";
echo 'sudo -u postgres psql -d ' . $db_name . ' -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO ' . $db_user . ';"' . "\n";
echo 'sudo systemctl restart postgresql' . "\n"; echo 'sudo systemctl restart postgresql' . "\n";

View File

@@ -1 +1 @@
30 Year Of the Tubular Dragon 31 Year Of the Tubular Dragon