-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·50 lines (39 loc) · 1.32 KB
/
main.py
File metadata and controls
executable file
·50 lines (39 loc) · 1.32 KB
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
#!/usr/bin/python3
import os
import subprocess
import requests
from dotenv import load_dotenv
from packaging import version
load_dotenv()
system_type = os.getenv("OS")
build = os.getenv("BUILD")
plex = os.getenv("PLEX_LOCATION")
download_location = os.getenv("DOWNLOAD_LOCATION")
result = requests.get('https://plex.tv/pms/downloads/5.json')
result = result.json()
result = result['computer'][system_type]
current_version = version.parse(result['version'])
try:
system_version = subprocess.check_output(
[plex, '--version']).decode("utf-8").strip()
except subprocess.CalledProcessError as e:
print("""An error occured when getting the system version of Plex.
Check that you have the correct location in your .env and try again.""")
print(repr(e))
exit(1)
system_version = version.parse(system_version) if not system_version.startswith(
"v") else version.parse(system_version[1:])
if current_version > system_version:
print("Update Found!")
else:
print("No Update")
exit(0)
for item in result['releases']:
if item['build'] == build:
update_url = item['url']
break
file_download = requests.get(update_url)
file_location = "{}update.deb".format(download_location)
with open(file_location, 'wb') as f:
f.write(file_download.content)
os.system("dpkg -i {}".format(file_location))