Skip to content

Commit dee78b5

Browse files
committed
perf: ⚡ use parallel downloads in install.sh
- The installation process has been significantly accelerated - Refactored the translation file download process to utilize parallel downloads for improved efficiency. - Added a function to handle individual translation downloads. - Enhanced comments for clarity regarding the installation prefix on macOS.
1 parent 2ac18d4 commit dee78b5

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

install.sh

+22-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ set -e
1212
# Determine the installation prefix
1313
if [[ ! -n "$PREFIX" ]]; then
1414
if echo "$OSTYPE" | grep -qE '^darwin.*'; then
15-
# The `/usr` directory in macOS is read-only, so you need to change the prefix to `/usr/local`
15+
# The `/usr` directory in macOS is read-only
16+
# so you need to change the prefix to `/usr/local`
1617
# https://github.com/openstreetmap/mod_tile/issues/349#issuecomment-1784165860
1718
prefix="/usr/local"
1819
else
@@ -43,22 +44,33 @@ fi
4344
mkdir -p "$TEMP_DIR"
4445
cd "$TEMP_DIR"
4546

46-
echo "Downloading cli-tips executable..."
47-
4847
# Download the main executable script from GitHub repository
49-
curl -sLO "https://raw.githubusercontent.com/$REPO/refs/heads/main/cli-tips.sh"
48+
echo "Downloading cli-tips executable..."
49+
curl -sLO "https://raw.githubusercontent.com/$REPO/refs/heads/main/cli-tips.sh" &
5050

51-
# Create translations directory and download all translation files
52-
# Uses GitHub API to get list of files, then downloads each one
51+
# Create translations directory
5352
mkdir -p translations
53+
54+
# Get list of translation files and download them in parallel
5455
echo "Downloading translation files..."
55-
curl -s "https://api.github.com/repos/$REPO/contents/translations" | grep "download_url" | cut -d '"' -f 4 | while read -r url; do
56-
lang=$(echo "$url" | grep -o '[a-z]\+\.txt' | cut -d'_' -f2 | cut -d'.' -f1)
56+
download_urls=$(curl -s "https://api.github.com/repos/$REPO/contents/translations" | grep "download_url" | cut -d '"' -f 4)
5757

58+
# Function to download a single translation file
59+
download_translation() {
60+
local url="$1"
61+
local lang=$(echo "$url" | grep -o '[a-z]\+\.txt' | cut -d'_' -f2 | cut -d'.' -f1)
5862
echo "- Downloading $lang translation..."
5963
curl -LOs -C - --output-dir translations "$url"
64+
}
65+
66+
# Start parallel downloads
67+
for url in $download_urls; do
68+
download_translation "$url" &
6069
done
6170

71+
# Wait for all downloads to complete
72+
wait
73+
6274
echo ""
6375

6476
echo "Installing..."
@@ -67,10 +79,8 @@ $sudo mv cli-tips.sh "$prefix/bin/cli-tips"
6779
# Set executable permissions
6880
chmod +x "$prefix/bin/cli-tips"
6981

70-
$sudo mkdir -p "$prefix/share/cli-tips/"
71-
72-
# Install translation files to system share directory
73-
$sudo mv translations/* "$prefix/share/cli-tips/"
82+
$sudo mkdir -p "$prefix/share/cli-tips"
83+
$sudo mv translations/* "$prefix/share/cli-tips"
7484

7585
# Clean up temporary installation files
7686
rm -rf "$TEMP_DIR"

0 commit comments

Comments
 (0)