qubes.Restore 909 B

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