Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions build_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ while true; do
fi
done

#
# A generic helper function to retry any command with a backoff strategy
#
try_n_times() {
MAX_ATTEMPTS=$1
CMD=$2
CLEAN_CMD=$3
i=0
WAIT_TIME=1
while ! $CMD; do
i=$(expr $i + 1)
if [ $i -le $MAX_ATTEMPTS ]; then
echo "Attempt $i failed! Waiting $WAIT_TIME seconds before retry..."
sleep $WAIT_TIME
test -n "$CLEAN_CMD" && $CLEAN_CMD
WAIT_TIME=$(expr $WAIT_TIME \* 2)
else
echo "$MAX_ATTEMPTS attempts failed!"
return 1
fi
done
return 0
}

#
# Create temporary build area, with working copy of module source
#
Expand All @@ -277,15 +301,15 @@ else
;;
"zip")
echo "$ME: INFO Downloading module source"
wget -O $BUILD_DIR/module.zip $1
try_n_times 3 "wget -O $BUILD_DIR/module.zip $1" "rm -f $BUILD_DIR/module.zip"
ARCHIVE_DIR=`zipinfo -1 $BUILD_DIR/module.zip | head -n 1 | cut -f1 -d/`
unzip $BUILD_DIR/module.zip -d $BUILD_DIR
mv $BUILD_DIR/$ARCHIVE_DIR $MODULE_DIR
;;
*)
echo "$ME: INFO Downloading module source"
# Assume tarball of some kind
wget -O $BUILD_DIR/module.tgz $1
try_n_times 3 "wget -O $BUILD_DIR/module.tgz $1" "rm -f $BUILD_DIR/module.tgz"
ARCHIVE_DIR=`tar tfz $BUILD_DIR/module.tgz | head -n 1 | cut -f1 -d/`
cd $BUILD_DIR
tar xfz module.tgz
Expand Down