This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
149 lines (113 loc) · 5.12 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/python
import os
import sys
from pymongo import MongoClient
from bson.objectid import ObjectId
def modifyConfig(expression, value):
print('Modifying server.properties '+expression+' with value '+str(value))
os.system("sed -i 's/"+str(expression)+"/"+str(value)+"/' server.properties")
def modifyLog(expression, value):
print('Modifying log4j2.xml '+expression+' with value '+str(value))
os.system("sed -i 's/"+str(expression)+"/"+str(value)+"/' log4j2.xml")
def main():
mongoHosts = os.environ['mongo_addresses'].split(',')
mongoDB = os.environ['mongo_database']
mongoUsername = os.getenv('mongo_username', None)
mongoPassword = os.getenv('mongo_password', None)
client = MongoClient(mongoHosts)
db = client[mongoDB]
if mongoUsername is not None:
db.authenticate(mongoUsername, mongoPassword)
serverCollection = db['servers']
servertypesCollection = db['servertypes']
nodesCollection = db['nodes']
worldsCollection = db['worlds']
pluginsCollection = db['plugins']
query = {"_id": ObjectId(os.environ['server_id'])}
server = serverCollection.find_one(query)
query = {"_id": ObjectId(server['server_type_id'])}
servertype = servertypesCollection.find_one(query)
query = {"_id": ObjectId(server['node_id'])}
node = nodesCollection.find_one(query)
if servertype is None:
print('No server type found')
sys.exit(1)
worlds = []
plugins = []
if 'worlds' in servertype:
for worldInfo in servertype['worlds']:
world = worldsCollection.find_one({"_id": ObjectId(worldInfo['world_id'])})
worldVersion = None
if 'versions' in world and 'worldversion_id' in worldInfo:
for version in world['versions']:
if version['_id'] == ObjectId(worldInfo['worldversion_id']):
worldVersion = version
break
default = worldInfo['defaultWorld']
worldDict = {'world': world, 'version': worldVersion, 'default': default}
worlds.append(worldDict)
if 'plugins' in servertype:
for pluginInfo in servertype['plugins']:
plugin = pluginsCollection.find_one({"_id": ObjectId(pluginInfo['plugin_id'])})
pluginConfig = None
pluginVersion = None
if 'configs' in plugin and 'pluginconfig_id' in pluginInfo:
for config in plugin['configs']:
if config['_id'] == ObjectId(pluginInfo['pluginconfig_id']):
pluginConfig = config
break
if 'versions' in plugin and 'pluginversion_id' in pluginInfo:
for version in plugin['versions']:
if version['_id'] == ObjectId(pluginInfo['pluginversion_id']):
pluginVersion = version
break
pluginDict = {'plugin': plugin, 'version': pluginVersion, 'config': pluginConfig}
plugins.append(pluginDict)
print('Copying Main Server files')
os.system('cp -R /mnt/minestack/server/bukkit/* .')
defaultWorld = None
os.system('mkdir worlds')
for worldInfo in worlds:
world = worldInfo['world']
version = worldInfo['version']
default = worldInfo['default']
print('Copying world '+world['name'])
if version is None:
print('World '+world['name']+' has no version. Skipping')
continue
if default is True:
defaultWorld = world
os.system('mkdir worlds/'+world['directory'])
os.system('cp -R /mnt/minestack/worlds/'+world['directory']+'/versions/'+version['version']+'/* worlds/'+world['directory'])
os.system('ls -l worlds')
if defaultWorld is None:
print('No default world set')
sys.exit(1)
# modify server config for default world
modifyConfig('levelname', defaultWorld['name'])
os.system('mkdir plugins')
for pluginInfo in plugins:
plugin = pluginInfo['plugin']
version = pluginInfo['version']
config = pluginInfo['config']
print('Copying plugin '+plugin['name'])
if version is None:
print('Plugin '+plugin['name']+' has no version. Skipping')
continue
if config is not None:
os.system('mkdir plugins/'+plugin['directory'])
os.system('cp -R /mnt/minestack/plugins/'+plugin['directory']+'/configs/'+config['directory']+'/* plugins/'+plugin['directory'])
os.system('cp -R /mnt/minestack/plugins/'+plugin['directory']+'/versions/'+version['version']+'/* plugins')
os.system('ls -l plugins')
# modify server config for num of players
modifyConfig('maxplayers', servertype['players'])
# modify server config for server name
modifyConfig('servername', servertype['name']+'.'+str(server['number']))
modifyLog('SYS_HOST', node['privateAddress'])
modifyLog('SERVERTYPE', servertype['name'])
modifyLog('NUMBER', server['number'])
os.system('touch .update-lock')
os.system('ls -l')
os.system("chmod +x start.sh")
os.system("./start.sh "+str(servertype['ram']))
main()