Denis Kulicek GitHub 6 роки тому
джерело
коміт
c07a89f620
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
2 змінених файлів з 29 додано та 4 видалено
  1. +9
    -4
      modules/addon/endpoints.py
  2. +20
    -0
      modules/utils/__init__.py

+ 9
- 4
modules/addon/endpoints.py Переглянути файл

@@ -4,7 +4,7 @@ import sys
from flask import Blueprint, request, send_from_directory
from importlib import import_module
from modules import socketio, cbpi
from modules.utils import chown_unroot

from git import Repo
import os
@@ -138,7 +138,7 @@ def plugins():
value["installed"] = os.path.isdir("./modules/plugins/%s/" % (key))

return json.dumps(cbpi.cache["plugins"])

@blueprint.route('/<name>/download', methods=['POST'])
def download_addon(name):
@@ -148,7 +148,10 @@ def download_addon(name):
if plugin is None:
return ('', 404)
try:
Repo.clone_from(plugin.get("repo_url"), "./modules/plugins/%s/" % (name))
module_path= "./modules/plugins/%s/" % (name)
Repo.clone_from(plugin.get("repo_url"), module_path)
chown_unroot(module_path)

cbpi.notify("Download successful", "Plugin %s downloaded successfully" % name)
finally:
plugin["loading"] = False
@@ -157,9 +160,11 @@ def download_addon(name):

@blueprint.route('/<name>/update', methods=['POST'])
def update_addon(name):
repo = Repo("./modules/plugins/%s/" % (name))
module_path= "./modules/plugins/%s/" % (name)
repo = Repo(module_path)
o = repo.remotes.origin
info = o.pull()
chown_unroot(module_path)
cbpi.notify("Plugin Updated", "Plugin %s updated successfully. Please restart the system" % name)
return ('', 204)



+ 20
- 0
modules/utils/__init__.py Переглянути файл

@@ -0,0 +1,20 @@
from modules import cbpi
import os

def chown_unroot(path):
"""
Changes owner of the path recursively from root:root to the user:group who installed craftbeerpi
can be used to unroot plugins and craftbeerpi updates
"""
dir_stat = os.stat('.')
uid = dir_stat.st_uid
gid = dir_stat.st_gid

cbpi.app.logger.info("Executing chown -R for: " + path)

for root, dirs, files in os.walk(path):
os.chown(root, uid, gid)
for name in dirs:
os.chown(os.path.join(root, name), uid, gid)
for name in files:
os.chown(os.path.join(root, name), uid, gid)

Завантаження…
Відмінити
Зберегти