qubes.RegisterBackupLocation 918 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. # Register backup location (path or a command) to be retrieved with qubes
  3. # .RestoreById service.
  4. # Registered location is only valid as long as this service call stays open
  5. set -e
  6. REGISTRY_DIR="$XDG_RUNTIME_DIR/qubes-backup-location"
  7. if ! [ -d "$REGISTRY_DIR" ]; then
  8. mkdir -p "$REGISTRY_DIR"
  9. fi
  10. read -r backup_location
  11. REGISTRY_FILE=$(mktemp "$REGISTRY_DIR/XXXXXXXX")
  12. PID=$$
  13. # this isn't perfetct, as comm field could contain spaces, but we do control
  14. # this value and we know it doesn't
  15. START_TIME=$(cut -f 22 -d ' ' /proc/$PID/stat)
  16. # add process id at the beginning to help verifying if it's still running;
  17. # record starttime too, to detect PID reuse
  18. printf "%d %d\n%s\n" "$PID" "$START_TIME" "$backup_location" >"$REGISTRY_FILE"
  19. # output registered ID to the user
  20. basename "$REGISTRY_FILE"
  21. # close stdout
  22. exec >&-
  23. # wait for stdin to close
  24. cat >/dev/null
  25. # and cleanup
  26. rm -f "$REGISTRY_FILE"