#!/bin/bash readonly user_agent=(--user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36') usage() { local program exit_status program="$(basename "$0")" exit_status="$1" echo "usage: ${program} " exit "${exit_status}" } absolute_path() { echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" } appcast_found_error() { local error_reason="$1" echo "An appcast was found pointing to ${appcast_url}, but it ${error_reason}. You should: 1. Check your internet connection. 2. Try again later. 3. Contact the developer." exit 1 } # exit if no argument (or more than one) was given if [[ -z "$1" ]] || [[ -n "$2" ]]; then usage 1 fi # get plist path_to_app="$(absolute_path "$1")" path_to_plist="${path_to_app}/Contents/Info.plist" if [[ ! -f "${path_to_plist}" ]]; then echo 'You need to use this on a .app bundle. Please verify your target.' usage 1 fi # get appcast appcast_url="$(defaults read "${path_to_plist}" 'SUFeedURL' 2>/dev/null)" if [[ -z "${appcast_url}" ]]; then echo 'It appears this app does not have a Sparkle appcast' exit 0 fi # validate appcast appcast_http_response="$(curl --silent --head "${user_agent[@]}" --write-out '%{http_code}' "${appcast_url}" -o /dev/null)" [[ "${appcast_http_response}" != '200' ]] && appcast_found_error "returned a non-200 (OK) HTTP response code (${appcast_http_response})" appcast_checkpoint=$(brew cask _appcast_checkpoint --calculate "${appcast_url}") [[ "${appcast_checkpoint}" == 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ]] && appcast_found_error 'seems to be empty' # output appcast echo "A Sparkle appcast was found. You should add it to your cask as appcast '${appcast_url}', checkpoint: '${appcast_checkpoint}' You should likely also add 'auto_updates true'" exit 0