qubes.Restore 964 B

12345678910111213141516171819202122232425262728293031323334
  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. TYPE=`type -t $COMMAND`
  15. if [ "$TYPE" == "file" ] ; then
  16. tmpdir=`mktemp -d`
  17. mkfifo $tmpdir/backup-data
  18. echo "Redirecting $args to STDOUT" >&2
  19. # Parsing args to handle quotes correctly
  20. # Dangerous method if args are uncontrolled
  21. eval "set -- $args"
  22. # Use named pipe to pass original stdin to tar2file
  23. $@ > $tmpdir/backup-data < /dev/null &
  24. retcode=$?
  25. /usr/lib/qubes/tar2qfile $tmpdir/backup-data $paths
  26. wait
  27. rm $tmpdir/backup-data
  28. rmdir $tmpdir
  29. exit $retcode
  30. else
  31. echo "Invalid command $COMMAND" >&2
  32. exit 2
  33. fi
  34. fi