···11#!/bin/sh
22set -e
3344-pcscd -d -a &
55-sleep 2
44+# Debug: Show user and USB device permissions for agent mode only
55+if [ "$1" = "agent" ]; then
66+ echo "Starting pcscd as user: $(id)"
77+ echo "Groups: $(groups)"
88+ echo "USB device permissions:"
99+ if [ -d /dev/bus/usb ]; then
1010+ ls -la /dev/bus/usb/ | head -20
1111+ echo "Checking for specific USB devices..."
1212+ find /dev/bus/usb -type c -exec ls -la {} \; 2>/dev/null | grep -E "20a0|4230" || echo "No HSM devices found by vendor/product ID yet"
1313+ else
1414+ echo "ERROR: /dev/bus/usb not mounted"
1515+ exit 1
1616+ fi
1717+1818+ # Start pcscd with debug output
1919+ echo "Starting pcscd..."
2020+ pcscd -f -d -a &
2121+ PCSCD_PID=$!
2222+2323+ sleep 3
2424+2525+ # Verify pcscd started successfully
2626+ if ! kill -0 $PCSCD_PID 2>/dev/null; then
2727+ echo "ERROR: pcscd failed to start"
2828+ echo "Checking USB access permissions..."
2929+ # Try to access a USB device to see the actual error
3030+ cat /dev/bus/usb/001/001 > /dev/null 2>&1 || echo "Cannot read USB devices: $?"
3131+ exit 1
3232+ fi
3333+3434+ echo "pcscd started successfully with PID $PCSCD_PID"
3535+fi
636737# Entrypoint script for HSM Secrets Operator
838# Supports running manager, discovery, or agent binaries from the same container