Skip to content

Instantly share code, notes, and snippets.

@popstas
Last active March 12, 2017 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popstas/613a72a34576b85caec4 to your computer and use it in GitHub Desktop.
Save popstas/613a72a34576b85caec4 to your computer and use it in GitHub Desktop.
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