Merge pull request #16701 from vitorgalvao/find_sparkle_appcast

developer scripts: add find_sparkle_appcast
This commit is contained in:
Vítor Galvão 2016-01-12 00:46:11 +00:00
commit 6d2ececc02
1 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,77 @@
#!/bin/bash
#
# find_sparkle_appcast
#
###
### functions
###
usage() {
local program exit_status
program="$(basename "$0")"
exit_status="$1"
echo "usage: ${program} <path_to_app>"
exit "${exit_status}"
}
absolute_path() {
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
appcast_found_error() {
local error_reason="$1"
echo "An appcast was found, but it ${error_reason}. You should:
1. Check your internet connection.
2. Try again later.
3. Contact the developer."
exit 1
}
###
### main
###
# 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
# vaidate appcast
appcast_http_response="$(curl --silent --head --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_sha=$(curl --silent "${appcast_url}" | shasum --algorithm 256 | awk '{ print $1 }')
[[ "${appcast_sha}" == 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ]] && appcast_found_error 'seems to be empty'
# output appcast
echo "A Sparkle appcast was found. You sould add it to your cask as
appcast '${appcast_url}',
:sha256 => '${appcast_sha}'
You should likely also add 'auto_updates true'"
exit 0