diff --git a/screening/.classpath b/screening/.classpath index 4f2e3b0b2b03f3700ac90f06e62839ed566becec..4404042bc10a0cfc7662b544d6dfc3c3dbc8d5e7 100644 --- a/screening/.classpath +++ b/screening/.classpath @@ -50,5 +50,6 @@ <classpathentry kind="lib" path="/libraries/cisd-image_readers/cisd-image_readers-bioformats.jar"/> <classpathentry kind="lib" path="/libraries/cisd-image_readers/cisd-image_readers.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="/libraries/izpack/standalone-compiler.jar"/> <classpathentry kind="output" path="targets/www/WEB-INF/classes"/> </classpath> diff --git a/screening/build/build.xml b/screening/build/build.xml index 5a776c2381449ad136af744b3bfa157911f33aac..4f90b8968f93eb92062d8109ffc88e201efdbd46 100644 --- a/screening/build/build.xml +++ b/screening/build/build.xml @@ -13,26 +13,65 @@ <property name="dist.screening-api.jar" value="${dist.screening-api.lib}/openbis_screening_api.jar" /> <property name="dist.screening-api-batteries-included.jar" value="${dist.screening-api.lib}/openbis_screening_api-batteries_included.jar" /> <property name="dist.screening-api.src" value="${dist.screening-api}/openbis_screening_api_source.zip" /> - <property name="dist.screening-api.javadoc" value="${dist.screening-api}/doc" /> + <property name="dist.screening-api.javadoc" value="${dist.screening-api}/doc" /> <property name="dist.screening-api.javadoc.zip" value="${dist.screening-api}/openbis_screening_api_javadoc.zip" /> - - <property name="classes.screening" value="../screening/targets/ant/classes" /> - <property name="classes.openbis" value="../openbis/targets/ant/classes" /> - <property name="classes.common-server" value="../server-common/targets/ant/classes" /> + + <property name="classes.screening" value="../screening/targets/ant/classes" /> + <property name="classes.openbis" value="../openbis/targets/ant/classes" /> + <property name="classes.common-server" value="../server-common/targets/ant/classes" /> <property name="classes.common" value="../common/targets/ant/classes" /> + <!-- absolute path referenced from IzPack Ant task --> + <property name="installer.basedir" value="${basedir}/dist/installer" /> + <!-- relative path referenced from within the installer compilation --> + <property name="installer.resourcedir" value="../../dist/installer" /> + <property name="installer.jar.file" value="${basedir}/${dist}/installer.jar" /> + + <taskdef name="izpack" classpath="${lib}/izpack/standalone-compiler.jar" + classname="com.izforge.izpack.ant.IzPackTask"/> + <target name="compile" depends="build-common.compile, clean" /> + + <!-- // Task for creating distributions - --> + --> <target name="dist" depends="openbis.make-dist, make-full-dss-dist, dss-plugin-jar, datastore_server.make-plugin-dist, screening-api"> <zip update="true" destfile="${server.dist.file}"> <zipfileset file="${jars.to.be.signed.zip}"/> </zip> <delete file="${jars.to.be.signed.zip}"/> - </target> + </target> + + <target name="create-installer"> + + <!-- make the "admin" directory available to the installer as "bin" --> + <copy todir="${classes.screening}/bin"> + <fileset dir="${installer.basedir}/../admin"> + <include name="**/*"/> + <exclude name="svn-update.sh"/> + </fileset> + </copy> + + <izpack input="${installer.basedir}/install.xml" + output="${installer.jar.file}" + inheritAll="true" + installerType="standard" + basedir="${basedir}/${dist}"/> + + <jar update="true" destfile="${installer.jar.file}"> + <fileset dir="${classes.screening}"> + <include name="ch/systemsx/cisd/openbis/installer/izpack/**/*"/> + </fileset> + <zipfileset src="${lib}/postgresql/postgresql.jar"> + <exclude name="META_INF/*"/> + <include name="**/*"/> + </zipfileset> + </jar> + + </target> <target name="dss-plugin-jar" depends="compile"> <mkdir dir="${dist}/data" /> diff --git a/screening/dist/admin/backup-installation.sh b/screening/dist/admin/backup-installation.sh new file mode 100755 index 0000000000000000000000000000000000000000..3ef8a0999988a4c3c2695d725b131e672974cd53 --- /dev/null +++ b/screening/dist/admin/backup-installation.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Moves the current installation to a backup folder. +BASE=`dirname "$0"` +if [ ${BASE#/} == ${BASE} ]; then + BASE="`pwd`/${BASE}" +fi + +BACKUP_DIR=$1 +if [ "$BACKUP_DIR" == "" ]; then + echo ERROR: directory in which configuration should be stored has not been specified! + exit 1 +fi + +source $BASE/env + +$BASE/alldown.sh + +ROOT_DIR=$BASE/../servers +CONFIG=$BACKUP_DIR/config-backup + +echo "Creating backup folder $BACKUP_DIR ..." +mkdir -p $CONFIG +$BASE/backup-config.sh $CONFIG + +OLD_BIS=$BACKUP_DIR/openBIS-server + +echo "Copying old installation to backup dir" + +echo "mv $ROOT_DIR/openBIS-server $OLD_BIS" +mv $ROOT_DIR/openBIS-server $OLD_BIS + +echo "mv $ROOT_DIR/datastore_server $BACKUP_DIR/datastore_server" +mv $ROOT_DIR/datastore_server $BACKUP_DIR/datastore_server + + + +# Note: to restore the database afterwards one can use: +# pg_restore -d db-name db-file.dmp +echo "Creating database dumps for $OPENBIS_DB and $IMAGING_DB..." + +echo "pg_dump -U $DB_USER_NAME -Fc $OPENBIS_DB > $BACKUP_DIR/$OPENBIS_DB.dmp" +pg_dump -U $DB_USER_NAME -Fc $OPENBIS_DB > $BACKUP_DIR/$OPENBIS_DB.dmp + +# screening-specific +echo "pg_dump -U $DB_USER_NAME -Fc $IMAGING_DB > $BACKUP_DIR/$IMAGING_DB.dmp" +pg_dump -U $DB_USER_NAME -Fc $IMAGING_DB > $BACKUP_DIR/$IMAGING_DB.dmp + +echo "DONE" diff --git a/screening/dist/admin/restore-config-from-backup.sh b/screening/dist/admin/restore-config-from-backup.sh index b018b9d36412855139240489a357c4b1c10504bb..f9257160763f0b715871beffbe24dbc3e8a6b4d1 100755 --- a/screening/dist/admin/restore-config-from-backup.sh +++ b/screening/dist/admin/restore-config-from-backup.sh @@ -16,6 +16,8 @@ fi source $BASE/common-functions.sh ROOT=$BASE/../servers +echo "Restorting configuration backup from $CONF to $ROOT ..." + # -- AS cp $CONF/service.properties $ROOT/openBIS-server/jetty/webapps/openbis/WEB-INF/classes/ cp $CONF/log.xml $ROOT/openBIS-server/jetty/etc/ diff --git a/screening/dist/installer/backup-installation.xml b/screening/dist/installer/backup-installation.xml new file mode 100644 index 0000000000000000000000000000000000000000..f5c947a2e67e085aa2a3a7ea8f2c593a87ef4a93 --- /dev/null +++ b/screening/dist/installer/backup-installation.xml @@ -0,0 +1,7 @@ +<processing> + <job name="Backup existing installation"> + <executefile name="$INSTALL_BIN_PATH/backup-installation.sh"> + <arg>$BACKUP_FOLDER</arg> + </executefile> + </job> +</processing> \ No newline at end of file diff --git a/screening/dist/installer/default-install-dir.txt b/screening/dist/installer/default-install-dir.txt new file mode 100644 index 0000000000000000000000000000000000000000..a352e361a8f7b8b27eea045482332725c06614d7 --- /dev/null +++ b/screening/dist/installer/default-install-dir.txt @@ -0,0 +1 @@ +$USER_HOME/openbis \ No newline at end of file diff --git a/screening/dist/installer/eng.xml b/screening/dist/installer/eng.xml new file mode 100644 index 0000000000000000000000000000000000000000..fc81b2937f57b50ecb23209d8c192f55608d3942 --- /dev/null +++ b/screening/dist/installer/eng.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<langpack> + <str id="data.validation.error.title" txt="Error" /> + <str id="installer.reversetitle" txt="$APP_NAME installation" /> +</langpack> \ No newline at end of file diff --git a/screening/dist/installer/install.xml b/screening/dist/installer/install.xml new file mode 100644 index 0000000000000000000000000000000000000000..dc27ed89bc962a519454df8914b12d81865ddb82 --- /dev/null +++ b/screening/dist/installer/install.xml @@ -0,0 +1,145 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<installation version="1.0"> + <info> + <appname>openBIS</appname> + <appversion>S106</appversion> + <url>http://www.cisd.ethz.ch/software/openBIS</url> + </info> + + <!-- Sets the installer window size. --> + <guiprefs width="640" height="480" resizable="yes"> + <modifier key="useHeadingPanel" value="yes"/> + <modifier key="headingImageOnLeft" value="yes"/> + <modifier key="headingBackgroundColor" value="0xffffff"/> + </guiprefs> + + <locale> + <langpack iso3="eng" /> + </locale> + + <javaversion>1.6</javaversion> + <requiresjdk>yes</requiresjdk> + <os> + <family>unix, mac</family> + </os> + + <!-- The resources section. The ids must be these ones if you want to use the LicencePanel and/or the InfoPanel. --> + <resources> + <!-- res id="LicencePanel.licence" src="Licence.txt"/ --> + <res id="TargetPanel.dir" src="@{installer.resourcedir}/default-install-dir.txt" /> + <res id="Heading.image" src="@{installer.resourcedir}/openbis_logo_229x100.png"/> + <res id="userInputSpec.xml" src="@{installer.resourcedir}/userInputSpec.xml" /> + <res id="ProcessPanel.Spec.xml" src="@{installer.resourcedir}/backup-installation.xml"/> + </resources> + + <variables> + <!-- suppress the "target directory will be created" message --> + <variable name="ShowCreateDirectoryMessage" value="no" /> + <variable name="data.validation.error.title" value="Error" /> + <variable name="installer.reversetitle" value="$APP_NAME installation" /> + </variables> + + <dynamicvariables> + <variable name="INSTALL_BIN_PATH" value="$INSTALL_PATH/bin" /> + <variable name="INSTALL_OPENBIS_PATH" value="$INSTALL_PATH/servers/openBIS-server" /> + <variable name="INSTALL_DSS_PATH" value="$INSTALL_PATH/servers/datastore_server" /> + </dynamicvariables> + + <conditions> + <condition type="java" id="isUpdateInstallation"> + <java> + <class>ch.systemsx.cisd.openbis.installer.izpack.InstallationContext</class> + <field>isUpdateInstallation</field> + </java> + <returnvalue type="boolean">true</returnvalue> + </condition> + <condition type="java" id="isFirstTimeInstallation"> + <java> + <class>ch.systemsx.cisd.openbis.installer.izpack.InstallationContext</class> + <field>isFirstTimeInstallation</field> + </java> + <returnvalue type="boolean">true</returnvalue> + </condition> + </conditions> + + <!-- The panels section. We indicate here which panels we want to use. The order will be respected. --> + <panels> + <panel classname="HelloPanel" /> + <!-- panel classname="LicencePanel"/ --> + + <panel classname="TargetPanel"> + <actions> + <action stage="postvalidate" classname="ch.systemsx.cisd.openbis.installer.izpack.InitializeInstallationContextAction" /> + </actions> + </panel> + + <panel classname="UserInputPanel" id="UserInputPanel.0" condition="isFirstTimeInstallation"> + <validator classname="ch.systemsx.cisd.openbis.installer.izpack.DBConnectionValidator"/> + </panel> + <panel classname="UserInputPanel" id="UserInputPanel.1" condition="isFirstTimeInstallation"/> + + <!-- create backup if needed --> + <panel classname="ProcessPanel" condition="isUpdateInstallation" > + <actions> + <action stage="preactivate" classname="ch.systemsx.cisd.openbis.installer.izpack.PrepareInstallationBackupAction" /> + </actions> + </panel> + + <panel classname="PacksPanel"/> + <panel classname="InstallPanel" /> + <panel classname="FinishPanel" /> + </panels> + + + <!-- The packs (packages) to be installed. --> + <packs> + <pack name="openBIS Server" required="yes" loose="yes"> + <description>The openBIS application server</description> + <file src="openBIS-server-screening-SNAPSHOT-r21061.zip" targetdir="$INSTALL_PATH/servers" unpack="true" /> + <parsable targetfile="$INSTALL_OPENBIS_PATH/service.properties" /> + <!-- run post installation script for the openBIS server --> + <executable targetfile="$INSTALL_OPENBIS_PATH/install.sh" stage="postinstall"> + <args> + <arg value="$INSTALL_OPENBIS_PATH" /> + <arg value="$INSTALL_OPENBIS_PATH/service.properties" /> + </args> + </executable> + </pack> + + <pack name="Datastore Server" required="yes" loose="yes"> + <description>The data store server managing raw data</description> + <file src="datastore_server-screening-SNAPSHOT-r21061.zip" targetdir="$INSTALL_PATH/servers" unpack="true" /> + <parsable targetfile="$INSTALL_DSS_PATH/etc/service.properties" /> + </pack> + + <pack name="Administration Scripts" required="yes" loose="yes"> + <description>Scripts to facilitate openBIS administration</description> + <file src="../ant/classes/bin" targetdir="$INSTALL_PATH" /> + + <!-- set all *.sh files executable --> + <executable targetfile="/usr/bin/find" stage="postinstall" keep="true"> + <args> + <arg value="$INSTALL_PATH" /> + <arg value="-type" /> + <arg value="f" /> + <arg value="-name" /> + <arg value="*.sh" /> + <arg value="-exec" /> + <arg value="/bin/chmod" /> + <arg value="744"/> + <arg value="{}" /> + <arg value=";" /> + </args> + </executable> + + <!-- restore the config from the pre-existing installation --> + <executable targetfile="$INSTALL_BIN_PATH/restore-config-from-backup.sh" + stage="postinstall" condition="isUpdateInstallation" keep="true"> + <args> + <arg value="$BACKUP_FOLDER" /> + </args> + </executable> + </pack> + </packs> + +</installation> diff --git a/screening/dist/installer/openBIS_logo_229x100.png b/screening/dist/installer/openBIS_logo_229x100.png new file mode 100644 index 0000000000000000000000000000000000000000..369e8c93debc3cca0bdcf214702dd7798c01d043 Binary files /dev/null and b/screening/dist/installer/openBIS_logo_229x100.png differ diff --git a/screening/dist/installer/userInputSpec.xml b/screening/dist/installer/userInputSpec.xml new file mode 100644 index 0000000000000000000000000000000000000000..333ae0628c7229c45ad7db19ff6b8b87ddfea953 --- /dev/null +++ b/screening/dist/installer/userInputSpec.xml @@ -0,0 +1,41 @@ +<userInput> + <panel order="0"> + <createForPack name="openBIS Server" /> + + <field type="title" txt="Configure openBIS PostgreSQL DB" bold="true" size="2" /> + + <field type="text" variable="DB.HOST"> + <spec txt="Hostname" size="20" set="localhost" /> + </field> + + <field type="text" variable="DB.PORT"> + <spec txt="Port" size="20" set="5432" /> + </field> + + <field type="text" variable="DB.USERNAME"> + <spec txt="Username" size="20" set="$USER_NAME"/> + </field> + + <field type="password" variable="DB.PASSWORD"> + <spec> + <pwd txt="Password" size="20" set=""/> + </spec> + </field> + + <field type="text" variable="DB.KIND"> + <spec txt="DB Name Suffix" size="20" set="screening" /> + </field> + <field type="staticText" align="left" txt=" e.g. 'demo' will result in connecting to 'openbis_demo'" /> + + </panel> + + <panel order="1"> + <createForPack name="Datastore Server" /> + <field type="title" txt="DataStore Server Configuration" bold="true" size="2" /> + <field type="dir" align="left" variable="DSS.ROOT-DIR"> + <spec txt="Data folder" size="30" set="$INSTALL_PATH/data" mustExist="false" create="true" /> + </field> + <field type="staticText" align="left" txt="This directory will be used to store raw data." /> + </panel> + +</userInput> \ No newline at end of file diff --git a/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java new file mode 100644 index 0000000000000000000000000000000000000000..0cea55e2be5df8ebbfb1d8496b349cf32a14b5d2 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java @@ -0,0 +1,95 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.installer.izpack; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import com.izforge.izpack.installer.AutomatedInstallData; +import com.izforge.izpack.installer.DataValidator; + +/** + * @author Kaloyan Enimanev + */ +public class DBConnectionValidator implements DataValidator +{ + + private static final String DEFAULT_ERROR_MESSAGE = "Cannot connect to the specified database."; + + private String errorMessage; + + public boolean getDefaultAnswer() + { + return true; + } + + public String getErrorMessageId() + { + if (errorMessage != null) + { + return errorMessage; + } else + { + return DEFAULT_ERROR_MESSAGE; + } + } + + public String getWarningMessageId() + { + return getErrorMessageId(); + } + + public Status validateData(AutomatedInstallData data) + { + String hostname = data.getVariable("DB.HOST"); + String port = data.getVariable("DB.PORT"); + String username = data.getVariable("DB.USERNAME"); + String password = data.getVariable("DB.PASSWORD"); + String dbname = "openbis_" + data.getVariable("DB.KIND"); + + String connectionString = "jdbc:postgresql://" + hostname + ":" + port + "/" + dbname; + + boolean ok = testConnectionOK(connectionString, username, password); + return ok ? Status.OK : Status.ERROR; + } + + private boolean testConnectionOK(String connectionString, + String username, String password) + { + boolean connected = false; + try + { + Class.forName("org.postgresql.Driver"); + Connection connection = + DriverManager.getConnection(connectionString, username, password); + if (connection != null) + { + connected = true; + connection.close(); + } + } catch (ClassNotFoundException cnfe) + { + errorMessage = cnfe.getMessage(); + } catch (SQLException e) + { + errorMessage = e.getMessage(); + } + + return connected; + } +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/InitializeInstallationContextAction.java b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/InitializeInstallationContextAction.java new file mode 100644 index 0000000000000000000000000000000000000000..00cba79e816643e5c21f91a40443bc1a0ebd98fa --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/InitializeInstallationContextAction.java @@ -0,0 +1,41 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.installer.izpack; + +import com.izforge.izpack.installer.AutomatedInstallData; +import com.izforge.izpack.installer.PanelAction; +import com.izforge.izpack.installer.PanelActionConfiguration; +import com.izforge.izpack.util.AbstractUIHandler; + +/** + * + * + * @author kaloyane + */ +public class InitializeInstallationContextAction implements PanelAction +{ + + public void executeAction(AutomatedInstallData data, AbstractUIHandler arg1) + { + InstallationContext.initialize(data); + } + + public void initialize(PanelActionConfiguration arg0) + { + } + +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/InstallationContext.java b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/InstallationContext.java new file mode 100644 index 0000000000000000000000000000000000000000..1c929d9ab74478e0ee7845588081efdaf2138f99 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/InstallationContext.java @@ -0,0 +1,49 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.installer.izpack; + +import java.io.File; + +import com.izforge.izpack.installer.AutomatedInstallData; + +/** + * @author Kaloyan Enimanev + */ +public class InstallationContext +{ + /** + * set to true if the installation process is trying to update an existing openBIS installation. + */ + public static boolean isUpdateInstallation = false; + + /** + * set to true if this is the first openBIS installation on the machine. + */ + public static boolean isFirstTimeInstallation = true; + + public static File installDir; + + public static void initialize(AutomatedInstallData data) + { + String installPath = data.getInstallPath(); + System.out.println("Initializing -- " + installPath); + installDir = new File(installPath); + isFirstTimeInstallation = (installDir.exists() == false); + isUpdateInstallation = installDir.exists(); + } + +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/PrepareInstallationBackupAction.java b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/PrepareInstallationBackupAction.java new file mode 100644 index 0000000000000000000000000000000000000000..4983d77890c7a095217d90f73c166e221a2895fc --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/installer/izpack/PrepareInstallationBackupAction.java @@ -0,0 +1,90 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.installer.izpack; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.izforge.izpack.installer.AutomatedInstallData; +import com.izforge.izpack.installer.PanelAction; +import com.izforge.izpack.installer.PanelActionConfiguration; +import com.izforge.izpack.util.AbstractUIHandler; + +/** + * @author Kaloyan Enimanev + */ +public class PrepareInstallationBackupAction implements PanelAction +{ + + private static final String BACKUP_FOLDER_VARNAME = "BACKUP_FOLDER"; + + private static final String BACK_FOLDER_PATTERN = "yyyy-MM-dd-HHmm"; + + private static final String BACKUP_ROOT = "backup"; + + private File installDir; + private File backupDir; + + public synchronized void executeAction(AutomatedInstallData data, AbstractUIHandler arg1) + { + if (InstallationContext.isUpdateInstallation) + { + installDir = InstallationContext.installDir; + backupDir = generateUniqueBackupDirName(); + + setInstallationWideBackupDirVariable(data); + } + } + + public void initialize(PanelActionConfiguration arg0) + { + } + + /** + * sets a global variable in the installation context that will be visible by other + * panels/executables (or any kind of collaborators) in the installation process. + */ + private String setInstallationWideBackupDirVariable(AutomatedInstallData data) + { + String backupDirPath = backupDir.getAbsolutePath(); + System.out.println("Setting backup folder to " + backupDirPath + " ..."); + data.setVariable(BACKUP_FOLDER_VARNAME, backupDirPath); + return backupDirPath; + } + + /** + * generates an unique backup folder name. The returned value is a non-existing directory. + */ + private File generateUniqueBackupDirName() + { + File backupRootDir = new File(installDir, BACKUP_ROOT); + Date now = new Date(); + String backupDirName = new SimpleDateFormat(BACK_FOLDER_PATTERN).format(now); + File result = new File(backupRootDir, backupDirName); + + // check if previous backup exists + int uniqueSuffix = 1; + while (result.exists()) + { + result = new File(backupRootDir, backupDirName + "-" + uniqueSuffix); + uniqueSuffix++; + } + return result; + } + +}