diff --git a/ansible/roles/ovos_installer/tasks/ovos.yml b/ansible/roles/ovos_installer/tasks/ovos.yml index d63847d..92bb183 100644 --- a/ansible/roles/ovos_installer/tasks/ovos.yml +++ b/ansible/roles/ovos_installer/tasks/ovos.yml @@ -10,6 +10,7 @@ - "{{ ovos_installer_user_home }}/.config/OpenVoiceOS/*" - "{{ ovos_installer_user_home }}/.config/wireplumber/*" - "{{ ovos_installer_user_home }}/.local/share/hivemind/*" + - "{{ ovos_installer_user_home }}/.local/state/ovos/*" when: ovos_installer_cleaning | bool tags: - uninstall diff --git a/ansible/roles/ovos_installer/tasks/virtualenv/systemd.yml b/ansible/roles/ovos_installer/tasks/virtualenv/systemd.yml index 87c60fb..4b90b20 100644 --- a/ansible/roles/ovos_installer/tasks/virtualenv/systemd.yml +++ b/ansible/roles/ovos_installer/tasks/virtualenv/systemd.yml @@ -135,5 +135,6 @@ - "{{ ovos_installer_user_home }}/.local/share/precise-lite" - "{{ ovos_installer_user_home }}/.local/state/mycroft" - "{{ ovos_installer_user_home }}/.local/state/vosk" + - "{{ ovos_installer_user_home }}/.local/state/ovos" - "{{ ovos_installer_user_home }}/nltk_data" - "{{ ovos_installer_user_home }}/stdout" diff --git a/setup.sh b/setup.sh index 50a1e7c..16130a9 100755 --- a/setup.sh +++ b/setup.sh @@ -45,6 +45,7 @@ install_ansible download_yq detect_scenario i2c_scan +state_directory trap "" ERR set +eE diff --git a/tui/features.sh b/tui/features.sh index eff429a..b63d7bc 100644 --- a/tui/features.sh +++ b/tui/features.sh @@ -7,12 +7,32 @@ export FEATURE_GUI="false" export FEATURE_SKILLS="false" export FEATURE_EXTRA_SKILLS="false" +declare -a features features=("skills" "$SKILL_DESCRIPTION" ON) features+=("extra-skills" "$EXTRA_SKILL_DESCRIPTION" OFF) if [[ "$RASPBERRYPI_MODEL" != *"Raspberry Pi 3"* ]] && [[ "$KERNEL" != *"microsoft"* ]] && [ "$PROFILE" != "server" ]; then features+=("gui" "$GUI_DESCRIPTION" OFF) fi +features_state_file="$RUN_AS_HOME/.local/state/ovos/features.json" +if [ -f "$features_state_file" ]; then + if jq -e '.features|any(. == "skills")' "$features_state_file"; then + features=("skills" "$SKILL_DESCRIPTION" ON) + else + features=("skills" "$SKILL_DESCRIPTION" OFF) + fi + if jq -e '.features|any(. == "extra-skills")' "$features_state_file"; then + features+=("extra-skills" "$EXTRA_SKILL_DESCRIPTION" ON) + else + features+=("extra-skills" "$EXTRA_SKILL_DESCRIPTION" OFF) + fi + if jq -e '.features|any(. == "gui")' "$features_state_file"; then + features+=("gui" "$GUI_DESCRIPTION" ON) + else + features+=("gui" "$GUI_DESCRIPTION" OFF) + fi +fi + OVOS_FEATURES=$(whiptail --separate-output --title "$TITLE" \ --checklist "$CONTENT" --cancel-button "$BACK_BUTTON" --ok-button "$OK_BUTTON" --yes-button "$OK_BUTTON" "$TUI_WINDOW_HEIGHT" "$TUI_WINDOW_WIDTH" "${#features[@]}" "${features[@]}" 3>&1 1>&2 2>&3) @@ -27,16 +47,23 @@ if [ "$exit_status" -ne 0 ]; then fi fi +declare -a FEATURES_STATE + for FEATURE in $OVOS_FEATURES; do case "$FEATURE" in "gui") export FEATURE_GUI="true" + FEATURES_STATE+=("gui") ;; "skills") export FEATURE_SKILLS="true" + FEATURES_STATE+=("skills") ;; "extra-skills") export FEATURE_EXTRA_SKILLS="true" + FEATURES_STATE+=("extra-skills") ;; esac done + +jq -n '.features += $ARGS.positional' --args "${FEATURES_STATE[@]}" > "$features_state_file" diff --git a/utils/common.sh b/utils/common.sh index 67ee5c5..1255f42 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -548,3 +548,14 @@ function apt_ensure() { echo "No missing packages" fi } + +# This function ensures the existence of a specific local state directory and +# sets its ownership. This is useful for creating and managing state directories +# required by applications. +function state_directory() { + OVOS_LOCAL_STATE_DIRECTORY="$RUN_AS_HOME/.local/state/ovos" + if [ ! -d "$OVOS_LOCAL_STATE_DIRECTORY" ]; then + mkdir -p "$OVOS_LOCAL_STATE_DIRECTORY" &>>"$LOG_FILE" + chown "$RUN_AS":"$(id -ng "$RUN_AS")" "$OVOS_LOCAL_STATE_DIRECTORY" &>>"$LOG_FILE" + fi +}