qubes.Restore 932 B

123456789101112131415161718192021222324252627282930313233
  1. echo Starting Restorecopy >&2
  2. read args
  3. read paths
  4. echo Arguments: $args >&2
  5. echo Paths: $paths >&2
  6. if [ -f "$args" ] ; then
  7. echo "Performing restore from backup file $args" >&2
  8. TARGET="$args"
  9. echo "Copying $TARGET to STDOUT" >&2
  10. /usr/lib/qubes/tar2qfile $TARGET $paths
  11. else
  12. echo "Checking if arguments is matching a command" >&2
  13. COMMAND=`echo $args | cut -d ' ' -f 1`
  14. if which "$COMMAND"; then
  15. tmpdir=`mktemp -d`
  16. mkfifo $tmpdir/backup-data
  17. echo "Redirecting $args to STDOUT" >&2
  18. # Parsing args to handle quotes correctly
  19. # Dangerous method if args are uncontrolled
  20. eval "set -- $args"
  21. # Use named pipe to pass original stdin to tar2file
  22. $@ > $tmpdir/backup-data < /dev/null &
  23. retcode=$?
  24. /usr/lib/qubes/tar2qfile $tmpdir/backup-data $paths
  25. wait
  26. rm $tmpdir/backup-data
  27. rmdir $tmpdir
  28. exit $retcode
  29. else
  30. echo "Invalid command $COMMAND" >&2
  31. exit 2
  32. fi
  33. fi