2024-08-26 10:13:52 -04:00
|
|
|
#!/bin/bash
|
2025-01-03 09:34:16 +00:00
|
|
|
#
|
|
|
|
# Usage examples:
|
|
|
|
# ./build_all_langs.sh # By default, builds for all languages
|
|
|
|
# ./build_all_langs.sh --langs fast # Builds only en_US and zh_CN
|
|
|
|
# ./build_all_langs.sh --langs all # Builds for all languages
|
|
|
|
#
|
|
|
|
|
2025-01-02 13:30:06 +00:00
|
|
|
set -e # Exit immediately if any command returns a non-zero status
|
|
|
|
set -o pipefail # If any command in a pipeline fails, the entire pipeline fails
|
|
|
|
set -u # Treat unset variables as an error
|
2024-08-26 10:13:52 -04:00
|
|
|
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 1. Parse input argument for build mode
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
BUILD_MODE="all" # Default mode is 'all'
|
|
|
|
|
|
|
|
# If the user passes in '--langs ...'
|
|
|
|
if [[ "${1:-}" == "--langs" ]]; then
|
|
|
|
if [[ "${2:-}" == "fast" ]]; then
|
|
|
|
BUILD_MODE="fast"
|
2025-01-03 09:37:22 +00:00
|
|
|
echo "[INFO] Building only for 'en_US' and 'zh_CN' languages."
|
2025-01-03 09:34:16 +00:00
|
|
|
elif [[ "${2:-}" == "all" ]]; then
|
|
|
|
BUILD_MODE="all"
|
2025-01-03 09:37:22 +00:00
|
|
|
echo "[INFO] Building for all languages."
|
2025-01-03 09:34:16 +00:00
|
|
|
else
|
2025-01-21 06:13:58 +00:00
|
|
|
echo "[ERROR] Invalid value for '--langs'. Use 'all' or 'fast'."
|
2025-01-03 09:34:16 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2025-01-03 09:37:22 +00:00
|
|
|
else
|
2025-04-13 03:20:13 +00:00
|
|
|
echo "[INFO] No arguments provided, defaulting to building for all languages."
|
2025-01-03 09:34:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2025-04-13 03:20:13 +00:00
|
|
|
# 2. Load language configuration from JSON file
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
2025-04-13 03:20:13 +00:00
|
|
|
LANGUAGES_JSON="languages.json"
|
|
|
|
|
|
|
|
if [[ ! -f "$LANGUAGES_JSON" ]]; then
|
|
|
|
echo "[ERROR] Language configuration file $LANGUAGES_JSON does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-12-29 06:15:26 +00:00
|
|
|
|
2025-04-13 03:20:13 +00:00
|
|
|
# Check if jq is installed, install if not
|
|
|
|
if ! command -v jq &> /dev/null; then
|
|
|
|
echo "[INFO] Installing jq for JSON parsing..."
|
|
|
|
sudo apt-get update && sudo apt-get install -y jq
|
|
|
|
fi
|
2025-01-03 09:34:16 +00:00
|
|
|
|
2025-04-13 03:20:13 +00:00
|
|
|
# Build array of languages based on the selected mode
|
2025-01-03 09:34:16 +00:00
|
|
|
if [[ "$BUILD_MODE" == "fast" ]]; then
|
2025-04-13 03:20:13 +00:00
|
|
|
# Just select English and Chinese for fast mode
|
2025-04-13 15:27:35 +00:00
|
|
|
selected_languages=$(jq -c '[.[] | select(.lang_mode == "en_US" or .lang_mode == "zh_CN")]' "$LANGUAGES_JSON")
|
2025-01-03 09:34:16 +00:00
|
|
|
else
|
2025-04-13 03:20:13 +00:00
|
|
|
# Use all languages for full mode
|
|
|
|
selected_languages=$(jq -c '.' "$LANGUAGES_JSON")
|
2025-01-03 09:34:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 3. Cleanup old files
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
echo "[INFO] Removing old distribution files..."
|
|
|
|
sudo rm -rf ./dist/*
|
2024-08-26 10:13:52 -04:00
|
|
|
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 4. Check for required files
|
|
|
|
# -----------------------------------------------------------------------------
|
2024-08-26 10:13:52 -04:00
|
|
|
if [[ ! -f "args.sh" || ! -f "build.sh" ]]; then
|
2025-01-03 09:34:16 +00:00
|
|
|
echo "[ERROR] args.sh or build.sh does not exist."
|
2024-12-28 08:11:34 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
2025-01-21 06:13:58 +00:00
|
|
|
# 5. Build loop for selected languages with retry mechanism
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
2025-04-13 03:20:13 +00:00
|
|
|
# Get the count of languages from the selected_languages JSON array
|
|
|
|
lang_count=$(echo "$selected_languages" | jq '. | length')
|
|
|
|
|
|
|
|
for ((i=0; i<lang_count; i++)); do
|
|
|
|
# Extract language information from JSON
|
|
|
|
lang_info=$(echo "$selected_languages" | jq -c ".[$i]")
|
|
|
|
|
2025-04-13 15:27:35 +00:00
|
|
|
LANG_MODE=$(echo "$lang_info" | jq -r '.lang_mode')
|
2025-04-13 03:20:13 +00:00
|
|
|
LANG_CODE=$(echo "$lang_info" | jq -r '.lang_pack_code')
|
|
|
|
INPUT_METHOD_INSTALL=$(echo "$lang_info" | jq -r '.input_method_install')
|
|
|
|
CONFIG_IBUS_RIME=$(echo "$lang_info" | jq -r '.config_ibus_rime')
|
2025-04-13 15:27:35 +00:00
|
|
|
TIMEZONE=$(echo "$lang_info" | jq -r '.timezone')
|
2025-04-15 14:44:26 +00:00
|
|
|
CONFIG_WEATHER_LOCATION=$(echo "$lang_info" | jq -r '.config_weather_location')
|
|
|
|
CONFIG_INPUT_METHOD=$(echo "$lang_info" | jq -r '.config_input_method')
|
2024-12-28 08:11:34 +00:00
|
|
|
|
2025-04-13 15:27:35 +00:00
|
|
|
# Update environment variables in args.sh using unified delimiter
|
|
|
|
sed -i "s|^export LANG_MODE=\".*\"|export LANG_MODE=\"${LANG_MODE}\"|" args.sh
|
|
|
|
sed -i "s|^export LANG_PACK_CODE=\".*\"|export LANG_PACK_CODE=\"${LANG_CODE}\"|" args.sh
|
|
|
|
sed -i "s|^export INPUT_METHOD_INSTALL=\".*\"|export INPUT_METHOD_INSTALL=\"${INPUT_METHOD_INSTALL}\"|" args.sh
|
|
|
|
sed -i "s|^export CONFIG_IBUS_RIME=\".*\"|export CONFIG_IBUS_RIME=\"${CONFIG_IBUS_RIME}\"|" args.sh
|
|
|
|
sed -i "s|^export TIMEZONE=\".*\"|export TIMEZONE=\"${TIMEZONE}\"|" args.sh
|
2025-04-15 14:42:39 +00:00
|
|
|
sed -i "s|^export CONFIG_WEATHER_LOCATION=\".*\"|export CONFIG_WEATHER_LOCATION=\"${CONFIG_WEATHER_LOCATION}\"|" args.sh
|
|
|
|
sed -i "s|^export CONFIG_INPUT_METHOD=\".*\"|export CONFIG_INPUT_METHOD=\"${CONFIG_INPUT_METHOD}\"|" args.sh
|
2024-12-28 08:11:34 +00:00
|
|
|
|
2025-01-03 09:34:16 +00:00
|
|
|
echo "================================================="
|
|
|
|
echo "[INFO] Starting build -> LANG_MODE: ${LANG_MODE}, LANG_CODE: ${LANG_CODE}"
|
2025-04-13 03:20:13 +00:00
|
|
|
echo "[INFO] Input method: ${INPUT_METHOD_INSTALL}, Ibus Rime: ${CONFIG_IBUS_RIME}"
|
2025-04-13 15:27:35 +00:00
|
|
|
echo "[INFO] Timezone: ${TIMEZONE}"
|
2025-01-03 09:34:16 +00:00
|
|
|
echo "================================================="
|
2024-12-28 08:11:34 +00:00
|
|
|
|
2025-04-13 15:27:35 +00:00
|
|
|
|
2025-01-21 06:13:58 +00:00
|
|
|
# Initialize retry parameters
|
|
|
|
MAX_RETRIES=3
|
|
|
|
attempt=1
|
|
|
|
|
|
|
|
while [ $attempt -le $MAX_RETRIES ]; do
|
|
|
|
echo "[INFO] Build attempt $attempt for LANG_MODE: ${LANG_MODE}, LANG_CODE: ${LANG_CODE}"
|
|
|
|
|
|
|
|
if ./build.sh; then
|
|
|
|
echo "[INFO] Build succeeded for LANG_MODE: ${LANG_MODE}, LANG_CODE: ${LANG_CODE} on attempt $attempt."
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "[WARNING] Build failed for LANG_MODE: ${LANG_MODE}, LANG_CODE: ${LANG_CODE} on attempt $attempt."
|
|
|
|
if [ $attempt -lt $MAX_RETRIES ]; then
|
|
|
|
echo "[INFO] Retrying build for LANG_MODE: ${LANG_MODE}, LANG_CODE: ${LANG_CODE}..."
|
|
|
|
attempt=$((attempt + 1))
|
|
|
|
else
|
|
|
|
echo "[ERROR] Build failed after $MAX_RETRIES attempts for LANG_MODE: ${LANG_MODE}, LANG_CODE: ${LANG_CODE}."
|
|
|
|
echo "[ERROR] Stopping build process and waiting for manual intervention."
|
|
|
|
sleep 99999999
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2024-08-26 10:13:52 -04:00
|
|
|
done
|
2024-12-28 08:11:34 +00:00
|
|
|
|
2025-04-13 03:20:13 +00:00
|
|
|
echo "[INFO] All build tasks have been completed."
|