Skip to content

Latest commit

 

History

History
203 lines (140 loc) · 4.49 KB

File metadata and controls

203 lines (140 loc) · 4.49 KB

Using Scripts on macOS

This guide explains how to use the bash scripts (.sh files) on macOS.

Prerequisites

  1. Bash: macOS includes bash by default (though newer versions use zsh as default shell, bash is still available)

    which bash
    # Should show: /bin/bash or /usr/local/bin/bash
  2. SSH Client: macOS includes SSH by default

    which ssh
  3. rsync: macOS includes rsync by default

    which rsync
  4. Docker Desktop: Install Docker Desktop for Mac if you need to test locally

Setup

1. Navigate to Your Project

cd /path/to/vulnerability-scanner

2. Configure VM Access

Create your VM configuration file:

cp config/.vm-config.example config/.vm-config
# Edit config/.vm-config with your VM details
nano config/.vm-config  # or use your preferred editor (vim, code, etc.)

3. Make Scripts Executable

chmod +x scripts/*.sh

This should work fine on macOS since it's a native Unix filesystem.

Usage

All scripts are in the scripts/ directory. Run them from the project root:

Common Commands

# Sync code to VM
./scripts/sync-to-vm.sh
# OR
bash scripts/sync-to-vm.sh

# Full deployment
./scripts/deploy-to-vm.sh

# Check VM status
./scripts/check-vm-status.sh

# View logs
./scripts/view-vm-logs.sh
./scripts/view-vm-logs.sh backend  # specific service

# Restart services
./scripts/restart-vm-services.sh
./scripts/restart-vm-services.sh backend  # specific service

# Execute commands in containers
./scripts/vm-exec.sh backend rails console
./scripts/vm-exec.sh backend rails db:migrate

# Build Docker images
./scripts/build-vm-images.sh

# Start services
./scripts/start-vm-services.sh

Path Considerations

SSH Key Paths

If you're using SSH keys, reference them with macOS paths:

# In config/.vm-config
SSH_KEY_PATH=/Users/yourusername/.ssh/id_ed25519
# or
SSH_KEY_PATH=~/.ssh/id_ed25519

Home Directory

macOS home directories are at /Users/username/, so use:

SSH_KEY_PATH=/Users/YourUsername/.ssh/id_rsa

Troubleshooting

Permission Denied

If you get "Permission denied" errors:

chmod +x scripts/*.sh

Line Ending Issues

If you see errors like $'\r': command not found, the scripts have Windows line endings. Fix them:

# Option 1: Use the helper script
bash scripts/fix-line-endings.sh

# Option 2: Use dos2unix (install via Homebrew if needed)
brew install dos2unix
dos2unix scripts/*.sh
dos2unix config/.vm-config*

# Option 3: Use sed
sed -i '' 's/\r$//' scripts/*.sh
sed -i '' 's/\r$//' config/.vm-config*

Note: macOS sed requires the -i '' syntax (empty string after -i).

SSH Connection Issues

Test SSH connection first:

ssh user@your-vm-ip

rsync Not Found

rsync should be included with macOS, but if it's missing:

# Install via Homebrew
brew install rsync

Docker/Docker Compose

If you need Docker for local development:

  1. Install Docker Desktop for Mac: https://www.docker.com/products/docker-desktop
  2. Docker Compose is included with Docker Desktop

Tips

  1. Use Terminal.app or iTerm2: Both work great with bash scripts
  2. Stay in Project Root: Always run scripts from the project root directory
  3. Check Paths: Verify your config/.vm-config paths are correct for macOS
  4. Use Tab Completion: macOS bash supports tab completion for easier navigation
  5. Homebrew: Consider installing Homebrew (https://brew.sh) for additional tools if needed

Quick Start

# 1. Navigate to project
cd /path/to/vulnerability-scanner

# 2. Configure VM (if not done)
cp config/.vm-config.example config/.vm-config
nano config/.vm-config

# 3. Make scripts executable
chmod +x scripts/*.sh

# 4. Deploy
./scripts/deploy-to-vm.sh

Differences from WSL

  • Native Unix: macOS is Unix-based, so scripts work natively without WSL
  • File Permissions: chmod works normally (unlike WSL on Windows filesystem)
  • Paths: Use /Users/username/ instead of /home/username/ or /mnt/...
  • No Line Ending Issues: macOS uses LF line endings by default (same as Linux)
  • Terminal: Use Terminal.app, iTerm2, or any Unix terminal

Benefits of Using macOS

  • Native bash environment (no WSL needed)
  • Works seamlessly with Linux tools (rsync, ssh, etc.)
  • Standard Unix filesystem and permissions
  • No execution policy restrictions
  • Consistent with Linux/Unix development workflows