Skip to content

Instantly share code, notes, and snippets.

@beastycoding
Forked from danielcosta/updateJetbrains.sh
Created November 2, 2018 19:43
Show Gist options
  • Save beastycoding/665a0de09f20511c226851c7e982e134 to your computer and use it in GitHub Desktop.
Save beastycoding/665a0de09f20511c226851c7e982e134 to your computer and use it in GitHub Desktop.
Script to update PhpStorm and others Jetbrains products
#!/usr/bin/env bash
VERSION_PATTERN="([0-9]+\.[0-9]+\.[0-9]+)"
case "${1}" in
"phpstorm")
TOOL_NAME="PhpStorm"
INSTALL_DIR="/opt/phpstorm"
case "${2}" in
"eap")
URL="https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program"
FILE="PhpStorm-EAP-[0-9\.]+(:?[a-z\-]+)?.tar.gz"
;;
*)
URL="https://data.services.jetbrains.com//products/releases?code=PS&latest=true&type=release&build=&_=`date +%s`"
FILE="PhpStorm-[0-9\.]+.tar.gz"
esac
DOWNLOAD_URL="https://download.jetbrains.com/webide/"
;;
"pycharm")
TOOL_NAME="PyCharm"
INSTALL_DIR="/opt/pycharm"
case "${2}" in
"eap")
URL="http://confluence.jetbrains.com/display/PYH/JetBrains+PyCharm+Preview+%28EAP%29"
FILE="pycharm-professional-[0-9\.]+(:?[a-z\-]+)?.tar.gz"
;;
*)
URL="https://data.services.jetbrains.com//products/releases?code=PCP&latest=true&type=release&build=&_=`date +%s`"
FILE="PyCharm-professional-[0-9\.]+.tar.gz"
esac
DOWNLOAD_URL="https://download.jetbrains.com/python/"
;;
"rubymine")
TOOL_NAME="RubyMine"
INSTALL_DIR="/opt/rubymine"
case "${2}" in
"eap")
URL="https://confluence.jetbrains.com/display/RUBYDEV/Early+Access+Program"
FILE="RubyMine-[0-9\.]+.tar.gz"
;;
*)
URL="https://data.services.jetbrains.com//products/releases?code=RM&latest=true&type=release&build=&_=`date +%s`"
FILE="RubyMine-[0-9\.]+.tar.gz"
esac
DOWNLOAD_URL="https://download.jetbrains.com/ruby/"
;;
"webstorm")
TOOL_NAME="WebStorm"
INSTALL_DIR="/opt/webstorm"
case "${2}" in
"eap")
URL="https://confluence.jetbrains.com/display/WI/WebStorm+EAP"
FILE="WebStorm-[0-9\.]+.tar.gz"
;;
*)
URL="https://data.services.jetbrains.com//products/releases?code=WS&latest=true&type=release&build=&_=`date +%s`"
FILE="WebStorm-[0-9\.]+.tar.gz"
esac
DOWNLOAD_URL="https://download.jetbrains.com/webstorm/"
;;
*)
echo "Not supported"
exit 1
esac
BUILD_PATTERN=">[0-9]+\.[0-9]+\.[0-9]+<"
echo "Checking for ${TOOL_NAME} updates..."
BUILD_FILE="${INSTALL_DIR}/build.txt"
VERSION=$(curl -s "${URL}" | grep -Eo "${VERSION_PATTERN}" | head -1)
BUILD=$(curl -s "${URL}" | grep -Eo "${VERSION_PATTERN}" | head -8 | tail -1)
FILE=${TOOL_NAME}-${VERSION}.tar.gz
URL=${DOWNLOAD_URL}${FILE}
# echo ${BUILD_FILE};
# echo ${VERSION};
# echo ${BUILD};
# echo ${INSTALL_DIR};
# echo ${URL};
# echo ${FILE};
# exit;
if [ -z "${VERSION}" ]
then
echo "ERROR: No release found"
exit 1
fi
# Check current installed version if available
if [ -f "${BUILD_FILE}" ]
then
CURRENT_VERSION=$(cat ${INSTALL_DIR}/build.txt | grep -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
echo "Found ${TOOL_NAME}-${CURRENT_VERSION} at ${INSTALL_DIR}"
if [ "${CURRENT_VERSION}" == "${BUILD}" ]
then
echo "You have the latest version of ${TOOL_NAME} already installed."
exit;
fi
else
echo "No ${TOOL_NAME} found at ${INSTALL_DIR}"
fi
echo "Updating to ${TOOL_NAME} ${VERSION}"
TMP_DIR="/tmp/${TOOL_NAME}-${VERSION}"
TMP_FILE="${TMP_DIR}/${FILE}"
case "${TOOL_NAME}" in
"RubyMine")
EXTRACTED="${TMP_DIR}/${TOOL_NAME}-${VERSION}"
;;
*)
EXTRACTED="${TMP_DIR}/${TOOL_NAME}-${BUILD}"
esac
# echo ${TMP_DIR};
# echo ${TMP_FILE};
# echo ${EXTRACTED};
# exit;
# Create tmp dirctory for download and extracting
if [ ! -d "${TMP_DIR}" ]
then
mkdir "${TMP_DIR}"
fi
# Check if already extracted
if [ ! -d "${EXTRACTED}" ]
then
# Check if already downloaded
if [ ! -f "${TMP_FILE}" ]
then
echo "Downloading to ${TMP_FILE}"
curl -L --progress-bar -o "${TMP_FILE}" "${URL}"
fi
echo "Extracting..."
tar zxf ${TMP_FILE} -C ${TMP_DIR}
fi
echo "Installing to ${INSTALL_DIR}"
if [ -d "${INSTALL_DIR}" ]
then
rm -rf ${INSTALL_DIR}
fi
sudo mv $(echo ${EXTRACTED}) "${INSTALL_DIR}/"
echo "Cleanup..."
rm -rf "${TMP_DIR}"
echo "Done."
#!/usr/bin/env bash
TOOL_NAME="PhpStorm"
INSTALL_DIR="/opt/phpstorm"
EAP_URL="https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program"
EAP_FILE="PhpStorm-EAPxxxxxxxxxxxxxxx-[0-9\.]+(:?[a-z\-]+)?.tar.gz"
STABLE_URL="https://confluence.jetbrains.com/display/PhpStorm/Previous+PhpStorm+Releases"
STABLE_FILE="PhpStorm-[0-9\.]+.tar.gz"
DOWNLOAD_URL="http://download-cf.jetbrains.com/webide/"
BUILD_PATTERN=">[0-9]+\.[0-9]+\.[0-9]+<"
echo "Checking for ${TOOL_NAME} updates..."
BUILD_FILE="${INSTALL_DIR}/build.txt"
FILE=$(curl -s "${STABLE_URL}" | grep -Eo "${STABLE_FILE}" | head -1)
FILE2=$(curl -s "${STABLE_URL}" | grep -Eo "${BUILD_PATTERN}" | head -1)
VERSION=$(echo $FILE | grep -Eo "([0-9]+\.[0-9]+(:?\.[0-9]+)?)")
BUILD=$(echo $FILE2 | grep -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
URL="${DOWNLOAD_URL}${FILE}"
if [ -z "${VERSION}" ]
then
echo "ERROR: No release found"
exit 1
fi
# Check current installed version if available
if [ -f "${BUILD_FILE}" ]
then
CURRENT_VERSION=$(cat ${INSTALL_DIR}/build.txt | grep -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
echo "Found ${TOOL_NAME}-${CURRENT_VERSION} at ${INSTALL_DIR}"
if [ "${CURRENT_VERSION}" == "${BUILD}" ]
then
echo "You have the latest version of ${TOOL_NAME} already installed."
fi
else
echo "No ${TOOL_NAME} found at ${INSTALL_DIR}"
fi
echo "Updating to ${TOOL_NAME} ${VERSION}"
TMP_DIR="/tmp/${TOOL_NAME}-tmp-${VERSION}"
TMP_FILE="${TMP_DIR}/${FILE}"
EXTRACTED="${TMP_DIR}/${TOOL_NAME}-${BUILD}"
# Create tmp dirctory for download and extracting
if [ ! -d "${TMP_DIR}" ]
then
mkdir "${TMP_DIR}"
fi
# Check if already extracted
if [ ! -d "${EXTRACTED}" ]
then
# Check if already downloaded
if [ ! -f "${TMP_FILE}" ]
then
echo "Downloading to ${TMP_FILE}"
curl -L --progress-bar -o "${TMP_FILE}" "${URL}"
fi
echo "Extracting..."
tar zxf ${TMP_FILE} -C ${TMP_DIR}
rm ${TMP_FILE}
fi
echo "Installing to ${INSTALL_DIR}"
if [ -d "${INSTALL_DIR}" ]
then
rm -rf ${INSTALL_DIR}
fi
mv $(echo ${EXTRACTED}) "${INSTALL_DIR}/"
echo "Cleanup..."
rm -rf "${TMP_DIR}"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment