-
Notifications
You must be signed in to change notification settings - Fork 2
/
makedb.py
114 lines (96 loc) · 3.13 KB
/
makedb.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import MySQLdb
db_host = os.environ.get(
'DB_PORT_3306_TCP_ADDR',
os.environ.get(
'MYSQL_HOST',
'db',
),
)
db_port = int(os.environ.get('MYSQL_PORT', '3306'))
db_user = os.environ.get(
'DB_ENV_MYSQL_USER',
os.environ.get(
'MYSQL_USER',
),
)
db_pass = os.environ.get(
'DB_ENV_MYSQL_PASSWORD',
os.environ.get(
'MYSQL_PASSWORD',
),
)
db_root = os.environ.get(
'DB_ENV_MYSQL_ROOT_USER',
os.environ.get(
'MYSQL_ROOT',
'root',
),
)
db_root_pass = os.environ.get(
'DB_ENV_MYSQL_ROOT_PASSWORD',
os.environ.get(
'MYSQL_ROOT_PASSWORD',
),
)
if db_root_pass is None:
print('No mysql root password provided. Not creating databases')
exit(0)
try:
conn = MySQLdb.connect(host=db_host,
port=db_port,
user=db_root,
passwd=db_root_pass)
except Exception as e:
if isinstance(e, MySQLdb.OperationalError):
print('Failed to connect to mysql: {}'.format(e.args[1]))
else:
print('Failed to connect to mysql: {}'.format(e))
exit(1)
cursor = conn.cursor()
commands = [
'''CREATE DATABASE IF NOT EXISTS `ccnet-db` character set = 'utf8';''',
'''CREATE DATABASE IF NOT EXISTS `seafile-db` character set = 'utf8';''',
'''CREATE DATABASE IF NOT EXISTS `seahub-db` character set = 'utf8';''',
'''GRANT ALL PRIVILEGES ON `ccnet-db`.* to `{user}` identified by '{passw}';''',
'''GRANT ALL PRIVILEGES ON `seafile-db`.* to `{user}`;''',
'''GRANT ALL PRIVILEGES ON `seahub-db`.* to `{user}`;''',
]
for sql in commands:
sql = sql.format(user=db_user, passw=db_pass)
try:
cursor.execute(sql)
except Exception as e:
if isinstance(e, MySQLdb.OperationalError):
print('Failed to create database: {}'.format(e.args[1]))
else:
print('Failed to create database: {}'.format(e))
exit(2)
import ssm
ssm.db_config = ssm.ExistingDBConfigurator()
ssm.db_config.mysql_host = db_host
ssm.db_config.mysql_port = db_port
ssm.db_config.seafile_mysql_user = db_user
ssm.db_config.seafile_mysql_password = db_pass
ssm.db_config.use_existing_db = True
ssm.db_config.ccnet_db_name = 'ccnet-db'
ssm.db_config.seafile_db_name = 'seafile-db'
ssm.db_config.seahub_db_name = 'seahub-db'
ssm.db_config.seahub_admin_email = os.environ.get('ADMIN_EMAIL', '[email protected]')
ssm.db_config.seahub_admin_password = os.environ.get('ADMIN_PASSWORD', 'youcannotguesit')
ssm.ccnet_config.ip_or_domain = '127.0.0.1'
ssm.ccnet_config.server_name = os.environ.get('SITE_NAME', 'seafile')
ssm.seahub_config.admin_email = os.environ.get('ADMIN_EMAIL', '[email protected]')
ssm.seahub_config.admin_email = os.environ.get('ADMIN_PASSWORD', 'youcannotguesit')
ssm.db_config.generate()
ssm.ccnet_config.generate()
ssm.seafile_config.generate()
ssm.seafdav_config.generate()
ssm.seahub_config.generate()
ssm.seahub_config.do_syncdb()
ssm.seahub_config.prepare_avatar_dir()
#ssm.db_config.create_seahub_admin()
ssm.user_manuals_handler.copy_user_manuals()
ssm.create_seafile_server_symlink()
ssm.set_file_perm()
ssm.report_success()