Fix: never overwrite existing hwmonDaemon .env on re-runs

If /etc/hwmonDaemon/.env already exists and has a real API key,
skip the prompt and preserve the file entirely. Only write a new
.env when none exists or it still has the placeholder value.
Safe to run freshStart.sh on existing hosts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 14:32:16 -04:00
parent eeea0ebdfa
commit d5121c56f3
+9 -1
View File
@@ -311,11 +311,17 @@ echo "━━━━━━━━━━━━━━━━━━━━━━━━
echo " hwmonDaemon API Key Configuration" echo " hwmonDaemon API Key Configuration"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "" echo ""
API_KEY=""
if [[ -f /etc/hwmonDaemon/.env ]] && ! grep -q "your_api_key_here" /etc/hwmonDaemon/.env; then
echo "✓ Existing /etc/hwmonDaemon/.env detected — skipping (will not overwrite)"
else
echo "The hwmonDaemon requires an API key to create tickets." echo "The hwmonDaemon requires an API key to create tickets."
echo "You can enter it now or configure it later by editing:" echo "You can enter it now or configure it later by editing:"
echo " /etc/hwmonDaemon/.env" echo " /etc/hwmonDaemon/.env"
echo "" echo ""
read -p "Enter API key (or press Enter to skip): " API_KEY read -p "Enter API key (or press Enter to skip): " API_KEY
fi
# Determine platform-specific defaults # Determine platform-specific defaults
if [[ "$PLATFORM" == "pbs" ]]; then if [[ "$PLATFORM" == "pbs" ]]; then
@@ -326,7 +332,9 @@ else
CEPH_DEFAULT="true" CEPH_DEFAULT="true"
fi fi
if [[ -n "$API_KEY" ]]; then if [[ -f /etc/hwmonDaemon/.env ]] && ! grep -q "your_api_key_here" /etc/hwmonDaemon/.env; then
: # already guarded above — existing .env preserved
elif [[ -n "$API_KEY" ]]; then
# Create .env file with API key and all config options # Create .env file with API key and all config options
cat > /etc/hwmonDaemon/.env << EOF cat > /etc/hwmonDaemon/.env << EOF
# hwmonDaemon Configuration # hwmonDaemon Configuration