Improve system detection robustness

- Enhanced detect-system.sh with better SSH options
- Added BatchMode and StrictHostKeyChecking=no for automation
- Increased timeout from 5 to 10 seconds
- Explicit exit codes for clarity

- Improved cert-manager.py detection function:
  - Checks if detect script exists before running
  - Validates return code
  - Checks for empty output
  - Better timeout handling (15 seconds)
  - More detailed error messages
  - Handles TimeoutExpired exception separately
This commit is contained in:
root
2025-10-23 08:32:52 +02:00
parent d9e3356e9a
commit 6fb1454310
2 changed files with 34 additions and 7 deletions

View File

@@ -101,14 +101,33 @@ def yes_no_prompt(prompt, default=True):
def detect_system_type(target_host, script_dir): def detect_system_type(target_host, script_dir):
"""Detect the type of system on the target host""" """Detect the type of system on the target host"""
try: try:
detect_script = script_dir / 'detect-system.sh'
if not detect_script.exists():
print(f"Warning: detect-system.sh not found at {detect_script}")
return 'unknown'
result = subprocess.run( result = subprocess.run(
[str(script_dir / 'detect-system.sh'), target_host], [str(detect_script), target_host],
capture_output=True, capture_output=True,
text=True, text=True,
timeout=10 timeout=15
) )
if result.returncode != 0:
print(f"Warning: Detection script returned error code {result.returncode}")
if result.stderr:
print(f"Error output: {result.stderr}")
return 'unknown'
system_type = result.stdout.strip() system_type = result.stdout.strip()
if not system_type:
print("Warning: Detection script returned empty output")
return 'unknown'
return system_type if system_type in SYSTEM_TYPES else 'unknown' return system_type if system_type in SYSTEM_TYPES else 'unknown'
except subprocess.TimeoutExpired:
print(f"Warning: System detection timed out for {target_host}")
return 'unknown'
except Exception as e: except Exception as e:
print(f"Warning: Could not detect system type: {e}") print(f"Warning: Could not detect system type: {e}")
return 'unknown' return 'unknown'

View File

@@ -5,19 +5,27 @@
TARGET_HOST="$1" TARGET_HOST="$1"
if [ -z "$TARGET_HOST" ]; then if [ -z "$TARGET_HOST" ]; then
echo "Usage: $0 <hostname>" echo "Usage: $0 <hostname>" >&2
exit 1 exit 1
fi fi
# SSH options for faster connection
SSH_OPTS="-o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no"
# Try to detect system type # Try to detect system type
if ssh -o ConnectTimeout=5 root@${TARGET_HOST} "test -f /usr/bin/pvesh" 2>/dev/null; then if ssh $SSH_OPTS root@${TARGET_HOST} "test -f /usr/bin/pvesh" 2>/dev/null; then
echo "proxmox" echo "proxmox"
elif ssh -o ConnectTimeout=5 root@${TARGET_HOST} "test -f /usr/local/bin/freenas-version || test -f /usr/local/bin/truenas-version" 2>/dev/null; then exit 0
elif ssh $SSH_OPTS root@${TARGET_HOST} "test -f /usr/local/bin/freenas-version || test -f /usr/local/bin/truenas-version" 2>/dev/null; then
echo "truenas" echo "truenas"
elif ssh -o ConnectTimeout=5 root@${TARGET_HOST} "test -f /usr/local/sbin/pfSsh.php" 2>/dev/null; then exit 0
elif ssh $SSH_OPTS root@${TARGET_HOST} "test -f /usr/local/sbin/pfSsh.php" 2>/dev/null; then
echo "pfsense" echo "pfsense"
elif ssh -o ConnectTimeout=5 root@${TARGET_HOST} "test -f /usr/sbin/univention-config-registry" 2>/dev/null; then exit 0
elif ssh $SSH_OPTS root@${TARGET_HOST} "test -f /usr/sbin/univention-config-registry" 2>/dev/null; then
echo "ucs" echo "ucs"
exit 0
else else
echo "unknown" echo "unknown"
exit 0
fi fi