-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLU.py
42 lines (35 loc) · 1.45 KB
/
DLU.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
import requests
import tarfile
from os import path, makedirs, remove
# from shutil import rmtree
NameOfUpdateFile = "discordUpdate.tar.gz"
DISCORD_DOWNLOAD = {
"STABLE": "https://discord.com/api/download/stable?platform=linux&format=tar.gz",
"BETA": "https://discord.com/api/download/ptb?platform=linux&format=tar.gz",
"CANARY": "https://discord.com/api/download/canary?platform=linux&format=tar.gz"
}
def downloadUpdateFile(version):
try:
ver_download = version.upper()
if (path.isfile(f'/tmp/{NameOfUpdateFile}')):
remove(f'/tmp/{NameOfUpdateFile}')
updateFile = requests.get(DISCORD_DOWNLOAD[ver_download], allow_redirects=True)
open(f'/tmp/{NameOfUpdateFile}', 'wb').write(updateFile.content)
except:
print("Error when trying to download update package.")
raise Exception()
def applyUpdateToOpt(version):
match version:
case "stable":
if not path.exists('/opt/discord'): makedirs('/opt/discord')
case "beta":
if not path.exists('/opt/discord-ptb'): makedirs('/opt/discord-ptb')
case "canary":
if not path.exists('/opt/discord-canary'): makedirs('/opt/discord-canary')
try:
fileUpdate = tarfile.open(f'/tmp/{NameOfUpdateFile}')
fileUpdate.extractall('/opt')
fileUpdate.close()
print("Update completed.")
except:
print("Error when trying to extract updates for opt/Discord.")