Add retries, to make it fail-safe against network interruptions

This commit is contained in:
Filip Dimovski 2017-05-19 09:10:14 +00:00
parent d2bea48975
commit 4c21abea52

30
nvm.sh
View File

@ -2684,10 +2684,38 @@ nvm() {
# Install version if not available
if ! nvm ls "$PROVIDED_VERSION" &>/dev/null; then
nvm install "$PROVIDED_VERSION"
tries_global=3
installed_flag="/tmp/.nvm_success"
while [ $tries_global -gt 0 ]; do
( nvm install "$PROVIDED_VERSION" && touch $installed_flag ) &
proc_id="$!"
#wait $proc_id
#result=$?
# Check every 2 seconds if the installation finished,
# if it did, install the needed npm packages and exit
tries_install=10
while [ $tries_install -gt 0 ]; do
if [ -f $installed_flag ]; then
npm install -g grunt-cli bower
rm $installed_flag &>/dev/null
return
fi
sleep 2
tries_install=$(( $tries_install - 1 ))
done
# Kill process after 20 seconds
kill $proc_id &>/dev/null
tries_global=$(( $tries_global - 1 ))
done
echo "Cannot install and use $PROVIDED_VERSION - network/disk space issues might be the reason."
return 1
fi
if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then