diff --git a/cert-manager.py b/cert-manager.py index cf9bf21..d51978c 100755 --- a/cert-manager.py +++ b/cert-manager.py @@ -101,14 +101,33 @@ def yes_no_prompt(prompt, default=True): def detect_system_type(target_host, script_dir): """Detect the type of system on the target host""" 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( - [str(script_dir / 'detect-system.sh'), target_host], + [str(detect_script), target_host], capture_output=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() + if not system_type: + print("Warning: Detection script returned empty output") + return '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: print(f"Warning: Could not detect system type: {e}") return 'unknown' diff --git a/detect-system.sh b/detect-system.sh index d245d90..d4c6101 100755 --- a/detect-system.sh +++ b/detect-system.sh @@ -5,19 +5,27 @@ TARGET_HOST="$1" if [ -z "$TARGET_HOST" ]; then - echo "Usage: $0 " + echo "Usage: $0 " >&2 exit 1 fi +# SSH options for faster connection +SSH_OPTS="-o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no" + # 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" -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" -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" -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" + exit 0 else echo "unknown" + exit 0 fi