Last active
October 7, 2017 10:53
-
-
Save piotrpolak/6dfeae405a6b6d999cf5f16f5615d70c to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# Usage: ./update_phpstorm_eap.sh | |
# Download and run: wget -O ~/update_phpstorm_eap.sh https://gist.githubusercontent.com/piotrpolak/6dfeae405a6b6d999cf5f16f5615d70c/raw/842e9ad7650265a9c7a76c8699e10fad58814af9/update_phpstorm_eap.sh && chmod +x ~/update_phpstorm_eap.sh && ~/update_phpstorm_eap.sh | |
# Your custom location | |
PHPSTORM_DESTINATION="/home/${USER}/Apps/PhpStorm" | |
# Page containing links to the latest EAP tar.gz | |
EAP_PAGE_URL='https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program' | |
# ---------------------------------------------------------------------------------------------------- | |
# Based on http://stackoverflow.com/questions/2804467/spider-a-website-and-return-urls-only | |
echo "Parsing links..." | |
EAP_TAR_GZ_URL=`wget -q "$EAP_PAGE_URL" -O - | \ | |
tr "\t\r\n'" ' "' | \ | |
grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' | \ | |
sed -e 's/^.*"\([^"]\+\)".*$/\1/g' | \ | |
grep -i -o '.*\.tar\.gz$'` | |
if [ -z $EAP_TAR_GZ_URL ]; | |
then | |
echo "No download links found at $EAP_PAGE_URL" | |
exit 9 | |
fi | |
NUMBER_OF_LINKS=`echo "$EAP_TAR_GZ_URL" | wc -l` | |
if [ $NUMBER_OF_LINKS -gt 1 ]; | |
then | |
echo "Too many download links $EAP_PAGE_URL" | |
echo "$EAP_TAR_GZ_URL" | |
exit 9 | |
else | |
EAP_TAR_GZ_URL_TO_DOWNLOAD="$EAP_TAR_GZ_URL" | |
fi | |
EAP_LOCAL_TMP_FILE=`mktemp` | |
EAP_LOCAL_TMP_DIR=`mktemp -d` | |
echo "Downloading $EAP_TAR_GZ_URL_TO_DOWNLOAD..." | |
wget -q --show-progress "$EAP_TAR_GZ_URL_TO_DOWNLOAD" -O "$EAP_LOCAL_TMP_FILE" | |
if [ $? -ne 0 ]; | |
then | |
echo "Unable to download file $EAP_TAR_GZ_URL_TO_DOWNLOAD" | |
exit 11 | |
fi | |
echo "Extracting archive contents..." | |
tar xzf "$EAP_LOCAL_TMP_FILE" -C "$EAP_LOCAL_TMP_DIR" | |
if [ $? -ne 0 ]; | |
then | |
echo "Unable to untar file $EAP_LOCAL_TMP_FILE" | |
exit 12 | |
fi | |
unlink "$EAP_LOCAL_TMP_FILE" | |
UNZIPED_DIR=`find "$EAP_LOCAL_TMP_DIR" -maxdepth 1 -type d -name PhpStorm* -print` | |
if [ -z $UNZIPED_DIR ]; | |
then | |
echo "Unzipped directory does not contain PhpStorm directory." | |
exit 13 | |
fi | |
eval PHPSTORM_DESTINATION=$PHPSTORM_DESTINATION | |
if [ -d "$PHPSTORM_DESTINATION" ]; | |
then | |
echo "Removing previous installation..." | |
rm -rf "$PHPSTORM_DESTINATION" | |
fi | |
mv "$UNZIPED_DIR" "$PHPSTORM_DESTINATION" | |
rm -rf "$EAP_LOCAL_TMP_DIR" | |
LUNCHER_PATH="${PHPSTORM_DESTINATION}/bin/phpstorm.sh" | |
chmod +x "$LUNCHER_PATH" | |
echo "PHPStorm EAP successfully updated!" | |
nhoup $LUNCHER_PATH &> /dev/null & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment