2013-11-19 13:35:51 +01:00
|
|
|
echo Starting Restorecopy >&2
|
2013-11-09 19:01:57 +01:00
|
|
|
read args
|
2013-11-14 21:26:31 +01:00
|
|
|
read paths
|
2013-11-19 13:35:51 +01:00
|
|
|
echo Arguments: $args >&2
|
|
|
|
echo Paths: $paths >&2
|
2013-11-09 19:01:57 +01:00
|
|
|
if [ -f "$args" ] ; then
|
2013-11-19 13:35:51 +01:00
|
|
|
echo "Performing restore from backup file $args" >&2
|
2013-11-09 19:01:57 +01:00
|
|
|
TARGET="$args"
|
2013-11-19 13:35:51 +01:00
|
|
|
echo "Copying $TARGET to STDOUT" >&2
|
2013-11-14 21:26:31 +01:00
|
|
|
/usr/lib/qubes/tar2qfile $TARGET $paths
|
2013-11-09 19:01:57 +01:00
|
|
|
else
|
2013-11-19 13:35:51 +01:00
|
|
|
echo "Checking if arguments is matching a command" >&2
|
2013-11-09 19:01:57 +01:00
|
|
|
COMMAND=`echo $args | cut -d ' ' -f 1`
|
2015-02-05 03:14:41 +01:00
|
|
|
if which "$COMMAND"; then
|
2013-11-09 19:01:57 +01:00
|
|
|
tmpdir=`mktemp -d`
|
|
|
|
mkfifo $tmpdir/backup-data
|
2013-11-19 13:35:51 +01:00
|
|
|
echo "Redirecting $args to STDOUT" >&2
|
2013-11-09 19:01:57 +01:00
|
|
|
# Parsing args to handle quotes correctly
|
|
|
|
# Dangerous method if args are uncontrolled
|
|
|
|
eval "set -- $args"
|
|
|
|
# Use named pipe to pass original stdin to tar2file
|
|
|
|
$@ > $tmpdir/backup-data < /dev/null &
|
|
|
|
retcode=$?
|
2013-11-14 21:26:31 +01:00
|
|
|
/usr/lib/qubes/tar2qfile $tmpdir/backup-data $paths
|
2013-11-09 19:01:57 +01:00
|
|
|
wait
|
|
|
|
rm $tmpdir/backup-data
|
|
|
|
rmdir $tmpdir
|
|
|
|
exit $retcode
|
|
|
|
else
|
2013-11-19 13:35:51 +01:00
|
|
|
echo "Invalid command $COMMAND" >&2
|
|
|
|
exit 2
|
2013-11-09 19:01:57 +01:00
|
|
|
fi
|
|
|
|
fi
|