diff options
Diffstat (limited to 'ddrescue_r')
| -rwxr-xr-x | ddrescue_r | 68 |
1 files changed, 53 insertions, 15 deletions
@@ -1,16 +1,54 @@ -#!/bin/sh +#!/bin/bash -echo '------------------------------------------------------------------------' -ilen=(1+${#1}) -find "${1}" -type d -print0 | while read -d $'\0' d;do - dname="${d:${ilen}}" - echo "*** ${dname}" - mkdir -p "${dname}" -done -echo "Directory tree restored" -find "${1}" -type f -print0 | while read -d $'\0' f; do - fname="${f:${ilen}}" - echo "+++ ${fname}" - ddrescue "${1}/${fname}" "${2}/${fname}" -done -echo "Done." +set -o nounset +set -o errexit +set -o pipefail + +readonly ARGS=( "${@}" ); + +main() +{ + local _input_root; + _input_root="${1}"; shift; + + local _output_root; + _output_root="${1}"; shift; + + local input_root; + input_root="$(readlink --canonicalize-existing "${_input_root}")"; + + local output_root; + output_root="$(readlink --canonicalize-missing "${_output_root}")"; + + local input_length; + input_length=$((${#input_root} + 1)); + + find "${input_root}" -type d -print0 \ + | while read -r -d $'\0' d; + do + local dname; + dname="${d:${input_length}}"; + + local target; + target="${output_root}/${dname}"; + + >&2 echo "*** ${dname}/" + mkdir -p "${target}" + done + + >&2 echo "Directory tree restored" + + find "${input_root}" -type f -print0 \ + | while read -r -d $'\0' f; + do + local fname; + fname="${f:${input_length}}"; + + >&2 echo "+++ ${fname}" + ddrescue --quiet "${input_root}/${fname}" "${output_root}/${fname}" + done + + >&2 echo "Done." +} + +main "${ARGS[@]}" |
