-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathembyupdate.py
executable file
·109 lines (86 loc) · 4.42 KB
/
embyupdate.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
#!/usr/bin/env python3
# This Python file uses the following encoding: utf-8
"""
EmbyUpdate: The main file and only executable script of the EmbyUpdate package
###############################################################################################
# This script can be used to keep Emby servers for linux automatically up to date. #
# It is set up for the X64 and ARM versions of Debian,Ubuntu,Mint,CentOS,Fedora,Arch and #
# OpenSUSE. Most of these packages will stop/start the server as needed in the internal #
# install logic of the distro's installer. But if your distro uses systemd then this script #
# has logic that can stop and start the server if needed. If you don't have systemd then #
# if you want the server stopped and started by the script you'll need to modify the #
# commands as needed. #
# Must use python 3.6 +. 3.7 + recommended as dataclasses are used. #
###############################################################################################
"""
__version__ = "v4.20"
__author__ = "Justin Hopper"
__email__ = "[email protected]"
__maintainer__ = "Justin Hopper"
__copyright__ = "Copyright 2023, EmbyUpdate"
__license__ = "GNU3"
__status__ = "Stable"
__credits__ = [""]
# ------------------------------------------------------------------------------------------
import os.path
import sys
from genericpath import exists
import directoryfix
# Before we import the rest, we have to see if the user has a 3.6 or earlier version of EmbyUpdate. Because it had a
# broken unzipper that couldn't unzip into directories, it unzips 4.1+ versions without their directories. Therefore,
# causing an app failure. If it does fail to import, it throws an exception which we catch and trigger a fix. We detect
# earlier version by checking for the existence of a file (configupdate.py) that doesn't exist in later versions.
try:
from functions import (pythonversion, config, arguments, configsetup, selfupdate,
api, updatecheck, install, colors)
from db import createdb, dbobjects
except Exception:
os.chdir(sys.path[0])
if os.path.exists("configupdate.py"):
directoryfix.fix_directory()
# Here we reload the app to run with the directories now created. This will allow the app to run without an
# exception.
os.execv(sys.argv[0], sys.argv)
def main():
"""
The main function is the entry point for the program. It is called when embyupdate starts up
and checks to see if there are any updates available. If there are, it will download them
and install them.
"""
# pylint: disable=C0103
c = colors.Terminalcolors()
# Sets the version # for the command line -v/--version response
version = f"{__version__} - {__status__}"
# Checks for command line arguments
arguments.read_args(version)
# Checks for python version, exit if not greater than 3.6
pythonversion.python_version_check()
# Fixes pre version 4.0 config files if they exist (upgrade to new DB config system)
config.Config().config_fix(version)
# First we're going to force the working path to be where the script lives
os.chdir(sys.path[0])
# This will test to see if the DB exist. If it doesn't it will create it and
# launch the config setup process
if not exists('./db/embyupdate.db'):
print()
print(f"Database does {c.fg.red}NOT{c.end} exist, creating database...")
createdb.create_db(version)
print()
print("Starting config setup...")
configsetup.config_setup(version)
# We'll get the config from the DB
config_obj: dbobjects.ConfigObj = dbobjects.ConfigObj().get_config()
if not config_obj.mainconfig.configran:
configsetup.config_setup(version)
config_obj.selfupdate.version = version
# Now well try and update this app if the user chose that option
if config_obj.selfupdate.runupdate is True:
selfupdate.self_update(config_obj)
# Here we'll grab the latest online version from the Emby GitHub
config_obj = api.get_main_online_version(config_obj)
# Ok, we've got all the info we need. Now we'll test if we even need to update or not
update_needed = updatecheck.check_for_update(config_obj) # pylint: disable=E1111
if update_needed:
install.update_emby(config_obj)
if __name__ == "__main__":
main()