postinst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # postinst for smartbotic-automation
  3. set -e
  4. SM_USER="smartbotic-automation"
  5. SM_GROUP="smartbotic-automation"
  6. SM_HOME="/home/smartbotic-automation"
  7. SERVICES="smartbotic-automation-webserver smartbotic-automation-runner"
  8. case "$1" in
  9. configure)
  10. # System group + user (idempotent)
  11. if ! getent group "$SM_GROUP" >/dev/null 2>&1; then
  12. addgroup --system "$SM_GROUP"
  13. fi
  14. if ! getent passwd "$SM_USER" >/dev/null 2>&1; then
  15. adduser --system --ingroup "$SM_GROUP" --home "$SM_HOME" \
  16. --shell /usr/sbin/nologin \
  17. --gecos "SmartBotic Automation Service User" "$SM_USER"
  18. fi
  19. install -d -o "$SM_USER" -g "$SM_GROUP" -m 0750 "$SM_HOME"
  20. install -d -o "$SM_USER" -g "$SM_GROUP" -m 0750 /var/lib/smartbotic-automation
  21. install -d -o "$SM_USER" -g "$SM_GROUP" -m 0750 /var/log/smartbotic-automation
  22. install -d -o root -g "$SM_GROUP" -m 0750 /etc/smartbotic-automation
  23. # systemd
  24. if [ -d /run/systemd/system ]; then
  25. systemctl daemon-reload
  26. fi
  27. if [ -z "$2" ]; then
  28. # First install: enable but do NOT start (admin must configure
  29. # database_address first; the upstream DB port is deployment-specific).
  30. for svc in $SERVICES; do
  31. deb-systemd-helper enable "$svc.service" >/dev/null || true
  32. done
  33. echo
  34. echo "smartbotic-automation: services are enabled but not started."
  35. echo " WARNING: webserver.json contains placeholder values for jwt_secret and"
  36. echo " credentials.master_key. Replace 'CHANGE_ME_BEFORE_PRODUCTION'"
  37. echo " with strong unique secrets before starting the service in production."
  38. echo
  39. echo " Configuration steps:"
  40. echo " 1. Edit /etc/smartbotic-automation/webserver.json (set database_address, jwt_secret, credentials.master_key)"
  41. echo " 2. Edit /etc/smartbotic-automation/runner.json (set database_address)"
  42. echo " 3. systemctl start smartbotic-automation-webserver smartbotic-automation-runner"
  43. echo
  44. else
  45. # Upgrade path: try-restart any active units
  46. for svc in $SERVICES; do
  47. deb-systemd-invoke try-restart "$svc.service" >/dev/null 2>&1 || true
  48. done
  49. fi
  50. ;;
  51. esac
  52. exit 0