diff --git a/ansible/roles/ovos_installer/tasks/ovos.yml b/ansible/roles/ovos_installer/tasks/ovos.yml index d63847d3..92bb1835 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 87c60fba..4b90b20e 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 50a1e7c2..16130a98 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 eff429a7..dcfe6a07 100644 --- a/tui/features.sh +++ b/tui/features.sh @@ -7,12 +7,31 @@ 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 +if [ -f "$INSTALLER_STATE_FILE" ]; then + if jq -e '.features|any(. == "skills")' "$INSTALLER_STATE_FILE" &>>"$LOG_FILE"; then + features=("skills" "$SKILL_DESCRIPTION" ON) + else + features=("skills" "$SKILL_DESCRIPTION" OFF) + fi + if jq -e '.features|any(. == "extra-skills")' "$INSTALLER_STATE_FILE" &>>"$LOG_FILE"; then + features+=("extra-skills" "$EXTRA_SKILL_DESCRIPTION" ON) + else + features+=("extra-skills" "$EXTRA_SKILL_DESCRIPTION" OFF) + fi + if jq -e '.features|any(. == "gui")' "$INSTALLER_STATE_FILE" &>>"$LOG_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 +46,26 @@ 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 + +if [ "$exit_status" -ne 1 ]; then + jq -en '.features += $ARGS.positional' --args "${FEATURES_STATE[@]}" > "$TEMP_FEATURES_FILE" + jq -es '.[0] * .[1]' "$TEMP_PROFILE_FILE" "$TEMP_FEATURES_FILE" > "$INSTALLER_STATE_FILE" + rm "$TEMP_FEATURES_FILE" "$TEMP_PROFILE_FILE" +fi diff --git a/tui/locales/en-us/update.sh b/tui/locales/en-us/update.sh new file mode 100644 index 00000000..45c1c4d7 --- /dev/null +++ b/tui/locales/en-us/update.sh @@ -0,0 +1,14 @@ +#!/bin/env bash + +CONTENT=" +An existing instance of Open Voice OS/HiveMind has been detected. + +Upgrading your existing instance of Open Voice OS or HiveMind to the latest version ensures that you stay ahead with the most advanced features, critical security updates, bug fixes, and performance optimizations. + +This not only enhances the overall functionality and user experience but also ensures compatibility with the latest integrations and tools, keeping your system reliable, secure, and future-proof. + +Do you want to update Open Voice OS to the latest version? +" +TITLE="Open Voice OS Installation - Update" + +export CONTENT TITLE diff --git a/tui/profiles.sh b/tui/profiles.sh index aaf25168..83832fb8 100644 --- a/tui/profiles.sh +++ b/tui/profiles.sh @@ -3,9 +3,19 @@ # shellcheck source=locales/en-us/profiles.sh source "tui/locales/$LOCALE/profiles.sh" +# Default active and available profiles active_profile="ovos" available_profiles=(ovos satellite listener server) +# Handle existing installation +if [ -f "$INSTALLER_STATE_FILE" ]; then + if jq -e 'has("profile")' "$INSTALLER_STATE_FILE" &>>"$LOG_FILE"; then + current_profile=$(jq -re '.profile' "$INSTALLER_STATE_FILE") + active_profile="$current_profile" + available_profiles=("$current_profile") + fi +fi + whiptail_args=( --title "$TITLE" --radiolist "$CONTENT" @@ -31,3 +41,6 @@ if [ -z "$PROFILE" ]; then source tui/channels.sh source tui/profiles.sh fi + +jq -en --arg profile "$PROFILE" '.profile += $profile' > "$TEMP_PROFILE_FILE" + diff --git a/tui/uninstall.sh b/tui/uninstall.sh index b3a69c5a..5ed91107 100644 --- a/tui/uninstall.sh +++ b/tui/uninstall.sh @@ -13,4 +13,7 @@ whiptail --yesno --defaultno --no-button "$NO_BUTTON" --yes-button "$YES_BUTTON" exit_status=$? if [ "$exit_status" -eq 1 ]; then export CONFIRM_UNINSTALL="false" + + # shellcheck source=update.sh + source tui/update.sh fi diff --git a/tui/update.sh b/tui/update.sh new file mode 100644 index 00000000..fcca7559 --- /dev/null +++ b/tui/update.sh @@ -0,0 +1,14 @@ +#!/bin/env bash + +# shellcheck source=locales/en-us/misc.sh +source "tui/locales/$LOCALE/misc.sh" + +# shellcheck source=locales/en-us/update.sh +source "tui/locales/$LOCALE/update.sh" + +whiptail --yesno --no-button "$NO_BUTTON" --yes-button "$YES_BUTTON" --title "$TITLE" "$CONTENT" "$TUI_WINDOW_HEIGHT" "$TUI_WINDOW_WIDTH" + +exit_status=$? +if [ "$exit_status" -eq 1 ]; then + exit 0 +fi diff --git a/utils/common.sh b/utils/common.sh index 67ee5c5a..a3ea3144 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -548,3 +548,18 @@ function apt_ensure() { echo "No missing packages" fi } + +# This function ensures the existence and proper configuration of a +# local state directory for the OVOS environment. It sets up a +# specific directory structure and prepares an installer state file for use. +function state_directory() { + OVOS_LOCAL_STATE_DIRECTORY="$RUN_AS_HOME/.local/state/ovos" + export INSTALLER_STATE_FILE="$OVOS_LOCAL_STATE_DIRECTORY/installer.json" + if [ ! -d "$OVOS_LOCAL_STATE_DIRECTORY" ]; then + mkdir -p "$OVOS_LOCAL_STATE_DIRECTORY" &>>"$LOG_FILE" + chown -R "$RUN_AS":"$(id -ng "$RUN_AS")" "$OVOS_LOCAL_STATE_DIRECTORY" &>>"$LOG_FILE" + fi + if [ -f "$INSTALLER_STATE_FILE" ]; then + [ -s "$INSTALLER_STATE_FILE" ] || rm "$INSTALLER_STATE_FILE" &>>"$LOG_FILE" + fi +} diff --git a/utils/constants.sh b/utils/constants.sh index 03a7bcd9..63cd0115 100644 --- a/utils/constants.sh +++ b/utils/constants.sh @@ -54,6 +54,8 @@ declare -rA SUPPORTED_DEVICES=( ["tas5806"]="2f" #https://www.ti.com/product/TAS5806MD ) export SUPPORTED_DEVICES +export TEMP_FEATURES_FILE=/tmp/features.json +export TEMP_PROFILE_FILE=/tmp/profile.json export TUI_WINDOW_HEIGHT="35" export TUI_WINDOW_WIDTH="90" export USER_ID="$EUID"