2024-08-26 10:13:52 -04:00
|
|
|
#!/bin/bash
|
2025-01-03 09:34:16 +00:00
|
|
|
#
|
|
|
|
# Usage examples:
|
2025-05-02 13:39:05 +00:00
|
|
|
# ./build_all.sh -c ./config/all.json # Builds for all languages
|
|
|
|
# ./build_all.sh -c ./config/fast.json # Builds only en_US and zh_CN
|
2025-01-03 09:34:16 +00:00
|
|
|
#
|
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
|
|
|
# -----------------------------------------------------------------------------
|
2025-05-02 13:39:05 +00:00
|
|
|
# 1. Parse input argument for configuration file
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
2025-05-02 13:39:05 +00:00
|
|
|
CONFIG_JSON="./config/all.json" # Default config file
|
2025-01-03 09:34:16 +00:00
|
|
|
|
2025-05-02 13:39:05 +00:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case "$1" in
|
|
|
|
-c|--config)
|
|
|
|
CONFIG_JSON="$2"
|
|
|
|
echo "[INFO] Using configuration file '$CONFIG_JSON'."
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "[ERROR] Usage: $0 -c <config.json>"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2025-04-13 03:20:13 +00:00
|
|
|
|
2025-05-02 13:39:05 +00:00
|
|
|
if [[ ! -f "$CONFIG_JSON" ]]; then
|
|
|
|
echo "[ERROR] Configuration file $CONFIG_JSON does not exist."
|
2025-04-13 03:20:13 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2024-12-29 06:15:26 +00:00
|
|
|
|
2025-05-02 13:39:05 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 2. Check if jq is installed, install if not
|
|
|
|
# -----------------------------------------------------------------------------
|
2025-04-13 03:20:13 +00:00
|
|
|
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-05-02 13:39:05 +00:00
|
|
|
# Load languages
|
|
|
|
selected_languages=$(jq -c '.' "$CONFIG_JSON")
|
2025-01-03 09:34:16 +00:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 3. Cleanup old files
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
echo "[INFO] Removing old distribution files..."
|
2025-05-02 13:32:42 +00:00
|
|
|
sudo rm -rf ./src/dist/*
|
2024-08-26 10:13:52 -04:00
|
|
|
|
2025-01-03 09:34:16 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 4. Check for required files
|
|
|
|
# -----------------------------------------------------------------------------
|
2025-05-02 13:32:42 +00:00
|
|
|
if [[ ! -f "./src/args.sh" || ! -f "./src/build.sh" ]]; then
|
|
|
|
echo "[ERROR] ./src/args.sh or ./src/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-15 15:15:29 +00:00
|
|
|
# Display summary of the current language for logging
|
2025-04-13 15:27:35 +00:00
|
|
|
LANG_MODE=$(echo "$lang_info" | jq -r '.lang_mode')
|
2025-01-03 09:34:16 +00:00
|
|
|
echo "================================================="
|
2025-04-15 15:15:29 +00:00
|
|
|
echo "[INFO] Starting build -> LANG_MODE: ${LANG_MODE}"
|
|
|
|
echo "Current language configuration:"
|
|
|
|
echo "$lang_info" | jq '.'
|
2025-01-03 09:34:16 +00:00
|
|
|
echo "================================================="
|
2025-04-15 15:15:29 +00:00
|
|
|
|
2025-05-02 13:32:42 +00:00
|
|
|
# Dynamically update all fields in ./src/args.sh
|
2025-04-15 15:15:29 +00:00
|
|
|
# Get all keys from the current language configuration
|
|
|
|
keys=$(echo "$lang_info" | jq -r 'keys[]')
|
|
|
|
|
2025-05-02 13:32:42 +00:00
|
|
|
# For each key, update the corresponding environment variable in ./src/args.sh
|
2025-04-15 15:15:29 +00:00
|
|
|
for key in $keys; do
|
|
|
|
# Convert key to uppercase for environment variable naming
|
|
|
|
env_var=$(echo "$key" | tr '[:lower:]' '[:upper:]')
|
|
|
|
# Get the value and escape any special characters
|
|
|
|
value=$(echo "$lang_info" | jq -r --arg k "$key" '.[$k]')
|
|
|
|
escaped_value=$(echo "$value" | sed 's/[\/&]/\\&/g')
|
2025-05-02 13:32:42 +00:00
|
|
|
sed -i "s|^export ${env_var}=\".*\"|export ${env_var}=\"${escaped_value}\"|" ./src/args.sh
|
2025-04-15 15:15:29 +00:00
|
|
|
done
|
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
|
2025-04-15 15:15:29 +00:00
|
|
|
echo "[INFO] Build attempt $attempt for LANG_MODE: ${LANG_MODE}"
|
2025-01-21 06:13:58 +00:00
|
|
|
|
2025-05-02 13:32:42 +00:00
|
|
|
# cd ./src and run the build script
|
|
|
|
if ./src/build.sh; then
|
2025-04-15 15:15:29 +00:00
|
|
|
echo "[INFO] Build succeeded for LANG_MODE: ${LANG_MODE} on attempt $attempt."
|
2025-01-21 06:13:58 +00:00
|
|
|
break
|
|
|
|
else
|
2025-04-15 15:15:29 +00:00
|
|
|
echo "[WARNING] Build failed for LANG_MODE: ${LANG_MODE} on attempt $attempt."
|
2025-01-21 06:13:58 +00:00
|
|
|
if [ $attempt -lt $MAX_RETRIES ]; then
|
2025-04-15 15:15:29 +00:00
|
|
|
echo "[INFO] Retrying build for LANG_MODE: ${LANG_MODE}..."
|
2025-01-21 06:13:58 +00:00
|
|
|
attempt=$((attempt + 1))
|
|
|
|
else
|
2025-04-15 15:15:29 +00:00
|
|
|
echo "[ERROR] Build failed after $MAX_RETRIES attempts for LANG_MODE: ${LANG_MODE}."
|
2025-01-21 06:13:58 +00:00
|
|
|
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-05-02 13:39:05 +00:00
|
|
|
echo "[INFO] All build tasks have been completed."
|
2025-05-04 08:24:24 +00:00
|
|
|
echo "[INFO] Generating torrent files..."
|
|
|
|
|
2025-05-04 17:19:29 +00:00
|
|
|
shopt -s extglob
|
|
|
|
|
2025-05-04 08:24:24 +00:00
|
|
|
(
|
|
|
|
cd ./src/dist || exit 1
|
|
|
|
sudo apt install -y mktorrent
|
|
|
|
|
|
|
|
for f in AnduinOS-*-+([0-9]).@(iso|sha256); do
|
|
|
|
mv -- "$f" "${f%-+([0-9]).@(iso|sha256)}.${f##*.}"
|
|
|
|
done
|
|
|
|
|
|
|
|
shopt -u extglob
|
|
|
|
|
2025-05-11 09:51:00 +00:00
|
|
|
tracker=$(mktemp)
|
|
|
|
curl -fsSL -o "$tracker" \
|
|
|
|
https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt
|
|
|
|
|
|
|
|
mapfile -t raw_trackers < "$tracker"
|
|
|
|
rm "$tracker"
|
|
|
|
|
|
|
|
trackers=()
|
|
|
|
for t in "${raw_trackers[@]}"; do
|
|
|
|
[[ -n "$t" ]] && trackers+=( -a "$t" )
|
|
|
|
done
|
2025-05-04 08:24:24 +00:00
|
|
|
|
|
|
|
for iso in AnduinOS-*.iso; do
|
|
|
|
base="${iso%.iso}"
|
|
|
|
echo "[INFO] Generating torrent for $iso"
|
2025-05-11 09:51:00 +00:00
|
|
|
echo "[INFO] Using trackers: ${trackers[@]}"
|
|
|
|
mktorrent "${trackers[@]}" -o "${base}.torrent" "$iso"
|
2025-05-04 08:24:24 +00:00
|
|
|
done
|
|
|
|
)
|