-
-
Save tarranjones/74ac994cdad352f59b5547e149163ae1 to your computer and use it in GitHub Desktop.
Update/Install the latest PhpStorm EAP automatically (add to external tools)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
####################################################################################################################### | |
# | |
# Updates/Install the latest PhpStorm EAP | |
# | |
# -------------------------------------------------------------------------------------------------------------------- | |
# | |
# * Retrieves the current version from the EAP wiki | |
# * If the new version is not the current version (based on symlink to PhpStorm) then updates | |
# * Creates a symlink from versioned folder to PhpStorm | |
# | |
# -------------------------------------------------------------------------------------------------------------------- | |
# | |
# Configuration environment variables: | |
# | |
# PHPSTORM_HOME The location of the folder containing the PhpStorm installation | |
# If installed at ~/Apps/PhpStorm then this is ~/Apps/PhpStorm | |
# Default is ~/Apps/PhpStorm | |
# | |
# -------------------------------------------------------------------------------------------------------------------- | |
# | |
# Usage: | |
# | |
# Execute or add as an external tool to PhpStorm | |
# | |
# Execute this script: | |
# | |
# curl -Ls https://gist.githubusercontent.com/AubreyHewes/4f45ade2aaad575faa8e/raw | sh | |
# | |
# External tool: | |
# | |
# You can add this script to the PhpStorm external tools by creating a new script with | |
# the above contents and referring to this new script as the external tool: | |
# | |
# i.e. | |
# External tool command is "~/bin/phpstorm-eap-update" with script "~/bin/phpstorm-eap-update" contents as | |
# curl -Ls https://gist.githubusercontent.com/AubreyHewes/4f45ade2aaad575faa8e/raw | sh | |
# | |
####################################################################################################################### | |
# Configuration | |
# set "PHPSTORM_HOME" to the directory that contains the installed "PhpStorm" | |
# if not set then uses the default of "~/Apps/PhpStorm" | |
if [ "${PHPSTORM_HOME}" = "" ]; then | |
PHPSTORM_HOME=~/Apps/PhpStorm | |
fi | |
# the url containing the update download uri | |
PHPSTORM_EAP_URL="https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program" | |
############################################################################### | |
# do not change anything below here... ;-) | |
echo "[PhpStorm EAP Updater]" | |
# create home parent if not exists | |
HOME_PARENT=$(dirname ${PHPSTORM_HOME}) | |
if [ ! -d "${HOME_PARENT}" ]; then | |
echo "Creating home parent: ${HOME_PARENT}" | |
mkdir -p ${HOME_PARENT} | |
fi | |
# go to the home parent | |
cd ${HOME_PARENT} | |
# get the update uri | |
echo -n "Retrieving latest version... " | |
UPDATE_URI=$(curl -s ${PHPSTORM_EAP_URL} | grep -E "PhpStorm(-EAP)?-[0-9]+(\.[0-9]+)?(\.[0-9]+)?\.tar\.gz" | sed -e 's|.*href\=\"\(http://download.jetbrains.com/webide/PhpStorm-EAP.[^\"]*.tar.gz\)\".*|\1|g') | |
if [ "${UPDATE_URI}" = "" ]; then | |
echo "failed!" | |
echo "ERROR: Could not find update (check PHPSTORM_EAP_URL is correct) !!!" | |
exit 1 | |
fi | |
# get the current version | |
CURRENT_VERSION=$(readlink PhpStorm) | |
if [ "${CURRENT_VERSION}" = "" ]; then | |
CURRENT_VERSION="None" | |
fi | |
# get the new version | |
NEW_VERSION=$(echo "${UPDATE_URI}" | sed -e "s|.*-EAP|PhpStorm|g" | sed -e "s|.tar.gz||g") | |
echo " found latest version: ${NEW_VERSION}" | |
# check the new version against the current version | |
if [ "${CURRENT_VERSION}" = "${NEW_VERSION}" ]; then | |
echo "Current version is already: ${NEW_VERSION}" | |
exit | |
fi | |
# perform the update | |
echo "Updating..." | |
# either download the update file or if already exists reuse the previous downloaded update file | |
UPDATE_FILE=$(echo "${UPDATE_URI}" | sed -e "s|.*PhpStorm|PhpStorm|g") | |
if [ ! -f "${UPDATE_FILE}" ]; then | |
echo -n " + Downloading..." | |
wget --progress=dot:giga "${UPDATE_URI}" | |
if [ $? != 0 ]; then | |
echo "ERROR: can not download: ${UPDATE_URI}" | |
exit 1 | |
fi | |
echo " done." | |
else | |
echo " + Using cache" | |
fi | |
if [ ! -f "${UPDATE_FILE}" ]; then | |
echo "ERROR: failed to retrieve update" | |
exit 1 | |
fi | |
tar -xzf ${UPDATE_FILE} | |
if [ $? != 0 ]; then | |
echo "ERROR: corrupt archive; delete the archive and try again: ${UPDATE_FILE}" | |
exit 1 | |
fi | |
# relink "PhpStorm" to the new version | |
rm -f PhpStorm && ln -s ${NEW_VERSION} PhpStorm | |
# show some info | |
echo "Updated ${CURRENT_VERSION} -> $(readlink PhpStorm)" | |
echo " * This build includes a 30-day time-limited license." | |
echo " * Release notes: http://blog.jetbrains.com/phpstorm/" | |
cd $OLDPWD | |
# eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment