# usage: setpin.sh fp | setpin.sh ca — writes the agent's proxmox.tls block, restarts the agent main() { mode=$1; t0=$(date +%s.%N); echo "== setpin $mode start $(date -u +%FT%TZ)" FP=$(echo | openssl s_client -connect 127.0.0.1:8006 2>/dev/null | openssl x509 -noout -fingerprint -sha256 | cut -d= -f2) MODE=$mode FP=$FP python3 - <<'PY' import json,os f='/etc/felhom-agent/agent.json'; c=json.load(open(f)); st=os.stat(f) if os.environ['MODE']=='fp': c['proxmox']['tls']={'fingerprint':os.environ['FP'],'insecure_skip_verify':False} else: c['proxmox']['tls']={'ca_file':'/etc/ssl/certs/ISRG_Root_X1.pem','fingerprint':'','insecure_skip_verify':False} tmp=f+'.tmp'; fd=os.open(tmp,os.O_WRONLY|os.O_CREAT|os.O_TRUNC,0o600) with os.fdopen(fd,'w') as o: json.dump(c,o,indent=2); o.write('\n') os.chown(tmp,st.st_uid,st.st_gid); os.rename(tmp,f); print('written tls:',c['proxmox']['tls']) PY systemctl restart felhom-agent n=0; mark=$(date '+%d/%m/%Y:%H:%M:%S'); until [ $n -ge 60 ]; do l=$(grep 'felhom-agent@pve' /var/log/pveproxy/access.log | tail -1); ts=$(echo "$l" | awk '{print $4}' | tr -d '['); if [ "$(date -d "$(echo $ts | sed 's#\([0-9]*\)/\([0-9]*\)/\([0-9]*\):#\3-\2-\1 #')" +%s 2>/dev/null || echo 0)" -ge "${t0%.*}" ]; then echo "first agent call after restart: $(echo "$l" | awk '{print $4,$6,$7,$9}')"; break; fi; n=$((n+1)); sleep 1; done t1=$(date +%s.%N); echo "seconds from start to a working call: $(echo "$t1 - $t0" | bc) (loops: $n; 60 = no call seen)" echo "agent: $(systemctl is-active felhom-agent)" }; main "$@"