From a7e08a6fe7ecdcf454ba67eaf8a852bfb85790f1 Mon Sep 17 00:00:00 2001 From: Sylvain Herlédan Date: Thu, 16 Jul 2026 21:42:02 +0200 Subject: Bashify ddrescue_r --- ddrescue_r | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 16 deletions(-) (limited to 'ddrescue_r') diff --git a/ddrescue_r b/ddrescue_r index f2d55c1..38fddc4 100755 --- a/ddrescue_r +++ b/ddrescue_r @@ -1,16 +1,54 @@ -#!/bin/sh - -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." +#!/bin/bash + +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[@]}" -- cgit v1.3.1