Update check-nextcloud

Add docker support
This commit is contained in:
Thorsten Spille 2022-01-30 23:36:29 +01:00 committed by GitHub
parent fb1880fa9f
commit 0a11b3ddac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,6 +39,9 @@ def check_nextcloud(name:str, conf:dict):
def update_check(conf:dict):
if 'docker_container' in conf.keys() and (conf['docker_container'] != None or conf['docker_container'] != ""):
result = occ("update:check", conf['nc_www_user'],conf['nc_path'], conf['nc_php_version'], docker_container=conf['docker_container'])
else:
result = occ("update:check", conf['nc_www_user'],conf['nc_path'], conf['nc_php_version'])
if len(result.split('\n')) > 2:
@ -51,6 +54,9 @@ def update_check(conf:dict):
return f"updates={count};;1;; {updates}"
def status(conf:dict):
if 'docker_container' in conf.keys() and (conf['docker_container'] != None or conf['docker_container'] != ""):
result = occ("status", conf['nc_www_user'],conf['nc_path'], conf['nc_php_version'], output="json", docker_container=conf['docker_container'])
else:
result = json.loads(occ("status", conf['nc_www_user'],conf['nc_path'], conf['nc_php_version'], output="json"))
if result.get('installed') == False:
state = 2
@ -63,11 +69,16 @@ def status(conf:dict):
def printout(name:str,function:str, result:str):
print(f'P "Nextcloud {name} {function}" {result}')
def occ (command:str, nc_www_user:str, nc_path:str, nc_php_version:str="", output:str="", return_stderr:bool=False):
def occ (command:str, nc_www_user:str, nc_path:str, nc_php_version:str="", output:str="", return_stderr:bool=False, docker_container:str=None):
if docker_container != None:
cmd = f"docker exec --user {nc_www_user} --workdir {nc_path} {docker_container} php{nc_php_version} occ {command}"
else:
cmd = f"sudo --user={nc_www_user} php{nc_php_version} occ {command}"
if output != "":
cmd = cmd + f" --output {output}"
_proc = subprocess.Popen([ cmd ], shell=True, cwd=nc_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_proc = subprocess.Popen([ cmd ], shell=True, cwd=nc_path if docker_container != None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = _proc.communicate()
if (stderr):