From 05cb7ce1c5687ec5f2c067cd2b3d4db1ec57ffc8 Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Thu, 28 Sep 2017 12:48:51 -0700 Subject: [PATCH] Make ios-install-third-party.sh more robust Summary: See https://github.com/facebook/react-native/issues/14423 This adds checks after download that each file is present, and has the correct sha1 hash. If not, it will retry several times, and fail if it can't successfully download the file. If a file is downloaded, the unpack and command will run, even if the third-party dir already exists. The diagnostics printed in the event of failure are improved. This should be self-healing for anybody who has a bad ~/.rncache directory. The checksum will fail, and the files will be redownloaded. Reviewed By: hramos Differential Revision: D5930707 fbshipit-source-id: cb15af949294243448ccc3995ec3f0396b1922b6 --- scripts/ios-install-third-party.sh | 56 ++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/scripts/ios-install-third-party.sh b/scripts/ios-install-third-party.sh index 271a35348..0d698ea3d 100755 --- a/scripts/ios-install-third-party.sh +++ b/scripts/ios-install-third-party.sh @@ -1,28 +1,56 @@ #!/bin/bash -set -e - cachedir="$HOME/.rncache" mkdir -p "$cachedir" +function file_fail () { + cachefile=$1 + msg=$2 + + echo "$msg. Debug info:" 2>&1 + ls -l "$cachefile" 2>&1 + shasum "$cachefile" 2>&1 + exit 1 +} + function fetch_and_unpack () { file=$1 url=$2 - cmd=$3 + hash=$3 + cmd=$4 - if [ ! -f "$cachedir/$file" ]; then + retries=4 + fetched=no + + while true; do + if [ -f "$cachedir/$file" ]; then + if shasum -p "$cachedir/$file" | + awk -v hash="$hash" '{exit $1 != hash}'; then + break + else + echo "Incorrect hash:" 2>&1 + shasum -p "$cachedir/$file" 2>&1 + echo "Retrying..." 2>&1 + fi + fi + + (( retries = retries - 1 )) + if (( retries < 0 )); then + file_fail "$cachedir/$file" "Failed to successfully download '$file'" + fi + + rm -f "$cachedir/$file" (cd "$cachedir"; curl -J -L -O "$url") - fi + fetched=yes + done dir=$(basename "$file" .tar.gz) - if [ ! -d "third-party/$dir" ]; then + if [ "$fetched" = "yes" ] || [ ! -d "third-party/$dir" ]; then (cd third-party; + rm -rf "$dir" echo Unpacking "$cachedir/$file"... if ! tar zxf "$cachedir/$file"; then - echo "Unpacking '$cachedir/$file' failed. Debug info:" 2>&1 - ls -l "$cachedir/$file" 2>&1 - shasum ~/.rncache/boost_1_63_0.tar.gz 2>&1 - exit 1 + file_fail "$cachedir/$file" "Unpacking '$cachedir/$file' failed" fi cd "$dir" eval "${cmd:-true}") @@ -33,7 +61,7 @@ mkdir -p third-party SCRIPTDIR=$(dirname "$0") -fetch_and_unpack glog-0.3.4.tar.gz https://github.com/google/glog/archive/v0.3.4.tar.gz "\"$SCRIPTDIR/ios-configure-glog.sh\"" -fetch_and_unpack double-conversion-1.1.5.tar.gz https://github.com/google/double-conversion/archive/v1.1.5.tar.gz -fetch_and_unpack boost_1_63_0.tar.gz https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz -fetch_and_unpack folly-2016.09.26.00.tar.gz https://github.com/facebook/folly/archive/v2016.09.26.00.tar.gz +fetch_and_unpack glog-0.3.4.tar.gz https://github.com/google/glog/archive/v0.3.4.tar.gz 69f91cd5a1de35ead0bc4103ea87294b0206a456 "\"$SCRIPTDIR/ios-configure-glog.sh\"" +fetch_and_unpack double-conversion-1.1.5.tar.gz https://github.com/google/double-conversion/archive/v1.1.5.tar.gz 96a8aba1b4ce7d4a7a3c123be26c379c2fed1def +fetch_and_unpack boost_1_63_0.tar.gz https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz c3f57e1d22a995e608983effbb752b54b6eab741 +fetch_and_unpack folly-2016.09.26.00.tar.gz https://github.com/facebook/folly/archive/v2016.09.26.00.tar.gz f3b928b5039235bad6cece638c597c6684d1e4e6