36 lines
807 B
Python
Executable File
36 lines
807 B
Python
Executable File
#!/usr/bin/python3
|
|
#
|
|
# Script to translate mappings between a list to hba and preseed databases
|
|
# caskd (https://redxen.eu)
|
|
# CC0
|
|
#
|
|
|
|
import sys
|
|
|
|
table = []
|
|
|
|
for elem in sys.argv[1:]:
|
|
table.append(elem.split('/'))
|
|
|
|
dbs = set()
|
|
users = set()
|
|
|
|
for val in table:
|
|
dbs.add(val[0])
|
|
users.add(val[1])
|
|
|
|
with open("init.sql", 'x') as w:
|
|
for db in dbs:
|
|
w.write("CREATE DATABASE " + db + ";\n")
|
|
|
|
for user in users:
|
|
w.write("CREATE USER " + user + " LOGIN;\n")
|
|
|
|
for combo in table:
|
|
w.write("GRANT ALL PRIVILEGES ON DATABASE " + combo[0] + " TO " + combo[1] + ";\n")
|
|
|
|
with open("pg_hba.conf", 'x') as w:
|
|
w.write("local\tall\tpostgres\ttrust\n")
|
|
for combo in table:
|
|
w.write("hostssl\t" + combo[0] + "\t" + combo[1] + "\tall\tcert\tclientcert=verify-full\n")
|