diff --git a/deploy.sh b/deploy.sh index f785ceb..4157dec 100755 --- a/deploy.sh +++ b/deploy.sh @@ -22,16 +22,27 @@ echo "Building jrunner..." ./gradlew build echo "Deploying to ${DEPLOY_DIR}..." + +# Remove both target and intermediate jrunner directory if they exist if [ -d "${DEPLOY_DIR}" ]; then - echo "Removing existing deployment..." + echo "Removing existing deployment at ${DEPLOY_DIR}..." sudo rm -rf "${DEPLOY_DIR}" fi -sudo mkdir -p "$(dirname "${DEPLOY_DIR}")" -sudo unzip -q jrunner/build/distributions/jrunner.zip -d "$(dirname "${DEPLOY_DIR}")" -# Rename if custom directory name was specified +PARENT_DIR="$(dirname "${DEPLOY_DIR}")" +EXTRACT_DIR="${PARENT_DIR}/jrunner" + +if [ -d "${EXTRACT_DIR}" ] && [ "${EXTRACT_DIR}" != "${DEPLOY_DIR}" ]; then + echo "Removing existing jrunner directory at ${EXTRACT_DIR}..." + sudo rm -rf "${EXTRACT_DIR}" +fi + +# Extract and rename if needed +sudo mkdir -p "${PARENT_DIR}" +sudo unzip -q jrunner/build/distributions/jrunner.zip -d "${PARENT_DIR}" + if [ "$(basename "${DEPLOY_DIR}")" != "jrunner" ]; then - sudo mv "$(dirname "${DEPLOY_DIR}")/jrunner" "${DEPLOY_DIR}" + sudo mv "${EXTRACT_DIR}" "${DEPLOY_DIR}" fi # Only create symlink for default location