jrunner/deploy.sh
Paul Trowbridge c6d34847d5 fix race condition in deploy script rename logic
Previous version failed when /opt/jrunner existed from a prior run,
because mv cannot move over an existing directory. Now the script:

1. Removes target directory if it exists
2. Removes intermediate jrunner/ directory if it exists and differs
   from target (prevents collision)
3. Extracts cleanly
4. Renames to target name

This fixes the issue where ./deploy.sh /opt/jr_test would fail if
/opt/jrunner already existed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-06 22:26:14 -05:00

58 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -e
# Default deployment directory
DEPLOY_DIR="${1:-/opt/jrunner}"
# Safety checks
if [ -z "${DEPLOY_DIR}" ]; then
echo "Error: Deployment directory cannot be empty"
exit 1
fi
# Prevent deleting critical system directories
case "${DEPLOY_DIR}" in
/|/bin|/boot|/dev|/etc|/lib|/lib64|/proc|/root|/run|/sbin|/sys|/usr|/var|/home)
echo "Error: Cannot deploy to system directory: ${DEPLOY_DIR}"
exit 1
;;
esac
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 at ${DEPLOY_DIR}..."
sudo rm -rf "${DEPLOY_DIR}"
fi
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 "${EXTRACT_DIR}" "${DEPLOY_DIR}"
fi
# Only create symlink for default location
if [ "${DEPLOY_DIR}" = "/opt/jrunner" ]; then
echo "Creating symlink..."
sudo ln -sf /opt/jrunner/bin/jrunner /usr/local/bin/jrunner
echo "✅ Deployment complete!"
echo "Run 'jrunner --help' to test"
else
echo "✅ Deployment complete!"
echo "Run '${DEPLOY_DIR}/bin/jrunner --help' to test"
fi