Esempio n. 1
0
def check_updates():
    """Check for updates from arkOS repo server."""
    updates = []
    gpg = gnupg.GPG()
    server = config.get("general", "repo_server")
    current = config.get("updates", "current_update")
    # Fetch updates from registry server
    api_url = "https://{0}/api/v1/updates/{1}"
    data = api(api_url.format(server, str(current)), crit=True)
    for x in data["updates"]:
        ustr, u = str(x["tasks"]), json.loads(x["tasks"])
        # Get the update signature and test it
        sig_url = "https://{0}/api/v1/signatures/{1}"
        sig = api(sig_url.format(server, x["id"]), returns="raw", crit=True)
        with open("/tmp/{0}.sig".format(x["id"]), "w") as f:
            f.write(sig)
        v = gpg.verify_data("/tmp/{0}.sig".format(x["id"]), ustr)
        if v.trust_level is None:
            err_str = "Update {0} signature verification failed"
            logger.error("Updates", err_str.format(x["id"]))
            break
        else:
            data = {
                "id": x["id"],
                "name": x["name"],
                "date": x["date"],
                "info": x["info"],
                "tasks": u
            }
            updates.append(data)
    storage.updates = {x.id: x for x in updates}
    return updates
Esempio n. 2
0
def save_config(config):
    api_key = get_api_key()
    api("http://*****:*****@syncthing")
    s.restart()
    return config
Esempio n. 3
0
def save_config(config):
    api_key = get_api_key()
    api("http://*****:*****@syncthing")
    s.restart()
    return config
Esempio n. 4
0
def scan(verify=True):
    signals.emit("apps", "pre_scan")
    app_dir = config.get("apps", "app_dir")
    apps = []
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)

    # Get paths for installed apps, metadata for available ones
    installed_apps = [x for x in os.listdir(app_dir) if not x.startswith(".")]
    available_apps = api("https://%s/api/v1/apps" % config.get("general", "repo_server"),
        crit=False)
    if available_apps:
        available_apps = available_apps["applications"]
    else:
        available_apps = []

    # Create objects for installed apps with appropriate metadata
    for x in installed_apps:
        try:
            with open(os.path.join(app_dir, x, "manifest.json"), "r") as f:
                data = json.loads(f.read())
        except ValueError:
            logger.warn("Failed to load %s due to a JSON parsing error" % x)
            continue
        except IOError:
            logger.warn("Failed to load %s: manifest file inaccessible or not present" % x)
            continue
        logger.debug(" *** Loading %s" % data["id"])
        app = App(**data)
        app.installed = True
        for y in enumerate(available_apps):
            if app.id == y[1]["id"] and app.version != y[1]["version"]:
                app.upgradable = y[1]["version"]
            if app.id == y[1]["id"]:
                app.assets = y[1]["assets"]
                available_apps[y[0]]["installed"] = True
        app.load()
        apps.append(app)

    # Convert available apps payload to objects
    for x in available_apps:
        if not x.get("installed"):
            app = App(**x)
            app.installed = False
            apps.append(app)

    storage.apps.set("applications", apps)

    if verify:
        verify_app_dependencies()
    signals.emit("apps", "post_scan")
    return storage.apps.get("applications")
Esempio n. 5
0
def check_updates():
    updates = []
    gpg = gnupg.GPG()
    server = config.get("general", "repo_server")
    current = config.get("updates", "current_update", 0)
    # Fetch updates from registry server
    data = api("https://%s/api/v1/updates/%s" % (server, str(current)), crit=True)
    for x in data["updates"]:
        ustr, u = str(x["tasks"]), json.loads(x["tasks"])
        # Get the update signature and test it
        sig = api("https://%s/api/v1/signatures/%s" % (server, x["id"]), 
            returns="raw", crit=True)
        with open("/tmp/%s.sig" % x["id"], "w") as f:
            f.write(sig)
        v = gpg.verify_data("/tmp/%s.sig" % x["id"], ustr)
        if v.trust_level == None:
            logger.error("Update %s signature verification failed" % x["id"])
            break
        else:
            updates.append({"id": x["id"], "name": x["name"], "date": x["date"], 
                "info": x["info"], "tasks": u})
    storage.updates.set("updates", updates)
    return updates
Esempio n. 6
0
def _install(id, load=True, cry=True):
    """
    Utility function to download and install arkOS app packages.

    :param str id: ID of arkOS app to install
    :param bool load: Load the app after install?
    :param bool cry: Raise exception on dependency install failure?
    """
    app_dir = config.get("apps", "app_dir")
    # Download and extract the app source package
    api_url = "https://{0}/api/v1/apps/{1}"
    data = api(api_url.format(config.get("general", "repo_server"), id),
               returns="raw", crit=True)
    path = os.path.join(app_dir, "{0}.tar.gz".format(id))
    with open(path, "wb") as f:
        f.write(data)
    with tarfile.open(path, "r:gz") as t:
        t.extractall(app_dir)
    os.unlink(path)
    # Read the app's metadata and create an object
    with open(os.path.join(app_dir, id, "manifest.json")) as f:
        data = json.loads(f.read())
    app = get(id)
    for x in data:
        setattr(app, x, data[x])
    app.upgradable = ""
    app.installed = True
    for x in app.services:
        if x.get("type") == "system" and x.get("binary") \
                and not x.get("ignore_on_install"):
            s = services.get(x["binary"])
            if s:
                s.enable()
                if s.state != "running":
                    try:
                        s.start()
                    except services.ActionError as e:
                        logger.warning(
                            "Apps", "{0} could not be automatically started."
                            .format(s.name))
    if load:
        app.load(cry=cry)
Esempio n. 7
0
def _install(id, load=True):
    app_dir = config.get("apps", "app_dir")
    # Download and extract the app source package
    data = api("https://%s/api/v1/apps/%s" % (config.get("general", "repo_server"), id),
        returns="raw", crit=True)
    with open(os.path.join(app_dir, "%s.tar.gz" % id), "wb") as f:
        f.write(data)
    with tarfile.open(os.path.join(app_dir, "%s.tar.gz" % id), "r:gz") as t:
        t.extractall(app_dir)
    os.unlink(os.path.join(app_dir, "%s.tar.gz" % id))
    # Read the app's metadata and create an object
    with open(os.path.join(app_dir, id, "manifest.json")) as f:
        data = json.loads(f.read())
    app = get(id)
    for x in data:
        setattr(app, x, data[x])
    app.upgradable = ""
    app.installed = True
    if load:
        app.load()
Esempio n. 8
0
def get_myid():
    api_key = get_api_key()
    config = api("http://localhost:8384/rest/system/status",
        headers=[("X-API-Key", api_key)], crit=True)
    return config.get("myID", None)
Esempio n. 9
0
def pull_config():
    api_key = get_api_key()
    config = api("http://localhost:8384/rest/system/config",
        headers=[("X-API-Key", api_key)], crit=True)
    return config
Esempio n. 10
0
def scan(verify=True, cry=True):
    """
    Search app directory for applications, load them and store metadata.

    Also contacts arkOS repo servers to obtain current list of available
    apps, and merges in any updates as necessary.

    :param bool verify: Verify app dependencies as the apps are scanned
    :param bool cry: Raise exception on dependency install failure?
    :return: list of Application objects
    :rtype: list
    """
    signals.emit("apps", "pre_scan")
    logger.debug("Apps", "Scanning for applications")
    app_dir = config.get("apps", "app_dir")
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)

    pacman.refresh()
    logger.debug("Apps", "Getting system/python/ruby installed list")
    inst_list = {
        "sys": pacman.get_installed(),
        "py": python.get_installed(),
        "py2": python.get_installed(py2=True),
        "rb": ruby.get_installed()
    }

    # Get paths for installed apps, metadata for available ones
    installed_apps = [x for x in os.listdir(app_dir) if not x.startswith(".")]
    api_url = ("https://{0}/api/v1/apps"
               .format(config.get("general", "repo_server")))
    logger.debug("Apps", "Fetching available apps: {0}".format(api_url))
    try:
        available_apps = api(api_url)
    except Exception as e:
        available_apps = []
        logger.error("Apps", "Could not get available apps from GRM.")
        logger.error("Apps", str(e))
    if available_apps:
        available_apps = available_apps["applications"]
    else:
        available_apps = []

    # Create objects for installed apps with appropriate metadata
    for x in installed_apps:
        try:
            with open(os.path.join(app_dir, x, "manifest.json"), "r") as f:
                data = json.loads(f.read())
        except ValueError:
            warn_str = "Failed to load {0} due to a JSON parsing error"
            logger.warning("Apps", warn_str.format(x))
            continue
        except IOError:
            warn_str = "Failed to load {0}: manifest file inaccessible "\
                       "or not present"
            logger.warning("Apps", warn_str.format(x))
            continue
        logger.debug("Apps", " *** Loading {0}".format(data["id"]))
        app = App(**data)
        app.installed = True
        for y in enumerate(available_apps):
            if app.id == y[1]["id"] and app.version != y[1]["version"]:
                app.upgradable = y[1]["version"]
            if app.id == y[1]["id"]:
                app.assets = y[1]["assets"]
                available_apps[y[0]]["installed"] = True
        app.load(verify=verify, cry=cry, installed=inst_list)
        storage.applications[app.id] = app

    # Convert available apps payload to objects
    for x in available_apps:
        if not x.get("installed"):
            app = App(**x)
            app.installed = False
            storage.applications[app.id] = app

    if verify:
        verify_app_dependencies()
    signals.emit("apps", "post_scan")
    return storage.applications
Esempio n. 11
0
def get_myid():
    api_key = get_api_key()
    config = api("http://localhost:8384/rest/system/status",
                 headers=[("X-API-Key", api_key)],
                 crit=True)
    return config.get("myID", None)
Esempio n. 12
0
def pull_config():
    api_key = get_api_key()
    config = api("http://localhost:8384/rest/system/config",
                 headers=[("X-API-Key", api_key)],
                 crit=True)
    return config