#!/bin/bash absPath() { if [[ "$(uname -s)" == "Darwin" ]]; then echo "$(cd $(dirname $1); pwd)/$(basename $1)"; else readlink -f "$1" fi } if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then echo "Usage: $0 " echo echo "This script will update the current installation." echo "Make sure that you provide *all* required update sites, otherwise some extension may not be updated" echo "or the update process will even fail due to unsatisfied dependencies." echo echo "Example: $0 http://update.knime.com/analytics-platform/3.6" echo echo "You can also provide zipped update sites with their full (!) path." echo echo "Example $0 /tmp/org.knime.update.analytics-platform_3.6.0.zip" exit 0 fi unset DISPLAY # We assume that this script is in the root of the executor installation MYSELF=$(absPath $0) INST_DIR=${MYSELF%/*} TEMP=${TEMP:-/tmp} DIRECTOR="./knime -nosplash -consolelog -application org.eclipse.equinox.p2.director" UPDATE_SITES=$1 if [[ -z "$UPDATE_SITES" ]]; then echo "No update sites provided" exit 1 fi if [[ ! -w "${INST_DIR}" ]]; then echo "Current user does not have write access to ${INST_DIR}" exit 1 fi cd "${INST_DIR}" IFS="," US_LIST="" for us in ${UPDATE_SITES}; do if [[ "$us" =~ \.zip$ ]]; then US_LIST="${US_LIST}jar:file://${us}!/," else US_LIST="${US_LIST}${us}," fi done unset IFS echo "Retrieving list of installed features, this shouldn't take long..." ${DIRECTOR} -lir -destination "${INST_DIR}" | grep / | sort | uniq > "${TEMP}/installed.$$" if $(grep -q com.knime.features.reporting "${TEMP}/installed.$$"); then OLD_REPORTING_FOUND=1 sed -i -e 's/com.knime.features.reporting./org.knime.features.reporting./g;' "${TEMP}/installed.$$" sort -u "${TEMP}/installed.$$" > "${TEMP}/installed1.$$" && mv "${TEMP}/installed1.$$" "${TEMP}/installed.$$" fi echo "Retrieving list of available updates, this may take some time..." ${DIRECTOR} -repository "${US_LIST}" -list | grep = | tr = / | sort | uniq > "${TEMP}/available.$$" # Remove IUs for which there is no update but which exist on the update site (they would be uninstalled otherwise) comm -12 "${TEMP}/installed.$$" "${TEMP}/available.$$" > "${TEMP}/both.$$" comm -13 "${TEMP}/both.$$" "${TEMP}/available.$$" | awk -F / '{ print $1 }' | sort > "${TEMP}/available2.$$" comm -23 "${TEMP}/installed.$$" "${TEMP}/available2.$$" | awk -F / '{ print $1 }' | sort > "${TEMP}/installed2.$$" awk -F / '{ print $1 }' "${TEMP}/available2.$$" | sort > "${TEMP}/available3.$$" # Remove IUs that don't exist on the update site at all IUs=$(comm -12 "${TEMP}/installed2.$$" "${TEMP}/available3.$$" | tr '\n' ,) if [[ -z "$IUs" ]]; then echo "No updates found" else INSTALL_IUs=${IUs} UNINSTALL_IUs=${IUs} if [[ "$OLD_REPORTING_FOUND" == "1" ]]; then UNINSTALL_IUs=${UNINSTALL_IUs/org.knime.features.reporting./com.knime.features.reporting.} fi set -e ${DIRECTOR} -r "${US_LIST}" -i "${INSTALL_IUs}" -u "${UNINSTALL_IUs}" -d "${INST_DIR}" rm -rf "${INST_DIR}"/configuration/org.eclipse.osgi rm -rf ~/.eclipse/*/configuration/org.eclipse.osgi fi rm -f "${TEMP}"/installed*.$$ "${TEMP}"/available*.$$ "${TEMP}"/both*.$$