Skip to content

Commit

Permalink
[tui] Implement #135 for update
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Jan 20, 2025
1 parent 92fd641 commit d4d1d3c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
7 changes: 4 additions & 3 deletions tui/features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ if [ "$exit_status" -ne 0 ]; then
fi

declare -a FEATURES_STATE

for FEATURE in $OVOS_FEATURES; do
case "$FEATURE" in
"gui")
Expand All @@ -65,6 +64,8 @@ for FEATURE in $OVOS_FEATURES; do
esac
done

if [ ! -f "$INSTALLER_STATE_FILE" ]; then
jq -en '.features += $ARGS.positional' --args "${FEATURES_STATE[@]}" >> "$INSTALLER_STATE_FILE"
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
7 changes: 4 additions & 3 deletions tui/profiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# 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")
Expand Down Expand Up @@ -40,6 +42,5 @@ if [ -z "$PROFILE" ]; then
source tui/profiles.sh
fi

if [ ! -f "$INSTALLER_STATE_FILE" ]; then
jq -en '.profile += "ovos"' > "$INSTALLER_STATE_FILE"
fi
jq -en --arg profile "$PROFILE" '.profile += $profile' > "$TEMP_PROFILE_FILE"

7 changes: 5 additions & 2 deletions utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,12 @@ function apt_ensure() {
# 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 "$RUN_AS":"$(id -ng "$RUN_AS")" "$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
export INSTALLER_STATE_FILE="$OVOS_LOCAL_STATE_DIRECTORY/installer.json"
}
2 changes: 2 additions & 0 deletions utils/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d4d1d3c

Please sign in to comment.