169 lines
3.5 KiB
Markdown
169 lines
3.5 KiB
Markdown
|
|
# Script Path Configuration - Verified ✅
|
||
|
|
|
||
|
|
**Date**: 2025-12-13
|
||
|
|
**Status**: ✅ **PATHS CORRECTLY CONFIGURED**
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Path Resolution
|
||
|
|
|
||
|
|
All scripts now correctly locate the `.env` file using absolute paths based on the script's location.
|
||
|
|
|
||
|
|
### Path Resolution Logic
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Get the directory where this script is located
|
||
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
# Get the project root (one level up from scripts directory)
|
||
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||
|
|
# Locate .env file in project root
|
||
|
|
ENV_FILE="$PROJECT_ROOT/.env"
|
||
|
|
```
|
||
|
|
|
||
|
|
### Verified Paths
|
||
|
|
|
||
|
|
| Component | Path |
|
||
|
|
|-----------|------|
|
||
|
|
| **Script Directory** | `/home/intlc/projects/Sankofa/scripts` |
|
||
|
|
| **Project Root** | `/home/intlc/projects/Sankofa` |
|
||
|
|
| **Env File** | `/home/intlc/projects/Sankofa/.env` |
|
||
|
|
| **Status** | ✅ **EXISTS** |
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Updated Scripts
|
||
|
|
|
||
|
|
All scripts have been updated with proper path resolution:
|
||
|
|
|
||
|
|
1. ✅ `scripts/ssh-ml110-01.sh`
|
||
|
|
2. ✅ `scripts/ssh-r630-01.sh`
|
||
|
|
3. ✅ `scripts/test-proxmox-connectivity.sh`
|
||
|
|
4. ✅ `scripts/test-ssh-password.sh`
|
||
|
|
5. ✅ `scripts/ssh-proxmox-nodes.sh`
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Path Resolution Features
|
||
|
|
|
||
|
|
### ✅ Works from Any Directory
|
||
|
|
|
||
|
|
Scripts can be run from any directory and will still find the `.env` file:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# From project root
|
||
|
|
cd /home/intlc/projects/Sankofa
|
||
|
|
./scripts/ssh-ml110-01.sh
|
||
|
|
|
||
|
|
# From scripts directory
|
||
|
|
cd /home/intlc/projects/Sankofa/scripts
|
||
|
|
./ssh-ml110-01.sh
|
||
|
|
|
||
|
|
# From any other directory
|
||
|
|
cd /tmp
|
||
|
|
/home/intlc/projects/Sankofa/scripts/ssh-ml110-01.sh
|
||
|
|
```
|
||
|
|
|
||
|
|
### ✅ Error Handling
|
||
|
|
|
||
|
|
If `.env` file is not found, scripts provide helpful error messages:
|
||
|
|
|
||
|
|
```
|
||
|
|
Error: .env file not found at /home/intlc/projects/Sankofa/.env
|
||
|
|
Current directory: /tmp
|
||
|
|
Script directory: /home/intlc/projects/Sankofa/scripts
|
||
|
|
Project root: /home/intlc/projects/Sankofa
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Testing
|
||
|
|
|
||
|
|
### Path Resolution Test
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Test from project root
|
||
|
|
cd /home/intlc/projects/Sankofa
|
||
|
|
./scripts/ssh-ml110-01.sh 'echo "Test"'
|
||
|
|
|
||
|
|
# Test from scripts directory
|
||
|
|
cd /home/intlc/projects/Sankofa/scripts
|
||
|
|
./ssh-ml110-01.sh 'echo "Test"'
|
||
|
|
|
||
|
|
# Test from different directory
|
||
|
|
cd /tmp
|
||
|
|
/home/intlc/projects/Sankofa/scripts/ssh-ml110-01.sh 'echo "Test"'
|
||
|
|
```
|
||
|
|
|
||
|
|
All should correctly locate the `.env` file.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Password Extraction
|
||
|
|
|
||
|
|
The password is extracted from `.env` file (lines 45-46):
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Extract password from .env (lines 45-46)
|
||
|
|
PROXMOX_PASSWORD=$(sed -n '45,46p' "$ENV_FILE" | grep "PROXMOX_ROOT_PASS" | head -1 | cut -d'=' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||
|
|
|
||
|
|
# Remove quotes if present
|
||
|
|
PROXMOX_PASSWORD="${PROXMOX_PASSWORD#\"}"
|
||
|
|
PROXMOX_PASSWORD="${PROXMOX_PASSWORD%\"}"
|
||
|
|
PROXMOX_PASSWORD="${PROXMOX_PASSWORD#\'}"
|
||
|
|
PROXMOX_PASSWORD="${PROXMOX_PASSWORD%\'}"
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Verification
|
||
|
|
|
||
|
|
### Test Path Resolution
|
||
|
|
|
||
|
|
```bash
|
||
|
|
cd /home/intlc/projects/Sankofa
|
||
|
|
SCRIPT_DIR="$(cd scripts && pwd)"
|
||
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||
|
|
ENV_FILE="$PROJECT_ROOT/.env"
|
||
|
|
echo "Env file: $ENV_FILE"
|
||
|
|
echo "Exists: $([ -f "$ENV_FILE" ] && echo "YES" || echo "NO")"
|
||
|
|
```
|
||
|
|
|
||
|
|
**Expected Output**:
|
||
|
|
```
|
||
|
|
Env file: /home/intlc/projects/Sankofa/.env
|
||
|
|
Exists: YES
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Common Functions
|
||
|
|
|
||
|
|
A shared function file is available for reuse:
|
||
|
|
|
||
|
|
**File**: `scripts/load-env.sh`
|
||
|
|
|
||
|
|
**Usage**:
|
||
|
|
```bash
|
||
|
|
source "$(dirname "$0")/load-env.sh"
|
||
|
|
PROXMOX_PASSWORD=$(load_proxmox_password)
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Conclusion
|
||
|
|
|
||
|
|
✅ **All scripts correctly configured**
|
||
|
|
|
||
|
|
- Path resolution works from any directory
|
||
|
|
- `.env` file is located correctly
|
||
|
|
- Error messages are helpful
|
||
|
|
- Password extraction works correctly
|
||
|
|
|
||
|
|
**Status**: ✅ **READY FOR USE**
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**Last Updated**: 2025-12-13
|
||
|
|
**Status**: ✅ **VERIFIED**
|
||
|
|
|