+check_url() {
+ if [[ $DOWNLOADER_NAME == 'wget' ]]; then
+ if [[ $(wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then
+ return 0
+ else
+ return 1
+ fi
+ elif [[ $DOWNLOADER_NAME == 'curl' ]]; then
+ local code=$(curl -sL -w "%{http_code}\\n" "$1" -o /dev/null)
+ if [[ $code -eq 200 ]]; then return 0; else return 1; fi
+ else
+ $ECHO "error: wget or curl required in check_url"
+ exit_script 12
+ fi
+}
+
+# If we are on a branch, first try to get a boot image for that branch.
+# Otherwise, just use `master`
+set_boot_image_vars() {
+ set_current_branch
+ local url="https://downloads.factorcode.org/images/${CURRENT_BRANCH}/checksums.txt"
+ check_url $url
+ if [[ $? -eq 0 ]]; then
+ CHECKSUM_URL="$url"
+ BOOT_IMAGE_URL="https://downloads.factorcode.org/images/${CURRENT_BRANCH}/${BOOT_IMAGE}"
+ else
+ $ECHO "boot image for branch \`${CURRENT_BRANCH}\` is not on server, trying master instead"
+ $ECHO " tried nonexistent url: ${url}"
+ CHECKSUM_URL="https://downloads.factorcode.org/images/master/checksums.txt"
+ BOOT_IMAGE_URL="https://downloads.factorcode.org/images/master/${BOOT_IMAGE}"
+ fi