forked from F4stZ4p/HLavalink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
138 lines (94 loc) · 3.15 KB
/
bootstrap.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
"""
Lavalink on Heroku bootstrap script
Credit to diniboy for sed script
"""
from os import system, environ
class LavalinkBootstrap:
"""
Class we're using to get Lavalink working on Heroku
"""
def __init__(self):
"""
Doing important stuff here
"""
self.download_command = "curl -s https://api.github.com/repos/Frederikam/Lavalink/releases/latest | grep browser_download_url | cut -d '\"' -f 4 | wget -qi -"
self.replace_port_command = 'sed -i "s|DYNAMICPORT|$PORT|" application.yml'
self.replace_password_command = 'sed -i "s|DYNAMICPASSWORD|$PASSWORD|" application.yml'
self.replace_password_command_no_password = 'sed -i "s|DYNAMICPASSWORD|youshallnotpass|" application.yml'
self._additional_options = environ.get(
"ADDITIONAL_JAVA_OPTIONS"
) # Heroku provides basic Java configuration based on dyno size, no need in limiting memory
self.run_command = f"java -jar Lavalink.jar {self._additional_options}" # User-provided config, will override heroku's
def replace_password_and_port(self):
"""
Replacing password and port in application.yml
"""
print(
"[INFO] Replacing port..."
)
try:
system(
self.replace_port_command
)
if not environ.get("PASSWORD"):
print(
"""
[WARNING] You have not specified your Lavalink password in config vars. To do this, go to settings
and set the PASSWORD environment variable
"""
)
return system(
self.replace_password_command_no_password
)
system(
self.replace_password_command
)
except BaseException as exc:
print(
f"[ERROR] Failed to replace port/password. Info: {exc}"
)
else:
print(
"[INFO] Done. Config is ready now"
)
def download(self):
"""
Downloads latest release of Lavalink
"""
print(
"[INFO] Downloading latest release of Lavalink..."
)
try:
system(
self.download_command
)
except BaseException as exc:
print(
f"[ERROR] Lavalink download failed. Info: {exc}"
)
else:
print(
"[INFO] Lavalink download OK"
)
def run(self):
"""
Runs Lavalink instance
"""
self.download()
self.replace_password_and_port()
print(
"[INFO] Starting Lavalink..."
)
try:
system(
self.run_command
)
except BaseException as exc:
print(
f"[ERROR] Failed to start Lavalink. Info: {exc}"
)
if __name__ == "__main__":
"""
Starts our instance
"""
LavalinkBootstrap().run()