Add find_appcast script

This commit is contained in:
Vítor Galvão
2018-05-24 10:20:52 +01:00
parent f5b04ef91b
commit c7cac221a3
+118
View File
@@ -0,0 +1,118 @@
#!/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')
function usage {
echo "usage: ${0} <path_to_app>"
}
function absolute_path {
echo "$(cd "$(dirname "${1}")" && pwd)/$(basename "${1}")"
}
function appcast_found {
local http_response checkpoint
# validate appcast
http_response="$(curl --silent --head "${user_agent[@]}" --write-out '%{http_code}' "${url}" -o /dev/null)"
[[ "${http_response}" != '200' ]] && appcast_found_error "${url}" "returned a non-200 (OK) HTTP response code (${http_response})"
checkpoint=$(brew cask _appcast_checkpoint --calculate "${url}")
[[ "${checkpoint}" == 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ]] && appcast_found_error "${url}" 'seems to be empty'
# output appcast
echo "An appcast was found. You should add it to your cask as:
appcast '${url}',
checkpoint: '${checkpoint}'
You should likely also add 'auto_updates true'
"
exit 0
}
function appcast_found_error {
local url error
url="${1}"
error="${2}"
echo "An appcast was found pointing to ${url}, but it ${error}. You should:
1. Check your internet connection.
2. Try again later.
3. Contact the developer.
"
exit 1
}
function url_exists {
local url
url="${1}"
[[ "$(curl --silent "${url}")" == '[]' ]] && return 1 # Special case for empty devmate appcasts
curl --output /dev/null --silent --head --fail "${url}"
}
function find_sparkle {
local app plist url
app="${1}"
plist="${app}/Contents/Info.plist"
url="$(defaults read "${plist}" 'SUFeedURL' 2>/dev/null)"
if url_exists "${url}"; then
appcast_found "${url}"
fi
}
function find_hockeyapp {
local app binary identifier_hex url
app="${1}"
binary="$(find "${path_to_app}/Contents/MacOS" -type f -print -quit)"
identifier_hex="$(strings "${binary}" | grep --extended-regexp '^[a-f0-9]{32}$')"
url="https://rink.hockeyapp.net/api/2/apps/${identifier_hex}"
if url_exists "${url}"; then
appcast_found "${url}"
fi
}
function find_devmate {
local app bundle_id url
app="${1}"
bundle_id="$(mdls -raw -name kMDItemCFBundleIdentifier "${app}")"
url="https://updates.devmate.com/${bundle_id}.xml"
if url_exists "${url}"; then
appcast_found "${url}"
fi
}
# exit if no argument (or more than one) was given
if [[ -z "${1}" ]] || [[ -n "${2}" ]]; then
usage
exit 1
fi
readonly path_to_app="$(absolute_path "${1}")"
if [[ ! -d "${path_to_app}" ]] || [[ "${path_to_app}" != *'.app' ]]; then
echo 'You need to use this on a .app. Please verify your target.'
usage
exit 1
fi
find_sparkle "${path_to_app}"
find_hockeyapp "${path_to_app}"
find_devmate "${path_to_app}"
echo 'This script was not able to detect an appcast on this app.'