#!/bin/sh
# DeltaWalker script to cleanup old files before installation for Linux

# Any subsequent commands which fail will cause the shell script to exit immediately
set -e

_APP_DATA_DIR="${HOME}/.deltawalker"

echo "-> Start"

if [ -d "${_APP_DATA_DIR}" ]
then
    # Delete all files in _APP_DATA_DIR except:
    #   state.dws           - state file
    #   dw_log.properties   - configuration for logging
    #   dw.log.*            - all log files
    #   ! -name 'config.ini' and ! -name 'DeltaWalker.ini'  are not there for now
    echo "-> Delete files from DeltaWalker data directory ${_APP_DATA_DIR}"
    cd "${_APP_DATA_DIR}"
    find . ! -name '.' ! -name 'state.dws' ! -name 'dw_log.properties' ! -name 'dw.log.*' -delete
    echo "<- Deleted files from DeltaWalker data directory ${_APP_DATA_DIR}"
else
    echo "DeltaWalker data directory does not exist: ${_APP_DATA_DIR}. No delete."
fi

echo "<- Finish"

