@@ -76,35 +76,48 @@ function downloadSpigot {
7676 fi
7777
7878 setServerVar
79+ curlArgs=()
7980 if [ -f " $SERVER " ] && ! isTrue " $FORCE_REDOWNLOAD " ; then
8081 # tell curl to only download when newer
81- curlArgs= " -z $SERVER "
82+ curlArgs+=( -z " $SERVER " )
8283 fi
8384 if isDebugging; then
84- curlArgs= " $curlArgs -v "
85+ curlArgs+=(-v)
8586 fi
8687 log " Downloading $match from $downloadUrl ..."
87- curl -fsSL -o " $SERVER " $curlArgs " $downloadUrl "
88- if [[ $? != 0 || $( grep -c " DOCTYPE html" " $SERVER " ) != 0 ]]; then
88+
89+ tempFile=" $SERVER .$$ "
90+
91+ # HTTP error or download site responded with an HTML error page
92+ if ! curl -fsSL -o " $tempFile " " ${curlArgs[@]} " " $downloadUrl " || grep -iq " doctype html" " $tempFile " ; then
93+
8994 cat << EOF
9095
9196ERROR: failed to download from $downloadUrl
9297 Visit https://getbukkit.org/download/${getbukkitFlavor} to lookup the
93- exact version, such as 1.4.6-R0.4-SNAPSHOT or 1.8-R0.1-SNAPSHOT-latest.
94- Click into the version entry to find the **exact** version, because something
95- like "1.8" is not sufficient according to their download naming.
98+ exact version or see if download site is unavailable.
99+ Click into the version entry to find the **exact** version.
96100
97101EOF
98102
99- if isDebugging && [[ $( grep -c " DOCTYPE html" " $SERVER " ) != 0 ]]; then
100- cat " $SERVER "
103+ if isDebugging && grep -iq " doctype html" " $tempFile " ; then
104+ cat " $tempFile "
105+ fi
106+
107+ if [ -f " $SERVER " ]; then
108+ log " Continuing with existing $SERVER file"
109+ else
110+ # remove invalid download
111+ rm " $tempFile "
112+ exit 3
101113 fi
102114
103- # remove invalid download
104- rm " $SERVER "
105- exit 3
115+ else
116+ mv " $tempFile " " $SERVER "
117+
106118 fi
107119
120+
108121 JVM_OPTS=" ${JVM_OPTS} -DIReallyKnowWhatIAmDoingISwear"
109122 export JVM_OPTS
110123}
0 commit comments