From 79a3a9ce664cdc20a9c4b968fd8b8264999e01c3 Mon Sep 17 00:00:00 2001 From: Bart Ribbers Date: Wed, 20 Jan 2021 10:56:20 +0100 Subject: community/mycroft-core: apply improved XDG patches Applied patches are all submitted upstream This removes the need to ship our own start script and makes sure it's compatible with the patches applied to MSM in the previous commit --- .../0001-xdg-settings-cache-and-runtime-data.patch | 830 +++++++++++++++++++++ community/mycroft-core/0001-xdg.patch | 789 -------------------- .../mycroft-core/0002-system-wide-setups.patch | 402 ++++++++++ community/mycroft-core/0003-skills-from-xdg.patch | 220 ++++++ community/mycroft-core/APKBUILD | 22 +- community/mycroft-core/mycroft.conf | 6 - community/mycroft-core/profile.sh | 4 +- community/mycroft-core/start-mycroft.sh | 125 ---- community/mycroft-core/stop-mycroft.sh | 106 --- 9 files changed, 1462 insertions(+), 1042 deletions(-) create mode 100644 community/mycroft-core/0001-xdg-settings-cache-and-runtime-data.patch delete mode 100644 community/mycroft-core/0001-xdg.patch create mode 100644 community/mycroft-core/0002-system-wide-setups.patch create mode 100644 community/mycroft-core/0003-skills-from-xdg.patch delete mode 100644 community/mycroft-core/mycroft.conf delete mode 100755 community/mycroft-core/start-mycroft.sh delete mode 100755 community/mycroft-core/stop-mycroft.sh (limited to 'community') diff --git a/community/mycroft-core/0001-xdg-settings-cache-and-runtime-data.patch b/community/mycroft-core/0001-xdg-settings-cache-and-runtime-data.patch new file mode 100644 index 00000000000..486a3c058f9 --- /dev/null +++ b/community/mycroft-core/0001-xdg-settings-cache-and-runtime-data.patch @@ -0,0 +1,830 @@ +From ed3d54c8f15de72c8287fb1c57138e7c1de4073c Mon Sep 17 00:00:00 2001 +From: Bart Ribbers +Date: Fri, 8 May 2020 21:32:33 +0200 +Subject: [PATCH 1/3] Use XDG Base directories for settings, cache and runtime + data + +--- + README.md | 10 +-- + bin/mycroft-config | 6 +- + mycroft/api/__init__.py | 17 ++---- + mycroft/client/enclosure/__main__.py | 6 +- + mycroft/client/enclosure/mark1/__init__.py | 5 ++ + mycroft/client/speech/hotword_factory.py | 48 +++++++++++++-- + mycroft/client/text/text_client.py | 35 ++++++++++- + mycroft/configuration/__init__.py | 1 - + mycroft/configuration/config.py | 67 +++++++++++++++++---- + mycroft/configuration/locations.py | 25 ++------ + mycroft/configuration/mycroft.conf | 8 +-- + mycroft/filesystem/__init__.py | 10 ++- + mycroft/messagebus/send_func.py | 7 +-- + mycroft/skills/event_scheduler.py | 10 ++- + mycroft/skills/skill_updater.py | 7 ++- + mycroft/util/file_utils.py | 21 ++++--- + mycroft/util/log.py | 11 ++-- + test/unittests/skills/test_skill_updater.py | 6 +- + test/unittests/util/commented.json | 2 +- + test/unittests/util/plain.json | 2 +- + 20 files changed, 212 insertions(+), 92 deletions(-) + +diff --git a/README.md b/README.md +index 1665b0a68dd..eaf04259ddb 100644 +--- a/README.md ++++ b/README.md +@@ -71,20 +71,20 @@ Mycroft is nothing without skills. There are a handful of default skills that a + + ## Pairing Information + Pairing information generated by registering with Home is stored in: +-`~/.mycroft/identity/identity2.json` <-- DO NOT SHARE THIS WITH OTHERS! ++`~/.config/mycroft/identity/identity2.json` <-- DO NOT SHARE THIS WITH OTHERS! + + ## Configuration + Mycroft configuration consists of 4 possible locations: +-- `mycroft-core/mycroft/configuration/mycroft.conf`(Defaults) ++- `mycroft-core/mycroft/configuration/mycroft.conf` (Defaults) + - [Mycroft Home](https://home.mycroft.ai) (Remote) +-- `/etc/mycroft/mycroft.conf`(Machine) +-- `$HOME/.mycroft/mycroft.conf`(User) ++- `/etc/mycroft/mycroft.conf` (Machine) ++- `$XDG_CONFIG_DIR/mycroft/mycroft.conf` (which is by default `$HOME/.config/mycroft/mycroft.conf`) (USER) + + When the configuration loader starts, it looks in these locations in this order, and loads ALL configurations. Keys that exist in multiple configuration files will be overridden by the last file to contain the value. This process results in a minimal amount being written for a specific device and user, without modifying default distribution files. + + ## Using Mycroft Without Home + +-If you do not wish to use the Mycroft Home service, before starting Mycroft for the first time, create `$HOME/.mycroft/mycroft.conf` with the following contents: ++If you do not wish to use the Mycroft Home service, before starting Mycroft for the first time, create `$HOME/.config/mycroft/mycroft.conf` with the following contents: + + ``` + { +diff --git a/bin/mycroft-config b/bin/mycroft-config +index a1271b328df..981f2c5d0c6 100755 +--- a/bin/mycroft-config ++++ b/bin/mycroft-config +@@ -95,13 +95,13 @@ function validate_config_file() { + return $result + } + +-_conf_file="~/.mycroft/mycroft.conf" ++_conf_file="~/.config/mycroft/mycroft.conf" + function name_to_path() { + case ${1} in + "system") _conf_file="/etc/mycroft/mycroft.conf" ;; +- "user") _conf_file=$(readlink -f ~/.mycroft/mycroft.conf) ;; ++ "user") _conf_file=$(readlink -f ~/.config/mycroft/mycroft.conf) ;; + "default") _conf_file="$DIR/../mycroft/configuration/mycroft.conf" ;; +- "remote") _conf_file="/var/tmp/mycroft_web_cache.json" ;; ++ "remote") _conf_file="$HOME/.cache/mycroft/web_cache.json" ;; + + *) + echo "ERROR: Unknown name '${1}'." +diff --git a/mycroft/api/__init__.py b/mycroft/api/__init__.py +index 43663ee1270..d2843120ef4 100644 +--- a/mycroft/api/__init__.py ++++ b/mycroft/api/__init__.py +@@ -20,8 +20,6 @@ + from requests import HTTPError, RequestException + + from mycroft.configuration import Configuration +-from mycroft.configuration.config import DEFAULT_CONFIG, SYSTEM_CONFIG, \ +- USER_CONFIG + from mycroft.identity import IdentityManager, identity_lock + from mycroft.version import VersionManager + from mycroft.util import get_arch, connected, LOG +@@ -49,12 +47,9 @@ class Api: + def __init__(self, path): + self.path = path + +- # Load the config, skipping the REMOTE_CONFIG since we are ++ # Load the config, skipping the remote config since we are + # getting the info needed to get to it! +- config = Configuration.get([DEFAULT_CONFIG, +- SYSTEM_CONFIG, +- USER_CONFIG], +- cache=False) ++ config = Configuration.get(cache=False, remote=False) + config_server = config.get("server") + self.url = config_server.get("url") + self.version = config_server.get("version") +@@ -238,9 +233,7 @@ def activate(self, state, token): + platform_build = "" + + # load just the local configs to get platform info +- config = Configuration.get([SYSTEM_CONFIG, +- USER_CONFIG], +- cache=False) ++ config = Configuration.get(cache=False, remote=False) + if "enclosure" in config: + platform = config.get("enclosure").get("platform", "unknown") + platform_build = config.get("enclosure").get("platform_build", "") +@@ -262,9 +255,7 @@ def update_version(self): + platform_build = "" + + # load just the local configs to get platform info +- config = Configuration.get([SYSTEM_CONFIG, +- USER_CONFIG], +- cache=False) ++ config = Configuration.get(cache=False, remote=False) + if "enclosure" in config: + platform = config.get("enclosure").get("platform", "unknown") + platform_build = config.get("enclosure").get("platform_build", "") +diff --git a/mycroft/client/enclosure/__main__.py b/mycroft/client/enclosure/__main__.py +index 7ff403f4175..074258e0d9b 100644 +--- a/mycroft/client/enclosure/__main__.py ++++ b/mycroft/client/enclosure/__main__.py +@@ -17,7 +17,7 @@ + This provides any "enclosure" specific functionality, for example GUI or + control over the Mark-1 Faceplate. + """ +-from mycroft.configuration import LocalConf, SYSTEM_CONFIG ++from mycroft.configuration import Configuration + from mycroft.util.log import LOG + from mycroft.util import wait_for_exit_signal, reset_sigint_handler + +@@ -70,8 +70,8 @@ def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping): + only the GUI bus will be started. + """ + # Read the system configuration +- system_config = LocalConf(SYSTEM_CONFIG) +- platform = system_config.get("enclosure", {}).get("platform") ++ config = Configuration.get(remote=False) ++ platform = config.get("enclosure", {}).get("platform") + + enclosure = create_enclosure(platform) + if enclosure: +diff --git a/mycroft/client/enclosure/mark1/__init__.py b/mycroft/client/enclosure/mark1/__init__.py +index 26a7311c791..491d096496c 100644 +--- a/mycroft/client/enclosure/mark1/__init__.py ++++ b/mycroft/client/enclosure/mark1/__init__.py +@@ -15,8 +15,10 @@ + import subprocess + import time + import sys ++import os + from alsaaudio import Mixer + from threading import Thread, Timer ++from xdg import BaseDirectory + + import serial + +@@ -163,6 +165,9 @@ def process(self, data): + if "unit.factory-reset" in data: + self.bus.emit(Message("speak", { + 'utterance': mycroft.dialog.get("reset to factory defaults")})) ++ subprocess.call( ++ 'rm ~/.config/mycroft/identity/identity2.json', ++ shell=True) + subprocess.call( + 'rm ~/.mycroft/identity/identity2.json', + shell=True) +diff --git a/mycroft/client/speech/hotword_factory.py b/mycroft/client/speech/hotword_factory.py +index 6573b7aac40..4938c9dbb87 100644 +--- a/mycroft/client/speech/hotword_factory.py ++++ b/mycroft/client/speech/hotword_factory.py +@@ -28,10 +28,12 @@ + from shutil import rmtree + from threading import Timer, Thread + from urllib.error import HTTPError ++from xdg import BaseDirectory + + from petact import install_package + +-from mycroft.configuration import Configuration, LocalConf, USER_CONFIG ++from mycroft.configuration import Configuration, LocalConf ++from mycroft.configuration.locations import OLD_USER_CONFIG + from mycroft.util.log import LOG + from mycroft.util.monotonic_event import MonotonicEvent + from mycroft.util.plugins import load_plugin +@@ -191,7 +193,27 @@ def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): + from precise_runner import ( + PreciseRunner, PreciseEngine, ReadWriteStream + ) +- local_conf = LocalConf(USER_CONFIG) ++ ++ # We need to save to a writeable location, but the key we need ++ # might be stored in a different, unwriteable, location ++ # Make sure we pick the key we need from wherever it's located, ++ # but save to a writeable location only ++ local_conf = LocalConf(join(BaseDirectory.save_config_path('mycroft'), ++ 'mycroft.conf')) ++ ++ for dir in BaseDirectory.load_config_paths('mycroft'): ++ conf = LocalConf(join(dir, 'mycroft.conf')) ++ # If the current config contains the precise key use it, ++ # otherwise continue to the next file ++ if conf.get('precise', None) is not None: ++ local_conf['precise'] = conf.get('precise', None) ++ break ++ ++ # If the key is not found yet, it might still exist on the old ++ # (deprecated) location ++ if local_conf.get('precise', None) is None: ++ local_conf = LocalConf(OLD_USER_CONFIG) ++ + if (local_conf.get('precise', {}).get('dist_url') == + 'http://bootstrap.mycroft.ai/artifacts/static/daily/'): + del local_conf['precise']['dist_url'] +@@ -249,7 +271,10 @@ def update_precise(self, precise_config): + + @property + def folder(self): +- return join(expanduser('~'), '.mycroft', 'precise') ++ old_path = join(expanduser('~'), '.mycroft', 'precise') ++ if os.path.isdir(old_path): ++ return old_path ++ return join(BaseDirectory.save_data_path('mycroft', 'precise')) + + @property + def install_destination(self): +@@ -359,8 +384,23 @@ def found_wake_word(self, frame_data): + class PorcupineHotWord(HotWordEngine): + def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): + super(PorcupineHotWord, self).__init__(key_phrase, config, lang) ++ ++ xdg_data_path = None ++ ++ # Use the old path if available ++ old_path = join(expanduser('~'), '.mycroft', 'Porcupine') ++ if os.path.isdir(old_path): ++ xdg_data_path = old_path ++ ++ # Otherwise use the new XDG config dirs ++ if xdg_data_path is None: ++ for dir in BaseDirectory.load_data_paths('mycroft', 'Porcupine'): ++ if os.path.isdir(dir): ++ xdg_data_path = dir ++ break ++ + porcupine_path = expanduser(self.config.get( +- "porcupine_path", join('~', '.mycroft', 'Porcupine'))) ++ "porcupine_path", xdg_data_path)) + keyword_file_paths = [expanduser(x.strip()) for x in self.config.get( + "keyword_file_path", "hey_mycroft.ppn").split(',')] + sensitivities = self.config.get("sensitivities", 0.5) +diff --git a/mycroft/client/text/text_client.py b/mycroft/client/text/text_client.py +index 0c841d71a87..3729f153f26 100644 +--- a/mycroft/client/text/text_client.py ++++ b/mycroft/client/text/text_client.py +@@ -15,6 +15,7 @@ + import sys + import io + from math import ceil ++from xdg import BaseDirectory + + from .gui_server import start_qml_gui + +@@ -142,7 +143,7 @@ def handleNonAscii(text): + ############################################################################## + # Settings + +-config_file = os.path.join(os.path.expanduser("~"), ".mycroft_cli.conf") ++filename = "mycroft_cli.conf" + + + def load_mycroft_config(bus): +@@ -171,6 +172,34 @@ def load_settings(): + global max_log_lines + global show_meter + ++ config_file = None ++ ++ # Old location ++ path = os.path.join(os.path.expanduser("~"), ".mycroft_cli.conf") ++ if os.path.isfile(path): ++ LOG.warning(" ===============================================") ++ LOG.warning(" == DEPRECATION WARNING ==") ++ LOG.warning(" ===============================================") ++ LOG.warning(" You still have a config file at " + ++ path) ++ LOG.warning(" Note that this location is deprecated and will" + ++ " not be used in the future") ++ LOG.warning(" Please move it to " + ++ BaseDirectory.save_config_path('mycroft')) ++ config_file = path ++ ++ # Check XDG_CONFIG_DIR ++ if config_file is None: ++ for dir in BaseDirectory.load_config_paths('mycroft'): ++ file = os.path.join(dir, filename) ++ if os.path.isfile(file): ++ config_file = file ++ break ++ ++ # Check /etc/mycroft ++ if config_file is None: ++ config_file = os.path.join("/etc/mycroft", filename) ++ + try: + with io.open(config_file, 'r') as f: + config = json.load(f) +@@ -196,6 +225,10 @@ def save_settings(): + config["show_last_key"] = show_last_key + config["max_log_lines"] = max_log_lines + config["show_meter"] = show_meter ++ ++ config_file = os.path.join( ++ BaseDirectory.save_config_path("mycroft"), filename) ++ + with io.open(config_file, 'w') as f: + f.write(str(json.dumps(config, ensure_ascii=False))) + +diff --git a/mycroft/configuration/__init__.py b/mycroft/configuration/__init__.py +index da28826c11d..b920d9c8336 100644 +--- a/mycroft/configuration/__init__.py ++++ b/mycroft/configuration/__init__.py +@@ -13,4 +13,3 @@ + # limitations under the License. + # + from .config import Configuration, LocalConf, RemoteConf +-from .locations import SYSTEM_CONFIG, USER_CONFIG +diff --git a/mycroft/configuration/config.py b/mycroft/configuration/config.py +index dd82eae651f..d5a9fd520a4 100644 +--- a/mycroft/configuration/config.py ++++ b/mycroft/configuration/config.py +@@ -17,15 +17,15 @@ + import re + import json + import inflection +-from os.path import exists, isfile ++from os.path import exists, isfile, join, expanduser, dirname + from requests import RequestException ++from xdg import BaseDirectory + ++from .locations import DEFAULT_CONFIG, OLD_USER_CONFIG, USER_CONFIG ++from .locations import SYSTEM_CONFIG + from mycroft.util.json_helper import load_commented_json, merge_dict + from mycroft.util.log import LOG + +-from .locations import (DEFAULT_CONFIG, SYSTEM_CONFIG, USER_CONFIG, +- WEB_CONFIG_CACHE) +- + + def is_remote_list(values): + """Check if list corresponds to a backend formatted collection of dicts +@@ -127,7 +127,8 @@ class RemoteConf(LocalConf): + def __init__(self, cache=None): + super(RemoteConf, self).__init__(None) + +- cache = cache or WEB_CONFIG_CACHE ++ cache = cache or join(BaseDirectory.save_cache_path('mycroft'), ++ 'web_cache.json') + from mycroft.api import is_paired + if not is_paired(): + self.load_local(cache) +@@ -173,7 +174,7 @@ class Configuration: + __patch = {} # Patch config that skills can update to override config + + @staticmethod +- def get(configs=None, cache=True): ++ def get(configs=None, cache=True, remote=True): + """Get configuration + + Returns cached instance if available otherwise builds a new +@@ -182,6 +183,9 @@ def get(configs=None, cache=True): + Arguments: + configs (list): List of configuration dicts + cache (boolean): True if the result should be cached ++ remote (boolean): False if the Mycroft Home settings shouldn't ++ be loaded ++ + + Returns: + (dict) configuration dictionary. +@@ -189,23 +193,62 @@ def get(configs=None, cache=True): + if Configuration.__config: + return Configuration.__config + else: +- return Configuration.load_config_stack(configs, cache) ++ return Configuration.load_config_stack(configs, cache, remote) + + @staticmethod +- def load_config_stack(configs=None, cache=False): ++ def load_config_stack(configs=None, cache=False, remote=True): + """Load a stack of config dicts into a single dict + + Arguments: + configs (list): list of dicts to load + cache (boolean): True if result should be cached +- ++ remote (boolean): False if the Mycroft Home settings shouldn't ++ be loaded + Returns: + (dict) merged dict of all configuration files + """ + if not configs: +- configs = [LocalConf(DEFAULT_CONFIG), RemoteConf(), +- LocalConf(SYSTEM_CONFIG), LocalConf(USER_CONFIG), +- Configuration.__patch] ++ configs = configs or [] ++ ++ # First use the patched config ++ configs.append(Configuration.__patch) ++ ++ # Then use XDG config ++ # This includes both the user config and ++ # /etc/xdg/mycroft/mycroft.conf ++ for dir in BaseDirectory.load_config_paths('mycroft'): ++ configs.append(LocalConf(join(dir, 'mycroft.conf'))) ++ ++ # Then check the old user config ++ if isfile(OLD_USER_CONFIG): ++ LOG.warning(" ===============================================") ++ LOG.warning(" == DEPRECATION WARNING ==") ++ LOG.warning(" ===============================================") ++ LOG.warning(" You still have a config file at " + ++ OLD_USER_CONFIG) ++ LOG.warning(" Note that this location is deprecated and will" + ++ " not be used in the future") ++ LOG.warning(" Please move it to " + ++ BaseDirectory.save_config_path('mycroft')) ++ configs.append(LocalConf(OLD_USER_CONFIG)) ++ ++ # Then check the XDG user config ++ if isfile(USER_CONFIG): ++ configs.append(LocalConf(USER_CONFIG)) ++ ++ # Then use remote config ++ if remote: ++ configs.append(RemoteConf()) ++ ++ # Then use the system config (/etc/mycroft/mycroft.conf) ++ configs.append(LocalConf(SYSTEM_CONFIG)) ++ ++ # Then use the config that comes with the package ++ configs.append(LocalConf(DEFAULT_CONFIG)) ++ ++ # Make sure we reverse the array, as merge_dict will put every new ++ # file on top of the previous one ++ configs = reversed(configs) + else: + # Handle strings in stack + for index, item in enumerate(configs): +diff --git a/mycroft/configuration/locations.py b/mycroft/configuration/locations.py +index cbbaab6ca94..eb8cfb18c76 100644 +--- a/mycroft/configuration/locations.py ++++ b/mycroft/configuration/locations.py +@@ -13,26 +13,13 @@ + # limitations under the License. + import os + from os.path import join, dirname, expanduser, exists ++from xdg import BaseDirectory + + DEFAULT_CONFIG = join(dirname(__file__), 'mycroft.conf') + SYSTEM_CONFIG = os.environ.get('MYCROFT_SYSTEM_CONFIG', + '/etc/mycroft/mycroft.conf') +-USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf') +-REMOTE_CONFIG = "mycroft.ai" +-WEB_CONFIG_CACHE = os.environ.get('MYCROFT_WEB_CACHE', +- '/var/tmp/mycroft_web_cache.json') +- +- +-def __ensure_folder_exists(path): +- """ Make sure the directory for the specified path exists. +- +- Arguments: +- path (str): path to config file +- """ +- directory = dirname(path) +- if not exists(directory): +- os.makedirs(directory) +- +- +-__ensure_folder_exists(WEB_CONFIG_CACHE) +-__ensure_folder_exists(USER_CONFIG) ++# Make sure we support the old location still ++# Deprecated and will be removed eventually ++OLD_USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf') ++USER_CONFIG = join(BaseDirectory.save_config_path('mycroft'), ++ 'mycroft.conf') +diff --git a/mycroft/configuration/mycroft.conf b/mycroft/configuration/mycroft.conf +index b18eb9b09a9..c61fd90579b 100644 +--- a/mycroft/configuration/mycroft.conf ++++ b/mycroft/configuration/mycroft.conf +@@ -5,7 +5,7 @@ + // overridden at the REMOTE level (set by the user via + // https://home.mycroft.ai), at the SYSTEM level (typically in the file + // '/etc/mycroft/mycroft.conf'), or at the USER level (typically in the +- // file '~/.mycroft/mycroft.conf'). ++ // file '~/.config/mycroft/mycroft.conf'). + // + // The load order of settings is: + // DEFAULT +@@ -107,7 +107,7 @@ + }, + "upload_skill_manifest": true, + // Directory to look for user skills +- "directory": "~/.mycroft/skills", ++ "directory": "~/.local/share/mycroft/skills", + // Enable auto update by msm + "auto_update": true, + // blacklisted skills to not load +@@ -211,7 +211,7 @@ + "threshold": 1e-90, + "lang": "en-us" + // Specify custom model via: +- // "local_model_file": "~/.mycroft/precise/models/something.pb" ++ // "local_model_file": "~/.local/share/mycroft/precise/models/something.pb" + // Precise options: + // "sensitivity": 0.5, // Higher = more sensitive + // "trigger_level": 3 // Higher = more delay & less sensitive +@@ -315,7 +315,7 @@ + }, + + "padatious": { +- "intent_cache": "~/.mycroft/intent_cache", ++ "intent_cache": "~/.local/share/mycroft/intent_cache", + "train_delay": 4, + "single_thread": false + }, +diff --git a/mycroft/filesystem/__init__.py b/mycroft/filesystem/__init__.py +index 45ec15a4ac5..ecd10d86e41 100644 +--- a/mycroft/filesystem/__init__.py ++++ b/mycroft/filesystem/__init__.py +@@ -13,7 +13,9 @@ + # limitations under the License. + # + import os ++import shutil + from os.path import join, expanduser, isdir ++from xdg import BaseDirectory + + + class FileSystemAccess: +@@ -30,7 +32,13 @@ def __init__(self, path): + def __init_path(path): + if not isinstance(path, str) or len(path) == 0: + raise ValueError("path must be initialized as a non empty string") +- path = join(expanduser('~'), '.mycroft', path) ++ ++ old_path = join(expanduser('~'), '.mycroft', path) ++ path = join(BaseDirectory.save_config_path('mycroft'), path) ++ ++ # Migrate from the old location if it still exists ++ if isdir(old_path): ++ shutil.move(old_path, path) + + if not isdir(path): + os.makedirs(path) +diff --git a/mycroft/messagebus/send_func.py b/mycroft/messagebus/send_func.py +index 403db9f45c1..a11a9b0a591 100644 +--- a/mycroft/messagebus/send_func.py ++++ b/mycroft/messagebus/send_func.py +@@ -15,8 +15,6 @@ + from websocket import create_connection + + from mycroft.configuration import Configuration +-from mycroft.configuration.locations import (DEFAULT_CONFIG, SYSTEM_CONFIG, +- USER_CONFIG) + from mycroft.messagebus.client import MessageBusClient + from mycroft.messagebus.message import Message + +@@ -32,10 +30,7 @@ def send(message_to_send, data_to_send=None): + data_to_send = data_to_send or {} + + # Calculate the standard Mycroft messagebus websocket address +- config = Configuration.get([DEFAULT_CONFIG, +- SYSTEM_CONFIG, +- USER_CONFIG], +- cache=False) ++ config = Configuration.get(cache=False, remote=False) + config = config.get("websocket") + url = MessageBusClient.build_url( + config.get("host"), +diff --git a/mycroft/skills/event_scheduler.py b/mycroft/skills/event_scheduler.py +index fe41ac1bedc..5412dd02548 100644 +--- a/mycroft/skills/event_scheduler.py ++++ b/mycroft/skills/event_scheduler.py +@@ -20,6 +20,7 @@ + from datetime import datetime, timedelta + from threading import Thread, Lock + from os.path import isfile, join, expanduser ++from xdg import BaseDirectory + + from mycroft.configuration import Configuration + from mycroft.messagebus.message import Message +@@ -54,14 +55,19 @@ class EventScheduler(Thread): + """ + def __init__(self, bus, schedule_file='schedule.json'): + super().__init__() +- data_dir = expanduser(Configuration.get()['data_dir']) + + self.events = {} + self.event_lock = Lock() + + self.bus = bus + self.is_running = True +- self.schedule_file = join(data_dir, schedule_file) ++ old_schedule_path = join(expanduser(Configuration.get()['data_dir']), ++ schedule_file) ++ new_schedule_path = join( ++ BaseDirectory.load_first_config('mycroft'), schedule_file) ++ if isfile(old_schedule_path): ++ shutil.move(old_schedule_path, new_schedule_path) ++ self.schedule_file = new_path + if self.schedule_file: + self.load() + +diff --git a/mycroft/skills/skill_updater.py b/mycroft/skills/skill_updater.py +index ace247e2db4..37f4bdc72eb 100644 +--- a/mycroft/skills/skill_updater.py ++++ b/mycroft/skills/skill_updater.py +@@ -17,6 +17,7 @@ + import sys + from datetime import datetime + from time import time ++from xdg import BaseDirectory + + from msm import MsmException + +@@ -96,9 +97,9 @@ def installed_skills_file_path(self): + '.mycroft-skills' + ) + else: +- self._installed_skills_file_path = os.path.expanduser( +- '~/.mycroft/.mycroft-skills' +- ) ++ self._installed_skills_file_path = os.path.join( ++ BaseDirectory.save_data_path('mycroft', ++ 'skills')) + + return self._installed_skills_file_path + +diff --git a/mycroft/util/file_utils.py b/mycroft/util/file_utils.py +index 84555fc3bb3..7c09fd226ee 100644 +--- a/mycroft/util/file_utils.py ++++ b/mycroft/util/file_utils.py +@@ -22,6 +22,7 @@ + import psutil + from stat import S_ISREG, ST_MTIME, ST_MODE, ST_SIZE + import tempfile ++from xdg import BaseDirectory + + import mycroft.configuration + from .log import LOG +@@ -33,15 +34,15 @@ def resolve_resource_file(res_name): + Resource names are in the form: 'filename.ext' + or 'path/filename.ext' + +- The system wil look for ~/.mycroft/res_name first, and +- if not found will look at /opt/mycroft/res_name, +- then finally it will look for res_name in the 'mycroft/res' +- folder of the source code package. ++ The system wil look for $XDG_DATA_DIRS/mycroft/res_name first ++ (defaults to ~/.local/share/mycroft/res_name), and if not found will ++ look at /opt/mycroft/res_name, then finally it will look for res_name ++ in the 'mycroft/res' folder of the source code package. + + Example: + With mycroft running as the user 'bob', if you called + resolve_resource_file('snd/beep.wav') +- it would return either '/home/bob/.mycroft/snd/beep.wav' or ++ it would return either '/home/bob/.local/share/mycroft/snd/beep.wav' or + '/opt/mycroft/snd/beep.wav' or '.../mycroft/res/snd/beep.wav', + where the '...' is replaced by the path where the package has + been installed. +@@ -57,8 +58,14 @@ def resolve_resource_file(res_name): + if os.path.isfile(res_name): + return res_name + +- # Now look for ~/.mycroft/res_name (in user folder) +- filename = os.path.expanduser("~/.mycroft/" + res_name) ++ # Now look for XDG_DATA_DIRS ++ for dir in BaseDirectory.load_data_paths('mycroft'): ++ filename = os.path.join(dir, res_name) ++ if os.path.isfile(filename): ++ return filename ++ ++ # Now look in the old user location ++ filename = os.path.join(os.path.expanduser('~'), '.mycroft', res_name) + if os.path.isfile(filename): + return filename + +diff --git a/mycroft/util/log.py b/mycroft/util/log.py +index 0ea391f8f79..788f6df1c37 100644 +--- a/mycroft/util/log.py ++++ b/mycroft/util/log.py +@@ -21,7 +21,7 @@ + for use. + + The default log level of the logger created here can ONLY be set in +-/etc/mycroft/mycroft.conf or ~/.mycroft/mycroft.conf ++/etc/mycroft/mycroft.conf or ~/.config/mycroft/mycroft.conf + + The default log level can also be programatically be changed by setting the + LOG.level parameter. +@@ -31,10 +31,10 @@ + import logging + import sys + +-from os.path import isfile ++from os.path import isfile, join ++from xdg import BaseDirectory + + from mycroft.util.json_helper import load_commented_json, merge_dict +-from mycroft.configuration.locations import SYSTEM_CONFIG, USER_CONFIG + + + def getLogger(name="MYCROFT"): +@@ -84,7 +84,10 @@ def init(cls): + # Check configs manually, the Mycroft configuration system can't be + # used since it uses the LOG system and would cause horrible cyclic + # dependencies. +- confs = [SYSTEM_CONFIG, USER_CONFIG] ++ confs = [] ++ for dir in BaseDirectory.load_config_paths('mycroft'): ++ confs.append(join(dir, 'mycroft.conf')) ++ confs.append('/etc/mycroft/mycroft.conf') + config = {} + for conf in confs: + try: +diff --git a/test/unittests/skills/test_skill_updater.py b/test/unittests/skills/test_skill_updater.py +index 38d4083d7f2..fbcc9254319 100644 +--- a/test/unittests/skills/test_skill_updater.py ++++ b/test/unittests/skills/test_skill_updater.py +@@ -13,8 +13,9 @@ + # limitations under the License. + # + """Unit tests for the SkillUpdater class.""" +-from os import path ++import os + from time import sleep ++from xdg import BaseDirectory + from unittest.mock import Mock, patch, PropertyMock + + from mycroft.skills.skill_updater import SkillUpdater +@@ -143,7 +144,8 @@ def test_installed_skills_path_not_virtual_env(self): + os_patch.return_value = False + updater = SkillUpdater(self.message_bus_mock) + self.assertEqual( +- path.expanduser('~/.mycroft/.mycroft-skills'), ++ os.path.join(BaseDirectory.save_data_path('mycroft'), ++ 'skills'), + updater.installed_skills_file_path + ) + +diff --git a/test/unittests/util/commented.json b/test/unittests/util/commented.json +index 87c7d3e2c2d..00a581f6df4 100644 +--- a/test/unittests/util/commented.json ++++ b/test/unittests/util/commented.json +@@ -54,7 +54,7 @@ + } + }, + "skills": { +- "directory": "~/.mycroft/skills" ++ "directory": "~/.local/share/mycroft/skills" + }, + "server": { + "url": "https://api.mycroft.ai", +diff --git a/test/unittests/util/plain.json b/test/unittests/util/plain.json +index f8c474139ce..eec84631d88 100644 +--- a/test/unittests/util/plain.json ++++ b/test/unittests/util/plain.json +@@ -36,7 +36,7 @@ + } + }, + "skills": { +- "directory": "~/.mycroft/skills" ++ "directory": "~/.local/share/mycroft/skills" + }, + "server": { + "url": "https://api.mycroft.ai", + +From f01c21e7680846882ae4fa0b328ffe0dea5cb89d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=85ke=20Forslund?= +Date: Fri, 15 Jan 2021 17:11:33 +0100 +Subject: [PATCH 3/3] Fix issues found by flake + +- missing import +- variable name typo +- line-continuation issue +--- + mycroft/skills/event_scheduler.py | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/mycroft/skills/event_scheduler.py b/mycroft/skills/event_scheduler.py +index 5412dd02548..f9931a7ea13 100644 +--- a/mycroft/skills/event_scheduler.py ++++ b/mycroft/skills/event_scheduler.py +@@ -16,6 +16,7 @@ + times. + """ + import json ++import shutil + import time + from datetime import datetime, timedelta + from threading import Thread, Lock +@@ -62,12 +63,12 @@ def __init__(self, bus, schedule_file='schedule.json'): + self.bus = bus + self.is_running = True + old_schedule_path = join(expanduser(Configuration.get()['data_dir']), +- schedule_file) ++ schedule_file) + new_schedule_path = join( + BaseDirectory.load_first_config('mycroft'), schedule_file) + if isfile(old_schedule_path): + shutil.move(old_schedule_path, new_schedule_path) +- self.schedule_file = new_path ++ self.schedule_file = new_schedule_path + if self.schedule_file: + self.load() + diff --git a/community/mycroft-core/0001-xdg.patch b/community/mycroft-core/0001-xdg.patch deleted file mode 100644 index 1d1ec01ca7d..00000000000 --- a/community/mycroft-core/0001-xdg.patch +++ /dev/null @@ -1,789 +0,0 @@ -Upstream pull-request: https://github.com/MycroftAI/mycroft-core/pull/2578 - -From 5e4da71cf61ef69aa3306ba0a1bdf7aad3281587 Mon Sep 17 00:00:00 2001 -From: Bart Ribbers -Date: Fri, 8 May 2020 21:32:33 +0200 -Subject: [PATCH] Use XDG Base directories for settings, cache and runtime data - ---- - README.md | 10 ++-- - bin/mycroft-config | 6 +-- - mycroft/api/__init__.py | 17 ++----- - mycroft/client/enclosure/__main__.py | 6 +-- - mycroft/client/enclosure/mark1/__init__.py | 10 +++- - mycroft/client/speech/hotword_factory.py | 37 ++++++++++++-- - mycroft/client/text/text_client.py | 26 +++++++++- - mycroft/configuration/__init__.py | 1 - - mycroft/configuration/config.py | 53 ++++++++++++++++----- - mycroft/configuration/locations.py | 25 +++------- - mycroft/configuration/mycroft.conf | 8 ++-- - mycroft/filesystem/__init__.py | 8 +++- - mycroft/messagebus/send_func.py | 7 +-- - mycroft/skills/event_scheduler.py | 10 +++- - mycroft/skills/skill_updater.py | 7 +-- - mycroft/util/file_utils.py | 21 +++++--- - mycroft/util/log.py | 11 +++-- - test/unittests/skills/test_skill_updater.py | 6 ++- - test/unittests/util/commented.json | 2 +- - test/unittests/util/plain.json | 2 +- - test/util.py | 5 +- - 21 files changed, 184 insertions(+), 94 deletions(-) - -diff --git a/README.md b/README.md -index 1665b0a68dd..eaf04259ddb 100644 ---- a/README.md -+++ b/README.md -@@ -71,20 +71,20 @@ Mycroft is nothing without skills. There are a handful of default skills that a - - ## Pairing Information - Pairing information generated by registering with Home is stored in: --`~/.mycroft/identity/identity2.json` <-- DO NOT SHARE THIS WITH OTHERS! -+`~/.config/mycroft/identity/identity2.json` <-- DO NOT SHARE THIS WITH OTHERS! - - ## Configuration - Mycroft configuration consists of 4 possible locations: --- `mycroft-core/mycroft/configuration/mycroft.conf`(Defaults) -+- `mycroft-core/mycroft/configuration/mycroft.conf` (Defaults) - - [Mycroft Home](https://home.mycroft.ai) (Remote) --- `/etc/mycroft/mycroft.conf`(Machine) --- `$HOME/.mycroft/mycroft.conf`(User) -+- `/etc/mycroft/mycroft.conf` (Machine) -+- `$XDG_CONFIG_DIR/mycroft/mycroft.conf` (which is by default `$HOME/.config/mycroft/mycroft.conf`) (USER) - - When the configuration loader starts, it looks in these locations in this order, and loads ALL configurations. Keys that exist in multiple configuration files will be overridden by the last file to contain the value. This process results in a minimal amount being written for a specific device and user, without modifying default distribution files. - - ## Using Mycroft Without Home - --If you do not wish to use the Mycroft Home service, before starting Mycroft for the first time, create `$HOME/.mycroft/mycroft.conf` with the following contents: -+If you do not wish to use the Mycroft Home service, before starting Mycroft for the first time, create `$HOME/.config/mycroft/mycroft.conf` with the following contents: - - ``` - { -diff --git a/bin/mycroft-config b/bin/mycroft-config -index a1271b328df..435ceb607d8 100755 ---- a/bin/mycroft-config -+++ b/bin/mycroft-config -@@ -95,13 +95,13 @@ function validate_config_file() { - return $result - } - --_conf_file="~/.mycroft/mycroft.conf" -+_conf_file="~/.config/mycroft/mycroft.conf" - function name_to_path() { - case ${1} in - "system") _conf_file="/etc/mycroft/mycroft.conf" ;; -- "user") _conf_file=$(readlink -f ~/.mycroft/mycroft.conf) ;; -+ "user") _conf_file=$(readlink -f ~/.config/mycroft/mycroft.conf) ;; - "default") _conf_file="$DIR/../mycroft/configuration/mycroft.conf" ;; -- "remote") _conf_file="/var/tmp/mycroft_web_cache.json" ;; -+ "remote") _conf_file="~/.cache/mycroft/web_cache.json" ;; - - *) - echo "ERROR: Unknown name '${1}'." -diff --git a/mycroft/api/__init__.py b/mycroft/api/__init__.py -index 43663ee1270..d2843120ef4 100644 ---- a/mycroft/api/__init__.py -+++ b/mycroft/api/__init__.py -@@ -20,8 +20,6 @@ - from requests import HTTPError, RequestException - - from mycroft.configuration import Configuration --from mycroft.configuration.config import DEFAULT_CONFIG, SYSTEM_CONFIG, \ -- USER_CONFIG - from mycroft.identity import IdentityManager, identity_lock - from mycroft.version import VersionManager - from mycroft.util import get_arch, connected, LOG -@@ -49,12 +47,9 @@ class Api: - def __init__(self, path): - self.path = path - -- # Load the config, skipping the REMOTE_CONFIG since we are -+ # Load the config, skipping the remote config since we are - # getting the info needed to get to it! -- config = Configuration.get([DEFAULT_CONFIG, -- SYSTEM_CONFIG, -- USER_CONFIG], -- cache=False) -+ config = Configuration.get(cache=False, remote=False) - config_server = config.get("server") - self.url = config_server.get("url") - self.version = config_server.get("version") -@@ -238,9 +233,7 @@ def activate(self, state, token): - platform_build = "" - - # load just the local configs to get platform info -- config = Configuration.get([SYSTEM_CONFIG, -- USER_CONFIG], -- cache=False) -+ config = Configuration.get(cache=False, remote=False) - if "enclosure" in config: - platform = config.get("enclosure").get("platform", "unknown") - platform_build = config.get("enclosure").get("platform_build", "") -@@ -262,9 +255,7 @@ def update_version(self): - platform_build = "" - - # load just the local configs to get platform info -- config = Configuration.get([SYSTEM_CONFIG, -- USER_CONFIG], -- cache=False) -+ config = Configuration.get(cache=False, remote=False) - if "enclosure" in config: - platform = config.get("enclosure").get("platform", "unknown") - platform_build = config.get("enclosure").get("platform_build", "") -diff --git a/mycroft/client/enclosure/__main__.py b/mycroft/client/enclosure/__main__.py -index 20cb41aaac2..fdcadf08411 100644 ---- a/mycroft/client/enclosure/__main__.py -+++ b/mycroft/client/enclosure/__main__.py -@@ -17,7 +17,7 @@ - This provides any "enclosure" specific functionality, for example GUI or - control over the Mark-1 Faceplate. - """ --from mycroft.configuration import LocalConf, SYSTEM_CONFIG -+from mycroft.configuration import Configuration - from mycroft.util.log import LOG - from mycroft.util import (create_daemon, wait_for_exit_signal, - reset_sigint_handler) -@@ -59,8 +59,8 @@ def main(): - only the GUI bus will be started. - """ - # Read the system configuration -- system_config = LocalConf(SYSTEM_CONFIG) -- platform = system_config.get("enclosure", {}).get("platform") -+ config = Configuration.get(remote=False) -+ platform = config.get("enclosure", {}).get("platform") - - enclosure = create_enclosure(platform) - if enclosure: -diff --git a/mycroft/client/enclosure/mark1/__init__.py b/mycroft/client/enclosure/mark1/__init__.py -index 26a7311c791..c02566d3435 100644 ---- a/mycroft/client/enclosure/mark1/__init__.py -+++ b/mycroft/client/enclosure/mark1/__init__.py -@@ -15,8 +15,10 @@ - import subprocess - import time - import sys -+import os - from alsaaudio import Mixer - from threading import Thread, Timer -+from xdg import BaseDirectory - - import serial - -@@ -29,7 +31,7 @@ - from mycroft.client.enclosure.mark1.mouth import EnclosureMouth - from mycroft.enclosure.display_manager import \ - init_display_manager_bus_connection --from mycroft.configuration import Configuration, LocalConf, USER_CONFIG -+from mycroft.configuration import Configuration, LocalConf - from mycroft.messagebus.message import Message - from mycroft.util import play_wav, create_signal, connected, check_for_signal - from mycroft.util.audio_test import record -@@ -163,6 +165,9 @@ def process(self, data): - if "unit.factory-reset" in data: - self.bus.emit(Message("speak", { - 'utterance': mycroft.dialog.get("reset to factory defaults")})) -+ subprocess.call( -+ 'rm ~/.config/mycroft/identity/identity2.json', -+ shell=True) - subprocess.call( - 'rm ~/.mycroft/identity/identity2.json', - shell=True) -@@ -193,7 +198,8 @@ def process(self, data): - - LOG.info("Setting opt_in to: " + word) - new_config = {'opt_in': enable} -- user_config = LocalConf(USER_CONFIG) -+ user_config = LocalConf(os.path.join( -+ BaseDirectory.save_config_path('mycroft'), 'mycroft.conf')) - user_config.merge(new_config) - user_config.store() - -diff --git a/mycroft/client/speech/hotword_factory.py b/mycroft/client/speech/hotword_factory.py -index 32011be0095..f5d7d336026 100644 ---- a/mycroft/client/speech/hotword_factory.py -+++ b/mycroft/client/speech/hotword_factory.py -@@ -26,10 +26,11 @@ - from shutil import rmtree - from threading import Timer, Event, Thread - from urllib.error import HTTPError -+from xdg import BaseDirectory - - from petact import install_package - --from mycroft.configuration import Configuration, LocalConf, USER_CONFIG -+from mycroft.configuration import Configuration, LocalConf - from mycroft.util.log import LOG - - RECOGNIZER_DIR = join(abspath(dirname(__file__)), "recognizer") -@@ -137,7 +138,17 @@ def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): - from precise_runner import ( - PreciseRunner, PreciseEngine, ReadWriteStream - ) -- local_conf = LocalConf(USER_CONFIG) -+ -+ old_path = join(expanduser('~'), './mycroft/mycroft.conf') -+ if isfile(old_path): -+ local_conf = old_path -+ else: -+ for dir in BaseDirectory.load_config_paths('mycroft'): -+ local_conf = LocalConf(join(dir, 'mycroft.conf')) -+ # If the current config contains the precise key use it, -+ # otherwise continue to the next file -+ if local_conf.get('precise', None) is not None: -+ break - if (local_conf.get('precise', {}).get('dist_url') == - 'http://bootstrap.mycroft.ai/artifacts/static/daily/'): - del local_conf['precise']['dist_url'] -@@ -195,7 +206,10 @@ def update_precise(self, precise_config): - - @property - def folder(self): -- return join(expanduser('~'), '.mycroft', 'precise') -+ old_path = join(expanduser('~'), '.mycroft', 'precise') -+ if os.path.isdir(old_path): -+ return old_path -+ return join(BaseDirectory.save_data_path('mycroft', 'precise')) - - @property - def install_destination(self): -@@ -305,8 +319,23 @@ def found_wake_word(self, frame_data): - class PorcupineHotWord(HotWordEngine): - def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"): - super(PorcupineHotWord, self).__init__(key_phrase, config, lang) -+ -+ xdg_data_path = None -+ -+ # Use the old path if available -+ old_path = join(expanduser('~'), '.mycroft', 'Porcupine') -+ if os.path.isdir(old_path): -+ xdg_data_path = old_path -+ -+ # Otherwise use the new XDG config dirs -+ if xdg_data_path is None: -+ for dir in BaseDirectory.load_data_paths('mycroft', 'Porcupine'): -+ if os.path.isdir(dir): -+ xdg_data_path = dir -+ break -+ - porcupine_path = expanduser(self.config.get( -- "porcupine_path", join('~', '.mycroft', 'Porcupine'))) -+ "porcupine_path", xdg_data_path)) - keyword_file_paths = [expanduser(x.strip()) for x in self.config.get( - "keyword_file_path", "hey_mycroft.ppn").split(',')] - sensitivities = self.config.get("sensitivities", 0.5) -diff --git a/mycroft/client/text/text_client.py b/mycroft/client/text/text_client.py -index 44d11d61087..29ae0817a84 100644 ---- a/mycroft/client/text/text_client.py -+++ b/mycroft/client/text/text_client.py -@@ -15,6 +15,7 @@ - import sys - import io - from math import ceil -+from xdg import BaseDirectory - - from .gui_server import start_qml_gui - -@@ -142,7 +143,7 @@ def handleNonAscii(text): - ############################################################################## - # Settings - --config_file = os.path.join(os.path.expanduser("~"), ".mycroft_cli.conf") -+filename = "mycroft_cli.conf" - - - def load_mycroft_config(bus): -@@ -171,6 +172,25 @@ def load_settings(): - global max_log_lines - global show_meter - -+ config_file = None -+ -+ # Old location -+ path = os.path.join(os.path.expanduser("~"), ".mycroft_cli.conf") -+ if os.path.isfile(path): -+ config_file = path -+ -+ # Check XDG_CONFIG_DIR -+ if config_file is None: -+ for dir in BaseDirectory.load_config_paths('mycroft'): -+ file = os.path.join(dir, filename) -+ if os.path.isfile(file): -+ config_file = file -+ break -+ -+ # Check /etc/mycroft -+ if config_file is None: -+ config_file = os.path.join("/etc/mycroft", filename) -+ - try: - with io.open(config_file, 'r') as f: - config = json.load(f) -@@ -196,6 +216,10 @@ def save_settings(): - config["show_last_key"] = show_last_key - config["max_log_lines"] = max_log_lines - config["show_meter"] = show_meter -+ -+ config_file = os.path.join( -+ BaseDirectory.save_config_path("mycroft"), filename) -+ - with io.open(config_file, 'w') as f: - f.write(str(json.dumps(config, ensure_ascii=False))) - -diff --git a/mycroft/configuration/__init__.py b/mycroft/configuration/__init__.py -index da28826c11d..b920d9c8336 100644 ---- a/mycroft/configuration/__init__.py -+++ b/mycroft/configuration/__init__.py -@@ -13,4 +13,3 @@ - # limitations under the License. - # - from .config import Configuration, LocalConf, RemoteConf --from .locations import SYSTEM_CONFIG, USER_CONFIG -diff --git a/mycroft/configuration/config.py b/mycroft/configuration/config.py -index dd82eae651f..0d89e9fb84d 100644 ---- a/mycroft/configuration/config.py -+++ b/mycroft/configuration/config.py -@@ -17,15 +17,14 @@ - import re - import json - import inflection --from os.path import exists, isfile -+from os.path import exists, isfile, join, expanduser, dirname - from requests import RequestException -+from xdg import BaseDirectory - -+from .locations import DEFAULT_CONFIG, USER_CONFIG, SYSTEM_CONFIG - from mycroft.util.json_helper import load_commented_json, merge_dict - from mycroft.util.log import LOG - --from .locations import (DEFAULT_CONFIG, SYSTEM_CONFIG, USER_CONFIG, -- WEB_CONFIG_CACHE) -- - - def is_remote_list(values): - """Check if list corresponds to a backend formatted collection of dicts -@@ -127,7 +126,8 @@ class RemoteConf(LocalConf): - def __init__(self, cache=None): - super(RemoteConf, self).__init__(None) - -- cache = cache or WEB_CONFIG_CACHE -+ cache = cache or join(BaseDirectory.save_cache_path('mycroft'), -+ 'web_cache.json') - from mycroft.api import is_paired - if not is_paired(): - self.load_local(cache) -@@ -173,7 +173,7 @@ class Configuration: - __patch = {} # Patch config that skills can update to override config - - @staticmethod -- def get(configs=None, cache=True): -+ def get(configs=None, cache=True, remote=True): - """Get configuration - - Returns cached instance if available otherwise builds a new -@@ -182,6 +182,9 @@ def get(configs=None, cache=True): - Arguments: - configs (list): List of configuration dicts - cache (boolean): True if the result should be cached -+ remote (boolean): False if the Mycroft Home settings shouldn't -+ be loaded -+ - - Returns: - (dict) configuration dictionary. -@@ -189,23 +192,49 @@ def get(configs=None, cache=True): - if Configuration.__config: - return Configuration.__config - else: -- return Configuration.load_config_stack(configs, cache) -+ return Configuration.load_config_stack(configs, cache, remote) - - @staticmethod -- def load_config_stack(configs=None, cache=False): -+ def load_config_stack(configs=None, cache=False, remote=True): - """Load a stack of config dicts into a single dict - - Arguments: - configs (list): list of dicts to load - cache (boolean): True if result should be cached -- -+ remote (boolean): False if the Mycroft Home settings shouldn't -+ be loaded - Returns: - (dict) merged dict of all configuration files - """ - if not configs: -- configs = [LocalConf(DEFAULT_CONFIG), RemoteConf(), -- LocalConf(SYSTEM_CONFIG), LocalConf(USER_CONFIG), -- Configuration.__patch] -+ configs = [] -+ # Then use XDG config -+ # This includes both the user config and -+ # /etc/xdg/mycroft/mycroft.conf -+ for dir in BaseDirectory.load_config_paths('mycroft'): -+ configs.append(LocalConf(join(dir, 'mycroft.conf'))) -+ -+ # Then check the old user config -+ old_path = join(USER_CONFIG) -+ if isfile(old_path): -+ configs.append(LocalConf(old_path)) -+ -+ # Then use remote config -+ if remote: -+ configs.append(RemoteConf()) -+ -+ # Then use the system config (/etc/mycroft/mycroft.conf) -+ configs.append(LocalConf(SYSTEM_CONFIG)) -+ -+ # Then use the config that comes with the package -+ configs.append(LocalConf(DEFAULT_CONFIG)) -+ -+ # Lastly use patched config -+ configs.append(LocalConf(Configuration.__patch)) -+ -+ # Make sure we reverse the array, as merge_dict will put every new -+ # file on top of the previous one -+ configs = reversed(configs) - else: - # Handle strings in stack - for index, item in enumerate(configs): -diff --git a/mycroft/configuration/locations.py b/mycroft/configuration/locations.py -index cbbaab6ca94..3c4e608670a 100644 ---- a/mycroft/configuration/locations.py -+++ b/mycroft/configuration/locations.py -@@ -13,26 +13,15 @@ - # limitations under the License. - import os - from os.path import join, dirname, expanduser, exists -+from xdg import BaseDirectory - - DEFAULT_CONFIG = join(dirname(__file__), 'mycroft.conf') - SYSTEM_CONFIG = os.environ.get('MYCROFT_SYSTEM_CONFIG', - '/etc/mycroft/mycroft.conf') --USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf') --REMOTE_CONFIG = "mycroft.ai" --WEB_CONFIG_CACHE = os.environ.get('MYCROFT_WEB_CACHE', -- '/var/tmp/mycroft_web_cache.json') -- -- --def __ensure_folder_exists(path): -- """ Make sure the directory for the specified path exists. - -- Arguments: -- path (str): path to config file -- """ -- directory = dirname(path) -- if not exists(directory): -- os.makedirs(directory) -- -- --__ensure_folder_exists(WEB_CONFIG_CACHE) --__ensure_folder_exists(USER_CONFIG) -+# Use the old location if it exists, otherwise use the -+# XDG Base Directory specification -+USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf') -+if not os.path.isfile(USER_CONFIG): -+ USER_CONFIG = join(BaseDirectory.save_config_path('mycroft'), -+ 'mycroft.conf') -diff --git a/mycroft/configuration/mycroft.conf b/mycroft/configuration/mycroft.conf -index 4b5b69ee8be..65360118ad5 100644 ---- a/mycroft/configuration/mycroft.conf -+++ b/mycroft/configuration/mycroft.conf -@@ -5,7 +5,7 @@ - // overridden at the REMOTE level (set by the user via - // https://home.mycroft.ai), at the SYSTEM level (typically in the file - // '/etc/mycroft/mycroft.conf'), or at the USER level (typically in the -- // file '~/.mycroft/mycroft.conf'). -+ // file '~/.config/mycroft/mycroft.conf'). - // - // The load order of settings is: - // DEFAULT -@@ -107,7 +107,7 @@ - }, - "upload_skill_manifest": true, - // Directory to look for user skills -- "directory": "~/.mycroft/skills", -+ "directory": "~/.local/share/mycroft/skills", - // Enable auto update by msm - "auto_update": true, - // blacklisted skills to not load -@@ -210,7 +210,7 @@ - "threshold": 1e-90, - "lang": "en-us" - // Specify custom model via: -- // "local_model_file": "~/.mycroft/precise/models/something.pb" -+ // "local_model_file": "~/.local/share/mycroft/precise/models/something.pb" - // Precise options: - // "sensitivity": 0.5, // Higher = more sensitive - // "trigger_level": 3 // Higher = more delay & less sensitive -@@ -310,7 +310,7 @@ - }, - - "padatious": { -- "intent_cache": "~/.mycroft/intent_cache", -+ "intent_cache": "~/.local/share/mycroft/intent_cache", - "train_delay": 4, - "single_thread": false - }, -diff --git a/mycroft/filesystem/__init__.py b/mycroft/filesystem/__init__.py -index 45ec15a4ac5..8f6b595246f 100644 ---- a/mycroft/filesystem/__init__.py -+++ b/mycroft/filesystem/__init__.py -@@ -14,6 +14,7 @@ - # - import os - from os.path import join, expanduser, isdir -+from xdg import BaseDirectory - - - class FileSystemAccess: -@@ -30,7 +31,12 @@ def __init__(self, path): - def __init_path(path): - if not isinstance(path, str) or len(path) == 0: - raise ValueError("path must be initialized as a non empty string") -- path = join(expanduser('~'), '.mycroft', path) -+ path = join(BaseDirectory.save_config_path('mycroft'), path) -+ -+ # Migrate from the old location if it still exists -+ old_path = join(expanduser('~'), '.mycroft', path) -+ if isdir(old_path): -+ os.rename(old_path, path) - - if not isdir(path): - os.makedirs(path) -diff --git a/mycroft/messagebus/send_func.py b/mycroft/messagebus/send_func.py -index 403db9f45c1..a11a9b0a591 100644 ---- a/mycroft/messagebus/send_func.py -+++ b/mycroft/messagebus/send_func.py -@@ -15,8 +15,6 @@ - from websocket import create_connection - - from mycroft.configuration import Configuration --from mycroft.configuration.locations import (DEFAULT_CONFIG, SYSTEM_CONFIG, -- USER_CONFIG) - from mycroft.messagebus.client import MessageBusClient - from mycroft.messagebus.message import Message - -@@ -32,10 +30,7 @@ def send(message_to_send, data_to_send=None): - data_to_send = data_to_send or {} - - # Calculate the standard Mycroft messagebus websocket address -- config = Configuration.get([DEFAULT_CONFIG, -- SYSTEM_CONFIG, -- USER_CONFIG], -- cache=False) -+ config = Configuration.get(cache=False, remote=False) - config = config.get("websocket") - url = MessageBusClient.build_url( - config.get("host"), -diff --git a/mycroft/skills/event_scheduler.py b/mycroft/skills/event_scheduler.py -index fe41ac1bedc..cb1c9f3c61d 100644 ---- a/mycroft/skills/event_scheduler.py -+++ b/mycroft/skills/event_scheduler.py -@@ -20,6 +20,7 @@ - from datetime import datetime, timedelta - from threading import Thread, Lock - from os.path import isfile, join, expanduser -+from xdg import BaseDirectory - - from mycroft.configuration import Configuration - from mycroft.messagebus.message import Message -@@ -54,14 +55,19 @@ class EventScheduler(Thread): - """ - def __init__(self, bus, schedule_file='schedule.json'): - super().__init__() -- data_dir = expanduser(Configuration.get()['data_dir']) - - self.events = {} - self.event_lock = Lock() - - self.bus = bus - self.is_running = True -- self.schedule_file = join(data_dir, schedule_file) -+ old_path = join(expanduser(Configuration.get()['data_dir']), -+ schedule_file) -+ if isfile(old_path): -+ self.schedule_file = old_path -+ else: -+ self.schedule_file = join( -+ BaseDirectory.load_first_config('mycroft'), schedule_file) - if self.schedule_file: - self.load() - -diff --git a/mycroft/skills/skill_updater.py b/mycroft/skills/skill_updater.py -index 9535ad90319..e784f23b047 100644 ---- a/mycroft/skills/skill_updater.py -+++ b/mycroft/skills/skill_updater.py -@@ -17,6 +17,7 @@ - import sys - from datetime import datetime - from time import time -+from xdg import BaseDirectory - - from msm import MsmException - -@@ -91,9 +92,9 @@ def installed_skills_file_path(self): - '.mycroft-skills' - ) - else: -- self._installed_skills_file_path = os.path.expanduser( -- '~/.mycroft/.mycroft-skills' -- ) -+ self._installed_skills_file_path = os.path.join( -+ BaseDirectory.save_data_path('mycroft', -+ 'skills')) - - return self._installed_skills_file_path - -diff --git a/mycroft/util/file_utils.py b/mycroft/util/file_utils.py -index 84555fc3bb3..7c09fd226ee 100644 ---- a/mycroft/util/file_utils.py -+++ b/mycroft/util/file_utils.py -@@ -22,6 +22,7 @@ - import psutil - from stat import S_ISREG, ST_MTIME, ST_MODE, ST_SIZE - import tempfile -+from xdg import BaseDirectory - - import mycroft.configuration - from .log import LOG -@@ -33,15 +34,15 @@ def resolve_resource_file(res_name): - Resource names are in the form: 'filename.ext' - or 'path/filename.ext' - -- The system wil look for ~/.mycroft/res_name first, and -- if not found will look at /opt/mycroft/res_name, -- then finally it will look for res_name in the 'mycroft/res' -- folder of the source code package. -+ The system wil look for $XDG_DATA_DIRS/mycroft/res_name first -+ (defaults to ~/.local/share/mycroft/res_name), and if not found will -+ look at /opt/mycroft/res_name, then finally it will look for res_name -+ in the 'mycroft/res' folder of the source code package. - - Example: - With mycroft running as the user 'bob', if you called - resolve_resource_file('snd/beep.wav') -- it would return either '/home/bob/.mycroft/snd/beep.wav' or -+ it would return either '/home/bob/.local/share/mycroft/snd/beep.wav' or - '/opt/mycroft/snd/beep.wav' or '.../mycroft/res/snd/beep.wav', - where the '...' is replaced by the path where the package has - been installed. -@@ -57,8 +58,14 @@ def resolve_resource_file(res_name): - if os.path.isfile(res_name): - return res_name - -- # Now look for ~/.mycroft/res_name (in user folder) -- filename = os.path.expanduser("~/.mycroft/" + res_name) -+ # Now look for XDG_DATA_DIRS -+ for dir in BaseDirectory.load_data_paths('mycroft'): -+ filename = os.path.join(dir, res_name) -+ if os.path.isfile(filename): -+ return filename -+ -+ # Now look in the old user location -+ filename = os.path.join(os.path.expanduser('~'), '.mycroft', res_name) - if os.path.isfile(filename): - return filename - -diff --git a/mycroft/util/log.py b/mycroft/util/log.py -index 0ea391f8f79..788f6df1c37 100644 ---- a/mycroft/util/log.py -+++ b/mycroft/util/log.py -@@ -21,7 +21,7 @@ - for use. - - The default log level of the logger created here can ONLY be set in --/etc/mycroft/mycroft.conf or ~/.mycroft/mycroft.conf -+/etc/mycroft/mycroft.conf or ~/.config/mycroft/mycroft.conf - - The default log level can also be programatically be changed by setting the - LOG.level parameter. -@@ -31,10 +31,10 @@ - import logging - import sys - --from os.path import isfile -+from os.path import isfile, join -+from xdg import BaseDirectory - - from mycroft.util.json_helper import load_commented_json, merge_dict --from mycroft.configuration.locations import SYSTEM_CONFIG, USER_CONFIG - - - def getLogger(name="MYCROFT"): -@@ -84,7 +84,10 @@ def init(cls): - # Check configs manually, the Mycroft configuration system can't be - # used since it uses the LOG system and would cause horrible cyclic - # dependencies. -- confs = [SYSTEM_CONFIG, USER_CONFIG] -+ confs = [] -+ for dir in BaseDirectory.load_config_paths('mycroft'): -+ confs.append(join(dir, 'mycroft.conf')) -+ confs.append('/etc/mycroft/mycroft.conf') - config = {} - for conf in confs: - try: -diff --git a/test/unittests/skills/test_skill_updater.py b/test/unittests/skills/test_skill_updater.py -index 38d4083d7f2..fbcc9254319 100644 ---- a/test/unittests/skills/test_skill_updater.py -+++ b/test/unittests/skills/test_skill_updater.py -@@ -13,8 +13,9 @@ - # limitations under the License. - # - """Unit tests for the SkillUpdater class.""" --from os import path -+import os - from time import sleep -+from xdg import BaseDirectory - from unittest.mock import Mock, patch, PropertyMock - - from mycroft.skills.skill_updater import SkillUpdater -@@ -143,7 +144,8 @@ def test_installed_skills_path_not_virtual_env(self): - os_patch.return_value = False - updater = SkillUpdater(self.message_bus_mock) - self.assertEqual( -- path.expanduser('~/.mycroft/.mycroft-skills'), -+ os.path.join(BaseDirectory.save_data_path('mycroft'), -+ 'skills'), - updater.installed_skills_file_path - ) - -diff --git a/test/unittests/util/commented.json b/test/unittests/util/commented.json -index 87c7d3e2c2d..00a581f6df4 100644 ---- a/test/unittests/util/commented.json -+++ b/test/unittests/util/commented.json -@@ -54,7 +54,7 @@ - } - }, - "skills": { -- "directory": "~/.mycroft/skills" -+ "directory": "~/.local/share/mycroft/skills" - }, - "server": { - "url": "https://api.mycroft.ai", -diff --git a/test/unittests/util/plain.json b/test/unittests/util/plain.json -index f8c474139ce..eec84631d88 100644 ---- a/test/unittests/util/plain.json -+++ b/test/unittests/util/plain.json -@@ -36,7 +36,7 @@ - } - }, - "skills": { -- "directory": "~/.mycroft/skills" -+ "directory": "~/.local/share/mycroft/skills" - }, - "server": { - "url": "https://api.mycroft.ai", -diff --git a/test/util.py b/test/util.py -index f80c0f9bd40..6a6e31bcc85 100644 ---- a/test/util.py -+++ b/test/util.py -@@ -1,5 +1,8 @@ --from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG -+from os.path import join, dirname -+from mycroft.configuration.locations import DEFAULT_CONFIG -+from mycroft.configuration.config import LocalConf - from copy import deepcopy -+from xdg import BaseDirectory - - __config = LocalConf(DEFAULT_CONFIG) - diff --git a/community/mycroft-core/0002-system-wide-setups.patch b/community/mycroft-core/0002-system-wide-setups.patch new file mode 100644 index 00000000000..7a69ae9cfdb --- /dev/null +++ b/community/mycroft-core/0002-system-wide-setups.patch @@ -0,0 +1,402 @@ +From 51820329b69fa37423474aecf8c70d731452dea2 Mon Sep 17 00:00:00 2001 +From: Bart Ribbers +Date: Fri, 15 Jan 2021 12:59:25 +0100 +Subject: [PATCH 1/2] Replace mycroft-{start,stop} with scripts that can launch + properly installed setups + +These scripts will work with system-wide setups +(/usr/bin/mycroft-start), user setups (~/.local/bin/mycroft-start) and +virtual environments (.venv/bin/mycroft-start). + +A big benefit is that they don't care where they're installed. They'll +launch from a virtual environment, user setups or system-wide setup, in +that order. + +Also make sure these scripts are actually installed by setup.py. + +These changes should make it possible to create a PyPi package +installable with pip. +--- + bin/mycroft-start | 157 ++++++++++++++++++++++++++++++++++++++++++++-- + bin/mycroft-stop | 109 ++++++++++++++++++++++++++++++-- + setup.py | 6 +- + 3 files changed, 261 insertions(+), 11 deletions(-) + +diff --git a/bin/mycroft-start b/bin/mycroft-start +index 65723c2c373..36ddc9fcbe6 100755 +--- a/bin/mycroft-start ++++ b/bin/mycroft-start +@@ -1,4 +1,4 @@ +-#!/usr/bin/env bash ++#!/bin/sh + + # Copyright 2019 Mycroft AI Inc. + # +@@ -14,8 +14,155 @@ + # See the License for the specific language governing permissions and + # limitations under the License. + +-SOURCE="${BASH_SOURCE[0]}" +-cd -P "$( dirname "$SOURCE" )"/.. +-DIR="$( pwd )" ++script=${0} ++script=${script##*/} + +-. "$DIR/start-mycroft.sh" $@ ++help() { ++ echo "${script}: Mycroft command/service launcher" ++ echo "usage: ${script} [COMMAND] [restart] [params]" ++ echo ++ echo "Services COMMANDs:" ++ echo " all runs core services: bus, audio, skills, voice" ++ echo " debug runs core services, then starts the CLI" ++ echo " audio the audio playback service" ++ echo " bus the messagebus service" ++ echo " skills the skill service" ++ echo " voice voice capture service" ++ echo " enclosure mark_1 enclosure service" ++ echo ++ echo "Tool COMMANDs:" ++ echo " cli the Command Line Interface" ++ echo ++ echo "Options:" ++ echo " restart (optional) Force the service to restart if running" ++ echo ++ echo "Examples:" ++ echo " ${script} all" ++ echo " ${script} all restart" ++ echo " ${script} bus" ++ echo " ${script} voice" ++ ++ exit 1 ++} ++ ++name_to_script_path() { ++ case ${1} in ++ "bus") _module="mycroft.messagebus.service" ;; ++ "skills") _module="mycroft.skills" ;; ++ "audio") _module="mycroft.audio" ;; ++ "voice") _module="mycroft.client.speech" ;; ++ "cli") _module="mycroft.client.text" ;; ++ "enclosure") _module="mycroft.client.enclosure" ;; ++ ++ *) ++ echo "Error: Unknown name '${1}'" ++ exit 1 ++ esac ++} ++ ++require_process() { ++ name_to_script_path "${1}" ++ if ! pgrep -f "python3 (.*)-m ${_module}" > /dev/null; then ++ launch_background "${1}" ++ fi ++} ++ ++launch_process() { ++ name_to_script_path "${1}" ++ ++ # Luanch process in foreground ++ echo "Starting $1" ++ python3 -m ${_module} "$_params" ++} ++ ++launch_background() { ++ name_to_script_path "${1}" ++ ++ if pgrep -f "python3 (.*)-m ${_module}" > /dev/null; then ++ if ($_force_restart); then ++ echo "Restarting: ${1}" ++ mycroft-stop "${1}" ++ else ++ # Already running, no need to restart ++ return ++ fi ++ else ++ echo "Starting background service $1" ++ fi ++ ++ # Security warning/reminder for the user ++ if [ "${1}" = "bus" ] ; then ++ echo "CAUTION: The Mycroft bus is an open websocket with no built-in security" ++ echo " measures. You are responsible for protecting the local port" ++ echo " 8181 with a firewall as appropriate." ++ fi ++ ++ # Launch process in background ++ # Send logs to XDG Base Directories cache location ++ if [ -n "${XDG_CACHE_HOME+x}" ]; then ++ logdir="$XDG_CACHE_HOME/mycroft" ++ else ++ logdir="$HOME/.cache/mycroft" ++ fi ++ ++ if [ ! -d "$logdir" ]; then ++ mkdir -p "$logdir" ++ fi ++ ++ python3 -m ${_module} "$_params" >> "$logdir/${1}.log" 2>&1 & ++} ++ ++launch_all() { ++ echo "Starting all mycroft-core services" ++ launch_background bus ++ launch_background skills ++ launch_background audio ++ launch_background voice ++ launch_background enclosure ++} ++ ++_opt=$1 ++_force_restart=false ++shift ++if [ "${1}" = "restart" ] || [ "${_opt}" = "restart" ]; then ++ _force_restart=true ++ if [ "${_opt}" = "restart" ]; then ++ # Support "start-mycroft restart all" as well as "start-mycroft all restart" ++ _opt=$1 ++ fi ++ shift ++fi ++_params=$* ++ ++case ${_opt} in ++ "all") ++ launch_all ++ ;; ++ "bus") ++ launch_background "${_opt}" ++ ;; ++ "audio") ++ launch_background "${_opt}" ++ ;; ++ "skills") ++ launch_background "${_opt}" ++ ;; ++ "voice") ++ launch_background "${_opt}" ++ ;; ++ "debug") ++ launch_all ++ launch_process cli ++ ;; ++ "cli") ++ require_process bus ++ require_process skills ++ launch_process "${_opt}" ++ ;; ++ "enclosure") ++ launch-background "${_opt}" ++ ;; ++ *) ++ help ++ ;; ++esac +diff --git a/bin/mycroft-stop b/bin/mycroft-stop +index b86b0ea6557..289c736959a 100755 +--- a/bin/mycroft-stop ++++ b/bin/mycroft-stop +@@ -1,4 +1,4 @@ +-#!/usr/bin/env bash ++#!/bin/sh + + # Copyright 2019 Mycroft AI Inc. + # +@@ -14,8 +14,107 @@ + # See the License for the specific language governing permissions and + # limitations under the License. + +-SOURCE="${BASH_SOURCE[0]}" +-cd -P "$( dirname "$SOURCE" )"/.. +-DIR="$( pwd )" ++script=${0} ++script=${script##*/} + +-. "$DIR/stop-mycroft.sh" $@ ++help() { ++ echo "${script}: Mycroft service stopper" ++ echo "usage: ${script} [service]" ++ echo ++ echo "Service:" ++ echo " all ends core services: bus, audio, skills, voice" ++ echo " (none) same as \"all\"" ++ echo " bus stop the Mycroft messagebus service" ++ echo " audio stop the audio playback service" ++ echo " skills stop the skill service" ++ echo " voice stop voice capture service" ++ echo " enclosure stop enclosure (hardware/gui interface) service" ++ echo ++ echo "Examples:" ++ echo " ${script}" ++ echo " ${script} audio" ++ ++ exit 0 ++} ++ ++process_running() { ++ if [ "$( pgrep -f "python3 (.*)-m mycroft.*${1}" )" ]; then ++ return 0 ++ else ++ return 1 ++ fi ++} ++ ++end_process() { ++ if process_running "$1"; then ++ # Find the process by name, only returning the oldest if it has children ++ pid=$( pgrep -o -f "python3 (.*)-m mycroft.*${1}" ) ++ echo "Stopping $1 (${pid})..." ++ kill -SIGINT "${pid}" ++ ++ # Wait up to 5 seconds (50 * 0.1) for process to stop ++ c=1 ++ while [ $c -le 50 ]; do ++ if process_running "$1"; then ++ sleep 0.1 ++ c=$((c + 1)) ++ else ++ c=999 # end loop ++ fi ++ done ++ ++ if process_running "$1"; then ++ echo "Failed to stop." ++ pid=$( pgrep -o -f "python3 (.*)-m mycroft.*${1}" ) ++ echo " Killing $1 (${pid})..." ++ kill -9 "${pid}" ++ echo "Killed." ++ result=120 ++ else ++ echo "Stopped." ++ if [ $result -eq 0 ] ; then ++ result=100 ++ fi ++ fi ++ fi ++} ++ ++result=0 # default, no change ++ ++OPT=$1 ++shift ++ ++case ${OPT} in ++ "all"|"") ++ echo "Stopping all mycroft-core services" ++ end_process "skills" ++ end_process "audio" ++ end_process "speech" ++ end_process "enclosure" ++ end_process "messagebus.service" ++ ;; ++ "bus") ++ end_process "messagebus.service" ++ ;; ++ "audio") ++ end_process "audio" ++ ;; ++ "skills") ++ end_process "skills" ++ ;; ++ "voice") ++ end_process "speech" ++ ;; ++ "enclosure") ++ end_process "enclosure" ++ ;; ++ *) ++ help ++ ;; ++esac ++ ++# Exit codes: ++# 0 if nothing changed (e.g. --help or no process was running) ++# 100 at least one process was stopped ++# 120 if any process had to be killed ++exit $result +diff --git a/setup.py b/setup.py +index 963c503e4d2..89eefa496fc 100644 +--- a/setup.py ++++ b/setup.py +@@ -80,5 +80,9 @@ def required(requirements_file): + 'mycroft-enclosure-client=mycroft.client.enclosure.__main__:main', + 'mycroft-cli-client=mycroft.client.text.__main__:main' + ] +- } ++ }, ++ scripts=[ ++ 'bin/mycroft-start', ++ 'bin/mycroft-stop' ++ ] + ) + +From befd8a1d0a849ff2ccaf2f58e79ffe4d339882c2 Mon Sep 17 00:00:00 2001 +From: Bart Ribbers +Date: Fri, 15 Jan 2021 13:18:35 +0100 +Subject: [PATCH 2/2] Update README to reflect properly installed setups + +--- + README.md | 38 +++++++++++++++++++++++++++----------- + 1 file changed, 27 insertions(+), 11 deletions(-) + +diff --git a/README.md b/README.md +index 1665b0a68dd..9de90003ca7 100644 +--- a/README.md ++++ b/README.md +@@ -30,29 +30,45 @@ Mycroft is a hackable open source voice assistant. + + # Getting Started + +-First, get the code on your system! The simplest method is via git ([git installation instructions](https://gist.github.com/derhuerst/1b15ff4652a867391f03)): +-- `cd ~/` +-- `git clone https://github.com/MycroftAI/mycroft-core.git` +-- `cd mycroft-core` +-- `bash dev_setup.sh` ++Mycroft might be packaged by your distribution already, in that case installing it might be as simple as `apk add mycroft-core` or equivalent for your distribution. ++Otherwise, the simplest method is downloading the latest release on the [Github releases page](https://github.com/MycroftAI/mycroft-core/releases) and unpacking it somewhere. ++Then run `python3 setup.py install` in the unpacked directory. + ++For development on Mycroft it's recommended to use Git instead ([git installation instructions](https://gist.github.com/derhuerst/1b15ff4652a867391f03)). ++ ++```sh ++cd ~/ ++git clone https://github.com/MycroftAI/mycroft-core.git ++cd mycroft-core ++./dev_setup.sh ++``` + + This script sets up dependencies and a [virtualenv][about-virtualenv]. If running in an environment besides Ubuntu/Debian, Arch or Fedora you may need to manually install packages as instructed by dev_setup.sh. + + [about-virtualenv]:https://virtualenv.pypa.io/en/stable/ + +-NOTE: The default branch for this repository is 'dev', which should be considered a work-in-progress. If you want to clone a more stable version, switch over to the 'master' branch. ++**NOTE:** The default branch for this repository is 'dev', which should be considered a work-in-progress. If you want to clone a more stable version, switch over to the 'master' branch. + + # Running Mycroft + +-Mycroft provides `start-mycroft.sh` to perform common tasks. This script uses a virtualenv created by `dev_setup.sh`. Assuming you installed mycroft-core in your home directory run: +-- `cd ~/mycroft-core` +-- `./start-mycroft.sh debug` ++Mycroft provides `mycroft-start` to perform common tasks. Assuming you installed mycroft-core via your systems package manager or via `setup.py`: ++ ++```sh ++mycroft-start debug ++``` + +-The "debug" command will start the background services (microphone listener, skill, messagebus, and audio subsystems) as well as bringing up a text-based Command Line Interface (CLI) you can use to interact with Mycroft and see the contents of the various logs. Alternatively you can run `./start-mycroft.sh all` to begin the services without the command line interface. Later you can bring up the CLI using `./start-mycroft.sh cli`. ++The "debug" command will start the background services (microphone listener, skill, messagebus, and audio subsystems) as well as bringing up a text-based Command Line Interface (CLI) you can use to interact with Mycroft and see the contents of the various logs. ++Alternatively you can run `mycroft-start all` to begin the services without the command line interface. ++Later you can bring up the CLI using `mycroft-start cli`. + + The background services can be stopped as a group with: +-- `./stop-mycroft.sh` ++ ++```sh ++mycroft-stop ++``` ++ ++If you want to develop for Mycroft, please use `start-mycroft.sh` and `stop-mycroft.sh` instead of the aforementioned commands. ++These provide extra options for development purposes. + + # Using Mycroft + diff --git a/community/mycroft-core/0003-skills-from-xdg.patch b/community/mycroft-core/0003-skills-from-xdg.patch new file mode 100644 index 00000000000..60c147f779d --- /dev/null +++ b/community/mycroft-core/0003-skills-from-xdg.patch @@ -0,0 +1,220 @@ +From b1da87f6edcdb94c198d52af1ed566c0ccf536a7 Mon Sep 17 00:00:00 2001 +From: Bart Ribbers +Date: Fri, 15 Jan 2021 16:29:09 +0100 +Subject: [PATCH] Read skills from XDG home directory + +Also move over skills from data_dir if they still exist +--- + mycroft/configuration/mycroft.conf | 4 +--- + mycroft/skills/msm_wrapper.py | 13 +++++-------- + mycroft/skills/mycroft_skill/mycroft_skill.py | 2 +- + mycroft/skills/settings.py | 2 +- + mycroft/skills/skill_manager.py | 9 +++++++-- + mycroft/skills/skill_updater.py | 4 +++- + pytest.ini | 2 ++ + requirements/tests.txt | 1 + + test/unittests/base.py | 3 +++ + test/unittests/skills/test_skill_manager.py | 8 +++++--- + 10 files changed, 29 insertions(+), 19 deletions(-) + +diff --git a/mycroft/skills/msm_wrapper.py b/mycroft/skills/msm_wrapper.py +index 4f579f85ac5..27753c678ab 100644 +--- a/mycroft/skills/msm_wrapper.py ++++ b/mycroft/skills/msm_wrapper.py +@@ -22,6 +22,7 @@ + from collections import namedtuple + from functools import lru_cache + from os import path, makedirs ++from xdg import BaseDirectory + + from msm import MycroftSkillsManager, SkillRepo + +@@ -33,9 +34,8 @@ + [ + 'platform', + 'repo_branch', +- 'repo_cache', + 'repo_url', +- 'skills_dir', ++ 'old_skills_dir', + 'versioned' + ] + ) +@@ -70,9 +70,8 @@ def build_msm_config(device_config: dict) -> MsmConfig: + return MsmConfig( + platform=enclosure_config.get('platform', 'default'), + repo_branch=msm_repo_config['branch'], +- repo_cache=path.join(data_dir, msm_repo_config['cache']), + repo_url=msm_repo_config['url'], +- skills_dir=path.join(data_dir, msm_config['directory']), ++ old_skills_dir=path.join(data_dir, msm_config['directory']), + versioned=msm_config['versioned'] + ) + +@@ -94,17 +93,15 @@ def create_msm(msm_config: MsmConfig) -> MycroftSkillsManager: + msm_lock = _init_msm_lock() + LOG.info('Acquiring lock to instantiate MSM') + with msm_lock: +- if not path.exists(msm_config.skills_dir): +- makedirs(msm_config.skills_dir) ++ BaseDirectory.save_data_path('mycroft/skills') + + msm_skill_repo = SkillRepo( +- msm_config.repo_cache, + msm_config.repo_url, + msm_config.repo_branch + ) + msm_instance = MycroftSkillsManager( + platform=msm_config.platform, +- skills_dir=msm_config.skills_dir, ++ old_skills_dir=msm_config.old_skills_dir, + repo=msm_skill_repo, + versioned=msm_config.versioned + ) +diff --git a/mycroft/skills/mycroft_skill/mycroft_skill.py b/mycroft/skills/mycroft_skill/mycroft_skill.py +index c75a8a9b5fa..302c87eae7d 100644 +--- a/mycroft/skills/mycroft_skill/mycroft_skill.py ++++ b/mycroft/skills/mycroft_skill/mycroft_skill.py +@@ -124,7 +124,7 @@ def __init__(self, name=None, bus=None, use_settings=True): + + # Get directory of skill + #: Member variable containing the absolute path of the skill's root +- #: directory. E.g. /opt/mycroft/skills/my-skill.me/ ++ #: directory. E.g. $XDG_DATA_HOME/mycroft/skills/my-skill.me/ + self.root_dir = dirname(abspath(sys.modules[self.__module__].__file__)) + + self.gui = SkillGUI(self) +diff --git a/mycroft/skills/settings.py b/mycroft/skills/settings.py +index c48416afac0..6e70783df0c 100644 +--- a/mycroft/skills/settings.py ++++ b/mycroft/skills/settings.py +@@ -99,7 +99,7 @@ def save_settings(skill_dir, skill_settings): + """Save skill settings to file.""" + settings_path = Path(skill_dir).joinpath('settings.json') + +- # Either the file already exists in /opt, or we are writing ++ # Either the file already exists or we are writing + # to XDG_CONFIG_DIR and always have the permission to make + # sure the file always exists + if not Path(settings_path).exists(): +diff --git a/mycroft/skills/skill_manager.py b/mycroft/skills/skill_manager.py +index b76c555600a..7b1dada8cc8 100644 +--- a/mycroft/skills/skill_manager.py ++++ b/mycroft/skills/skill_manager.py +@@ -17,6 +17,8 @@ + from glob import glob + from threading import Thread, Event, Lock + from time import sleep, time, monotonic ++import shutil ++from xdg import BaseDirectory + + from mycroft.api import is_paired + from mycroft.enclosure.api import EnclosureAPI +@@ -262,7 +264,9 @@ def run(self): + + def _remove_git_locks(self): + """If git gets killed from an abrupt shutdown it leaves lock files.""" +- for i in glob(os.path.join(self.msm.skills_dir, '*/.git/index.lock')): ++ for i in glob(os.path.join( ++ BaseDirectory.save_data_path('mycroft/skills'), ++ '*/.git/index.lock')): + LOG.warning('Found and removed git lock file: ' + i) + os.remove(i) + +@@ -308,7 +312,8 @@ def _load_skill(self, skill_directory): + return skill_loader if load_status else None + + def _get_skill_directories(self): +- skill_glob = glob(os.path.join(self.msm.skills_dir, '*/')) ++ skill_glob = glob(os.path.join( ++ BaseDirectory.save_data_path('mycroft/skills'), '*/')) + + skill_directories = [] + for skill_dir in skill_glob: +diff --git a/mycroft/skills/skill_updater.py b/mycroft/skills/skill_updater.py +index ace247e2db4..3e7cc9e0b77 100644 +--- a/mycroft/skills/skill_updater.py ++++ b/mycroft/skills/skill_updater.py +@@ -53,7 +54,8 @@ def __init__(self, bus=None): + self.config = Configuration.get() + update_interval = self.config['skills']['update_interval'] + self.update_interval = int(update_interval) * ONE_HOUR +- self.dot_msm_path = os.path.join(self.msm.skills_dir, '.msm') ++ self.dot_msm_path = os.path.join( ++ BaseDirectory.save_data_path('mycroft/skills'), '.msm') + self.next_download = self._determine_next_download_time() + self._log_next_download_time() + self.installed_skills = set() +diff --git a/pytest.ini b/pytest.ini +index 6634fabcb06..92780db4d40 100644 +--- a/pytest.ini ++++ b/pytest.ini +@@ -1,3 +1,5 @@ + [pytest] + testpaths = test + norecursedirs = wake_word ++env = ++ XDG_DATA_HOME=/tmp/mycroft-test +diff --git a/requirements/tests.txt b/requirements/tests.txt +index 9e038123e51..3d2e2b9a4c9 100644 +--- a/requirements/tests.txt ++++ b/requirements/tests.txt +@@ -2,6 +2,7 @@ coveralls==1.8.2 + flake8==3.7.9 + pytest==5.2.4 + pytest-cov==2.8.1 ++pytest-env==0.6.2 + cov-core==1.15.0 + sphinx==2.2.1 + sphinx-rtd-theme==0.4.3 +diff --git a/test/unittests/base.py b/test/unittests/base.py +index fed93941769..ee86778fa10 100644 +--- a/test/unittests/base.py ++++ b/test/unittests/base.py +@@ -18,6 +18,8 @@ + from unittest import TestCase + from unittest.mock import patch + ++from xdg import BaseDirectory ++ + from .mocks import mock_msm, mock_config, MessageBusMock + + +@@ -54,3 +56,4 @@ def _mock_log(self): + + def tearDown(self): + rmtree(str(self.temp_dir)) ++ rmtree(BaseDirectory.save_data_path('mycroft')) +diff --git a/test/unittests/skills/test_skill_manager.py b/test/unittests/skills/test_skill_manager.py +index f2bdde3fa46..8de8168be14 100644 +--- a/test/unittests/skills/test_skill_manager.py ++++ b/test/unittests/skills/test_skill_manager.py +@@ -13,6 +13,8 @@ + # limitations under the License. + # + from os import path ++from pathlib import Path ++from xdg import BaseDirectory + from unittest import TestCase + from unittest.mock import Mock, patch + +@@ -90,7 +92,8 @@ def _mock_skill_updater(self): + self.skill_updater_mock = skill_updater_patch.start() + + def _mock_skill_loader_instance(self): +- self.skill_dir = self.temp_dir.joinpath('test_skill') ++ self.skill_dir = (Path(BaseDirectory.save_data_path('mycroft/skills')) ++ .joinpath('test_skill')) + self.skill_loader_mock = Mock(spec=SkillLoader) + self.skill_loader_mock.instance = Mock() + self.skill_loader_mock.instance.default_shutdown = Mock() +@@ -125,8 +128,7 @@ def test_instantiate(self): + ) + + def test_remove_git_locks(self): +- git_dir = self.temp_dir.joinpath('foo/.git') +- git_dir.mkdir(parents=True) ++ git_dir = Path(BaseDirectory.save_data_path('mycroft/skills/foo/.git')) + git_lock_file_path = str(git_dir.joinpath('index.lock')) + with open(git_lock_file_path, 'w') as git_lock_file: + git_lock_file.write('foo') diff --git a/community/mycroft-core/APKBUILD b/community/mycroft-core/APKBUILD index fa771bc2dde..4e0cdede1ec 100644 --- a/community/mycroft-core/APKBUILD +++ b/community/mycroft-core/APKBUILD @@ -2,7 +2,7 @@ # Maintainer: Bart Ribbers pkgname=mycroft-core pkgver=20.8.0 -pkgrel=4 +pkgrel=5 pkgdesc="Mycroft Core, the Mycroft Artificial Intelligence platform" url="https://mycroft.ai/" # mips, mips64 and s390x blocked by py3-precise-runner @@ -58,11 +58,10 @@ makedepends="py3-setuptools" checkdepends="py3-pytest py3-wheel py3-vlc" install="$pkgname.post-install" source="$pkgname-$pkgver.tar.gz::https://github.com/MycroftAI/mycroft-core/archive/release/v$pkgver.tar.gz - mycroft.conf - start-mycroft.sh - stop-mycroft.sh profile.sh - 0001-xdg.patch + 0001-xdg-settings-cache-and-runtime-data.patch + 0002-system-wide-setups.patch + 0003-skills-from-xdg.patch " # Net is required for tests # Some tests are broken still, will be enabled later @@ -82,15 +81,10 @@ check() { package() { MYCROFT_LOOSE_REQUIREMENTS=1 python3 setup.py install --prefix=/usr --root="$pkgdir" - install -Dm644 "$srcdir"/mycroft.conf "$pkgdir"/etc/mycroft/mycroft.conf - - install -Dm755 "$srcdir"/start-mycroft.sh "$pkgdir"/usr/bin/start-mycroft - install -Dm755 "$srcdir"/stop-mycroft.sh "$pkgdir"/usr/bin/stop-mycroft install -Dm644 "$srcdir"/profile.sh "$pkgdir"/etc/profile.d/mycroft.sh } sha512sums="5e86ee27aa9736b61f49f34ae14669ae453d0609d63443e29b8c027327f87a4495d10fec866f923862cef226da803bb55c45537d0b7bdad57c452b55acb9addc mycroft-core-20.8.0.tar.gz -c852bf37c3588a3f65f55b65af0e55440e13aeeaca522e7029a7326ec58c9cf053d14c7c3376a952b65512cabe3437ba6701f1e0e0e4971d6b5ada159bacd57a mycroft.conf -489687c94bfeeec03821afee13db8d4104a3c43f574a35751c26941f9b885049c1fe16e496151ab5cde0679d357a54e370d0f98b6dddb9ced3e50f49d79c1b3a start-mycroft.sh -66198ec833df7d338705b68b70348c62aca83e23d1d59fdf7261d2924e372a3c423fa5c1ca68cd30d92b2e7fc7c0c4293087a2f7d087fcab1698104671fa7550 stop-mycroft.sh -a0f8456a1be1dff2ce67a18e9464cfaf823d90987e6d85f0baa5c7ba17c72972bffe759701bc3ba5950d454ffbba40a6e5165c15e5e924cf70459f20de9f7daf profile.sh -33b4dbc733e741343fae9f573ef206a4d698e944946818f8181b49aece3bcfdef0a683ff5e1f592379ada2beef8a4ada1a536046dee64792d78f0677b3d9a545 0001-xdg.patch" +c3d1a605a0b574c8e2c4031f592bdbf023f5ed9b2e1ba0cea38cf79278331f245dbe4e220e7f81de73fe612ffd722253805058dae04ba89c3d01c361b329e4ef profile.sh +9c3d4210aca3eef36fadcd112fc053ea7a26632520b63e49347cb253471afa5bbee8d34e0c942c67c7a3b65ffffbc70d316d38ae8af7f5ae52e5af3bf6e73ca4 0001-xdg-settings-cache-and-runtime-data.patch +861269f037c5090da03caf9782be7fabd1381e46fd3bb33b726befbbf12788b7ddc3aec08beeea23a9e7b78ca0c43286ed179746c1b715880f8447ad86c4e747 0002-system-wide-setups.patch +987c3041482a2adfa4e99228b8670f381692ace6dbf3efbedeb06c95ebcc6274b50510a19cf5f9eadb73e23344a4d1256771fc6a656748ba36dfe97767140bef 0003-skills-from-xdg.patch" diff --git a/community/mycroft-core/mycroft.conf b/community/mycroft-core/mycroft.conf deleted file mode 100644 index ff8e493d4ca..00000000000 --- a/community/mycroft-core/mycroft.conf +++ /dev/null @@ -1,6 +0,0 @@ -{ - "data_dir": "/usr/share/mycroft", - "skills": { - "auto_update": false - } -} diff --git a/community/mycroft-core/profile.sh b/community/mycroft-core/profile.sh index 99c44fb8b4d..4765d018c0e 100644 --- a/community/mycroft-core/profile.sh +++ b/community/mycroft-core/profile.sh @@ -1,2 +1,2 @@ -export MYCROFT_START_CMD="start-mycroft all" -export MYCROFT_STOP_CMD="stop-mycroft all" +export MYCROFT_START_CMD="mycroft-start all" +export MYCROFT_STOP_CMD="mycroft-stop all" diff --git a/community/mycroft-core/start-mycroft.sh b/community/mycroft-core/start-mycroft.sh deleted file mode 100755 index bab1d5ed671..00000000000 --- a/community/mycroft-core/start-mycroft.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/sh - -script=${0} -script=${script##*/} - -help() { - echo "${script}: Mycroft command/service launcher" - echo "usage: ${script} [COMMAND] [restart] [params]" - echo - echo "Services COMMANDs:" - echo " all runs core services: bus, audio, skills, voice" - echo " audio the audio playback service" - echo " bus the messagebus service" - echo " skills the skill service" - echo " voice voice capture service" - echo " enclosure mark_1 enclosure service" - echo - echo "Options:" - echo " restart (optional) Force the service to restart if running" - echo - echo "Examples:" - echo " ${script} all" - echo " ${script} all restart" - echo " ${script} bus" - echo " ${script} voice" - - exit 1 -} - -name_to_script_path() { - case ${1} in - "bus") _module="/usr/bin/mycroft-messagebus" ;; - "skills") _module="/usr/bin/mycroft-skills" ;; - "audio") _module="/usr/bin/mycroft-audio" ;; - "voice") _module="/usr/bin/mycroft-speech-client" ;; - "enclosure") _module="/usr/bin/mycroft-enclosure-client" ;; - - *) - echo "Error: Unknown name '${1}'" - exit 1 - esac -} - -launch_background() { - name_to_script_path "${1}" - - if pgrep -f "python3 ${_module}" > /dev/null; then - if ($_force_restart); then - echo "Restarting: ${1}" - stop-mycroft "${1}" - else - # Already running, no need to restart - return - fi - else - echo "Starting background service $1" - fi - - # Security warning/reminder for the user - if [ "${1}" = "bus" ] ; then - echo "CAUTION: The Mycroft bus is an open websocket with no built-in security" - echo " measures. You are responsible for protecting the local port" - echo " 8181 with a firewall as appropriate." - fi - - # Launch process in background - # Send logs to XDG Base Directories cache location - if [ -n "${XDG_CACHE_HOME+x}" ]; then - logdir="$XDG_CACHE_HOME/mycroft" - else - logdir="$HOME/.cache/mycroft" - fi - - if [ ! -d "$logdir" ]; then - mkdir -p "$logdir" - fi - - ${_module} "$_params" >> "$logdir/${1}.log" 2>&1 & -} - -launch_all() { - echo "Starting all mycroft-core services" - launch_background bus - launch_background skills - launch_background audio - launch_background voice - launch_background enclosure -} - -_opt=$1 -_force_restart=false -shift -if [ "${1}" = "restart" ] || [ "${_opt}" = "restart" ]; then - _force_restart=true - if [ "${_opt}" = "restart" ]; then - # Support "start-mycroft restart all" as well as "start-mycroft all restart" - _opt=$1 - fi - shift -fi -_params=$* - -case ${_opt} in - "all") - launch_all - ;; - "bus") - launch_background "${_opt}" - ;; - "audio") - launch_background "${_opt}" - ;; - "skills") - launch_background "${_opt}" - ;; - "voice") - launch_background "${_opt}" - ;; - "enclosure") - launch-background "${_opt}" - ;; - *) - help - ;; -esac diff --git a/community/mycroft-core/stop-mycroft.sh b/community/mycroft-core/stop-mycroft.sh deleted file mode 100755 index ea27ff89629..00000000000 --- a/community/mycroft-core/stop-mycroft.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/sh - -script=${0} -script=${script##*/} - -help() { - echo "${script}: Mycroft service stopper" - echo "usage: ${script} [service]" - echo - echo "Service:" - echo " all ends core services: bus, audio, skills, voice" - echo " (none) same as \"all\"" - echo " bus stop the Mycroft messagebus service" - echo " audio stop the audio playback service" - echo " skills stop the skill service" - echo " voice stop voice capture service" - echo " enclosure stop enclosure (hardware/gui interface) service" - echo - echo "Examples:" - echo " ${script}" - echo " ${script} audio" - - exit 0 -} - -process_running() { - if [ "$( pgrep -f "python3 ${1}" )" ]; then - return 0 - else - return 1 - fi -} - -end_process() { - if process_running "$1"; then - # Find the process by name, only returning the oldest if it has children - pid=$( pgrep -o -f "python3 ${1}" ) - echo "Stopping $1 (${pid})..." - kill -SIGINT "${pid}" - - # Wait up to 5 seconds (50 * 0.1) for process to stop - c=1 - while [ $c -le 50 ]; do - if process_running "$1"; then - sleep 0.1 - c=$((c + 1)) - else - c=999 # end loop - fi - done - - if process_running "$1"; then - echo "Failed to stop." - pid=$( pgrep -o -f "python3 ${1}" ) - echo " Killing $1 (${pid})..." - kill -9 "${pid}" - echo "Killed." - result=120 - else - echo "Stopped." - if [ $result -eq 0 ] ; then - result=100 - fi - fi - fi -} - -result=0 # default, no change - -OPT=$1 -shift - -case ${OPT} in - "all"|"") - echo "Stopping all mycroft-core services" - end_process "/usr/bin/mycroft-skills" - end_process "/usr/bin/mycroft-audio" - end_process "/usr/bin/mycroft-speech-client" - end_process "/usr/bin/mycroft-enclosure-client" - end_process "/usr/bin/mycroft-messagebus" - ;; - "bus") - end_process "/usr/bin/mycroft-messagebus" - ;; - "audio") - end_process "/usr/bin/mycroft-audio" - ;; - "skills") - end_process "/usr/bin/mycroft-speech" - ;; - "voice") - end_process "/usr/bin/mycroft-speech-client" - ;; - "enclosure") - end_process "/usr/bin/mycroft-enclosure-client" - ;; - *) - help - ;; -esac - -# Exit codes: -# 0 if nothing changed (e.g. --help or no process was running) -# 100 at least one process was stopped -# 120 if any process had to be killed -exit $result -- cgit v1.2.3