This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
53 lines (48 loc) · 2.02 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
import subprocess
import os
import getpass
import sys
import json
# Postgresql needs to be install
# libpq-dev and python-dev needs to be installed for psycopg2
if not os.path.exists('config.json'):
print "First a config file needs to be created......"
userName = raw_input('Please enter your user name (pref your OS username): ')
userPass = getpass.getpass('Please enter your password for the Postgresql database (won\'t echo)');
with open('config.json', 'w') as configFile:
configText = """
{
"db": {
"host": "127.0.0.1",
"dbname": "logs_stats",
"user": "%s",
"password": "%s"
},
"vm_config" : {
"shared_folder": [
{"name": "logs_stats", "path": "/home/%s/logviewer", "host_path" : "../logs_stats"}
]
}
}
""" % (userName, userPass, userName)
configFile.write(configText)
confirm = raw_input("Are you running this script from the host machine? yes/no: ")
if (confirm == "yes"):
print "Run again from guest"
sys.exit();
# open the config file
with open('config.json', 'r') as configFile:
data = json.loads(configFile.read());
userName = data['db']['user']
userPass = data['db']['password']
subprocess.call(['apt-get', 'install', '-y', 'postgresql', 'libpq-dev', 'python-dev', 'python-pip'])
subprocess.call(['pip', 'install', 'psycopg2'])
os.system('echo "CREATE ROLE %s LOGIN ENCRYPTED PASSWORD \'%s\';" | sudo -u postgres psql' % (userName, userPass))
os.system('echo "CREATE DATABASE logs_stats OWNER %s;" | sudo -u postgres psql' % userName)
os.system('sudo -u postgres psql logs_stats < logs_stats.sql')
os.system('echo "ALTER TABLE messages OWNER TO %s;" | sudo -u postgres psql logs_stats' % userName)
os.system('echo "ALTER TABLE messages_id_seq OWNER TO %s;" | sudo -u postgres psql logs_stats' % userName)
os.system('echo "ALTER TYPE action OWNER TO %s;" | sudo -u postgres psql logs_stats' % userName)
os.system('echo "ALTER TABLE users OWNER TO %s;" | sudo -u postgres psql logs_stats' % userName)
os.system('echo "ALTER TABLE users_id_seq OWNER TO %s;" | sudo -u postgres psql logs_stats' % userName)