Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Updates PhpStorm EAP on Mac OS (don't work from PhpStorm 2016.1.1) - http://blog.popstas.ru/blog/2016/01/17/automacic-update-phpstorm-eap-on-mac-os/
#!/bin/bash
# blog post (rus) - http://blog.popstas.ru/blog/2016/01/17/automacic-update-phpstorm-eap-on-mac-os/
# usage: just run it!
set -euo pipefail
get_phpstorm_url() {
download_page="https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program"
url=$(curl -s "$download_page" | grep -oE "http:\/\/[a-zA-Z0-9\.\/-]+\.dmg")
echo "$url"
}
download_dmg() {
url="$1"
if [ -z "$url" ]; then
echo >&2 "No link to dmg found"
exit 1
fi
download_version=$(echo "$url" | grep -oE "[0-9\.]+\.dmg" | sed 's/\.dmg//g')
current_version=$(cat "/Applications/PhpStorm EAP.app/Contents/Resources/build.txt" | \
sed 's/PS\-//g')
if [ "$current_version" = "$download_version" ]; then
echo >&2 "You have latest version installed"
exit 1
fi
echo >&2 "Current version: $current_version"
echo >&2 "Download version: $download_version"
dest="$HOME/Downloads/PhpStorm-EAP-${download_version}.dmg"
wget -O "$dest" "$url"
echo "$dest"
}
close_phpstorm() {
phpstorm_pid=$(ps aux | grep "/Applications/PhpStorm EAP.app/Contents/MacOS/phpstorm" | \
grep -v grep | awk '{print $2}' || true)
if [ -n "$phpstorm_pid" ]; then
echo >&2 "Close running phpstorm"
kill "$phpstorm_pid"
fi
}
main() {
if [ -z "$(echo $OSTYPE | grep darwin)" ]; then
echo >&2 "Can be run only on Mac OS"
exit 1
fi
url="$(get_phpstorm_url)"
dest="$(download_dmg "$url" | tail -n1)"
mounted="$(hdiutil attach "$dest" | tail -n1 | grep -o "/Volumes/.*")"
close_phpstorm
rm -rf "/Applications/PhpStorm EAP.app/"
cp -a "$mounted/PhpStorm EAP.app" "/Applications/PhpStorm EAP.app"
open -a "PhpStorm EAP"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.