Files
rhvoice-english/update_android.sh

105 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Update RHVoice English pronunciation fixes on Android via adb
set -euo pipefail
packageName="com.github.olga_yakovleva.rhvoice.android"
sourceDir="English"
remoteBaseDir="/sdcard/Android/data/${packageName}/files"
remoteDictDir="${remoteBaseDir}/dicts/English"
adbArgs=()
check_command() {
local commandName="$1"
if ! command -v "$commandName" >/dev/null 2>&1; then
echo "Error: Required command '$commandName' is not installed" >&2
exit 1
fi
}
run_adb() {
adb "${adbArgs[@]}" "$@"
}
select_device() {
local deviceCount
if [[ -n "${ADB_SERIAL:-}" ]]; then
adbArgs=(-s "$ADB_SERIAL")
return
fi
deviceCount="$(adb devices | awk 'NR > 1 && $2 == "device" { count++ } END { print count + 0 }')"
if [[ "$deviceCount" -eq 0 ]]; then
echo "Error: No Android device in 'device' state found" >&2
exit 1
fi
if [[ "$deviceCount" -gt 1 ]]; then
echo "Error: Multiple Android devices detected. Set ADB_SERIAL to choose one." >&2
exit 1
fi
}
check_source_dir() {
if [[ ! -d "$sourceDir" ]]; then
echo "Error: Source directory '$sourceDir' not found" >&2
exit 1
fi
}
check_package() {
if ! run_adb shell pm list packages "$packageName" | tr -d '\r' | grep -Fxq "package:${packageName}"; then
echo "Error: RHVoice package '$packageName' is not installed on the connected device" >&2
exit 1
fi
}
push_dict_files() {
local dictFiles=()
local sourcePath
local fileName
shopt -s nullglob
dictFiles=("$sourceDir"/*.txt)
shopt -u nullglob
if [[ "${#dictFiles[@]}" -eq 0 ]]; then
echo "Error: No dictionary files found in '$sourceDir'" >&2
exit 1
fi
echo "Ensuring RHVoice dictionary directory exists at ${remoteDictDir}..."
run_adb shell mkdir -p "$remoteDictDir"
for sourcePath in "${dictFiles[@]}"; do
fileName="$(basename "$sourcePath")"
echo "Pushing ${sourcePath} to ${remoteDictDir}/${fileName}..."
run_adb push "$sourcePath" "${remoteDictDir}/${fileName}" >/dev/null
done
}
show_remote_dir() {
echo "Remote dictionary files:"
run_adb shell ls -l "$remoteDictDir" | tr -d '\r'
}
main() {
check_command adb
check_source_dir
select_device
check_package
push_dict_files
show_remote_dir
echo "Android update complete!"
echo "RHVoice dictionaries on Android are stored in ${remoteDictDir}."
echo "RHVoice config on Android is stored under ${remoteBaseDir}, for example ${remoteBaseDir}/RHVoice.conf."
echo "You may need to restart RHVoice or apps using it for changes to take effect."
}
main "$@"