diff --git a/.includes/rhvoice-dictionaries.sh b/.includes/rhvoice-dictionaries.sh new file mode 100644 index 0000000..4935e7c --- /dev/null +++ b/.includes/rhvoice-dictionaries.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2154 +# sudoFlags is set by configure-stormux.sh before this file is sourced. + +update_rhvoice_dictionaries() { + local targetDirectory="/etc/RHVoice/dicts/English" + local baseUrl="https://git.stormux.org/storm/rhvoice-english/raw/branch/master/English" + local dictionaryFiles=( + "wordfix.txt" + "namefix.txt" + ) + local tempDirectory + local dictionaryFile + + tempDirectory="$(mktemp -d)" || { + msgbox "Failed to create a temporary directory for RHVoice dictionary updates." + return 1 + } + + cleanup() { + rm -rf "$tempDirectory" + } + trap cleanup RETURN + + infobox "Downloading RHVoice dictionaries..." + for dictionaryFile in "${dictionaryFiles[@]}"; do + if ! curl -fL --retry 10 -o "${tempDirectory}/${dictionaryFile}" "${baseUrl}/${dictionaryFile}"; then + msgbox "Failed to download ${dictionaryFile} from the RHVoice English dictionary repository." + return 1 + fi + done + + if ! sudo "${sudoFlags[@]}" mkdir -p "$targetDirectory"; then + msgbox "Failed to create ${targetDirectory}." + return 1 + fi + + for dictionaryFile in "${dictionaryFiles[@]}"; do + if ! sudo "${sudoFlags[@]}" install -m 0644 "${tempDirectory}/${dictionaryFile}" "${targetDirectory}/${dictionaryFile}"; then + msgbox "Failed to install ${dictionaryFile} to ${targetDirectory}." + return 1 + fi + done + + if [[ "$(yesno "RHVoice dictionaries updated successfully.\n\nRestart speech-dispatcher?")" == "Yes" ]]; then + if ! sudo "${sudoFlags[@]}" killall speech-dispatcher; then + msgbox "RHVoice dictionaries were updated, but restarting speech-dispatcher failed." + return 1 + fi + fi + + msgbox "RHVoice dictionaries updated successfully." + return 0 +} + +update_rhvoice_dictionaries diff --git a/configure-stormux.sh b/configure-stormux.sh index 1c778e9..3e03270 100755 --- a/configure-stormux.sh +++ b/configure-stormux.sh @@ -118,6 +118,9 @@ while [[ "$choice" != "Exit" ]]; do sudo "${sudoFlags[@]}" git pull exit $? ;; + "Update RHVoice dictionaries") + source .includes/rhvoice-dictionaries.sh + ;; "Convert to Server") source .includes/convert-to-server.sh ;; @@ -151,6 +154,7 @@ while [[ "$choice" != "Exit" ]]; do "Get help on IRC" "Update configure-stormux" "Update EEPROM" + "Update RHVoice dictionaries" "Convert to Server" "Configure StormUX Repository" )