Skip to content

Instantly share code, notes, and snippets.

@suwardhana
Created October 18, 2024 01:36
Show Gist options
  • Select an option

  • Save suwardhana/abd6662aa2d732dbdc1d7ebd7783f0f3 to your computer and use it in GitHub Desktop.

Select an option

Save suwardhana/abd6662aa2d732dbdc1d7ebd7783f0f3 to your computer and use it in GitHub Desktop.
retry_brew for automatically retry connection reset when install use by ./retry_brew.sh (package_name)
#!/bin/bash
MAX_RETRIES=5
COUNT=0
PACKAGE_NAME=$1
while [ $COUNT -lt $MAX_RETRIES ]; do
brew install $PACKAGE_NAME && break
COUNT=$((COUNT+1))
echo "Connection reset by peer, retrying... ($COUNT/$MAX_RETRIES)"
sleep 5
done
if [ $COUNT -eq $MAX_RETRIES ]; then
echo "Failed to execute brew command after $MAX_RETRIES retries."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment