jrunner/deploy.sh
Paul Trowbridge 7db2abdf18 Create ~/.jrqrc config template on deploy
deploy.sh now generates a commented ~/.jrqrc template on first install
so users know what to fill in. Skips creation if the file already exists
to avoid overwriting existing credentials.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 06:49:41 -05:00

128 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "jrunner deployment script"
echo "========================="
echo ""
echo "Select deployment option:"
echo " 1) Local install (./jrunner/build/install)"
echo " 2) Global install (/opt/jrunner)"
echo " 3) Custom directory"
echo ""
read -p "Enter choice [1-3]: " choice
case $choice in
1)
DEPLOY_MODE="local"
DEPLOY_DIR="./jrunner/build/install/jrunner"
;;
2)
DEPLOY_MODE="global"
DEPLOY_DIR="/opt/jrunner"
;;
3)
DEPLOY_MODE="custom"
read -e -p "Enter deployment directory (required): " DEPLOY_DIR
if [ -z "$DEPLOY_DIR" ]; then
echo "Error: Directory path is required"
exit 1
fi
# Expand tilde to home directory
DEPLOY_DIR="${DEPLOY_DIR/#\~/$HOME}"
;;
*)
echo "Error: Invalid choice"
exit 1
;;
esac
# Prevent deleting critical system directories
case "${DEPLOY_DIR}" in
/|/bin|/boot|/dev|/etc|/lib|/lib64|/proc|/root|/run|/sbin|/sys|/usr|/var)
echo "Error: Cannot deploy to system directory: ${DEPLOY_DIR}"
exit 1
;;
esac
echo ""
echo "Building jrunner..."
./gradlew build
if [ "$DEPLOY_MODE" = "local" ]; then
echo "Installing locally with gradle..."
./gradlew installDist
echo "Installing jrq wrapper script..."
cp jrq "${DEPLOY_DIR}/bin/jrq"
chmod +x "${DEPLOY_DIR}/bin/jrq"
echo ""
echo "✅ Installed locally at: ${DEPLOY_DIR}"
echo "Run './jrunner/build/install/jrunner/bin/jrunner --help' to test"
echo "Run './jrunner/build/install/jrunner/bin/jrq' for query wrapper usage"
else
# Global or custom deployment
if [ ! -d "${DEPLOY_DIR}" ]; then
echo "Creating directory: ${DEPLOY_DIR}"
sudo mkdir -p "${DEPLOY_DIR}"
fi
echo "Extracting to temporary location..."
sudo rm -rf /tmp/jrunner-deploy
sudo unzip -q jrunner/build/distributions/jrunner.zip -d /tmp/jrunner-deploy
echo "Deploying to ${DEPLOY_DIR}..."
sudo rm -rf "${DEPLOY_DIR}"/*
sudo mv /tmp/jrunner-deploy/jrunner/* "${DEPLOY_DIR}"/
sudo rm -rf /tmp/jrunner-deploy
echo "Fixing ownership..."
sudo chown -R $USER:$USER "${DEPLOY_DIR}"
# Copy jrq wrapper script
echo "Installing jrq wrapper script..."
sudo cp jrq "${DEPLOY_DIR}/bin/jrq"
sudo chmod +x "${DEPLOY_DIR}/bin/jrq"
# Create symlink for global install
if [ "$DEPLOY_MODE" = "global" ]; then
echo "Creating symlinks at /usr/local/bin/..."
sudo ln -sf /opt/jrunner/bin/jrunner /usr/local/bin/jrunner
sudo ln -sf /opt/jrunner/bin/jrq /usr/local/bin/jrq
fi
echo ""
echo "✅ Deployed to ${DEPLOY_DIR}"
echo "Run '${DEPLOY_DIR}/bin/jrunner --help' to test"
echo "Run '${DEPLOY_DIR}/bin/jrq' for query wrapper usage"
if [ "$DEPLOY_MODE" = "global" ]; then
echo "Or simply: jrunner --help"
echo " jrq (for query wrapper)"
fi
fi
# Create ~/.jrqrc template if it doesn't exist
if [ ! -f "${HOME}/.jrqrc" ]; then
echo "Creating ~/.jrqrc config template..."
cat > "${HOME}/.jrqrc" <<'EOF'
# jrq configuration
# Uncomment and fill in the values below
# JDBC connection URL (required)
# Examples:
# AS/400: jdbc:as400://hostname
# PostgreSQL: jdbc:postgresql://hostname:5432/dbname
# SQL Server: jdbc:sqlserver://hostname:1433;databaseName=mydb
#JR_URL=""
# Database credentials (required)
#JR_USER=""
#JR_PASS=""
# Output format: csv or tsv (default: csv)
#JR_FORMAT="csv"
EOF
echo "Edit ~/.jrqrc to add your connection details before using jrq"
else
echo "~/.jrqrc already exists, skipping template creation"
fi