From 4063a8e72ddd25da1412386bc7e39def54dfbf2e Mon Sep 17 00:00:00 2001 From: cielavenir Date: Tue, 25 Oct 2022 17:24:28 +0900 Subject: [PATCH] add d2u-dir.sh --- d2u-dir.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 d2u-dir.sh diff --git a/d2u-dir.sh b/d2u-dir.sh new file mode 100755 index 000000000..d3a34fafa --- /dev/null +++ b/d2u-dir.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# https://gist.github.com/tansy/c4a1f7ea1019915b4263c024757d3ac4 +# https://github.com/jinfeihan57/p7zip/pull/186#issuecomment-1223976885 + +if [ $# -eq 0 ]; then + echo "d2u-dir " + echo "will copy contents of to changing new lines from dos to unix." + echo "It ignores binary files by their extension," + echo "so you may want to copy whole dir1 to dir2 first and then apply d2u-dir." + exit 0 +fi + +# reference dir: +DIR0="${1}" +# new dir: +DIR1="${2}" +if [ -d "${DIR1}" ]; then + echo "directory ${DIR1} exists, do you want to continue? [y/N]" + read ANS + if [ "${ANS}" == "y" ] || [ "${ANS}" == "Y" ]; then + continue + else + exit 0 + fi +fi + +IFS=" +" + +if [ -n "${DIR1}" ]; then + +for line in `find "${DIR0}" -type d`; do + mkdir -p "${DIR1}/${line#$DIR0}" +done +# every `.' denoting extension has to escaped, every extension terminated with $ +for line in `find "${DIR0}" -type f | grep -Ev '\.git|\.BMP$|\.bmp$|\.BIN$|\.bin$|\.CUR$|\.cur$|\.DSP$|\.dsp$|\.DSW$|\.dsw$|\.EXE$|\.exe$|\.GIF$|\.gif$|\.icns$|\.ICO$|\.ico$|\.JAR$|\.jar$|\.JPG$|\.jpg$|\.jpeg$|\.PCX$|\.pcx$|\.PNG$|\.png$|\.RES$|\.res$|\.SFX$|\.sfx$|\.WAV$|\.wav$'`; do + dos2unix < "${line}" > "${DIR1}/${line#$DIR0}" + touch -r "${line}" "${DIR1}/${line#$DIR0}" +done +for line in `find "${DIR0}" -type d`; do + touch -r "${line}" "${DIR1}/${line#$DIR0}" +done + +else + +for line in `find "${DIR0}" -type f | grep -Ev '\.git|\.BMP$|\.bmp$|\.BIN$|\.bin$|\.CUR$|\.cur$|\.DSP$|\.dsp$|\.DSW$|\.dsw$|\.EXE$|\.exe$|\.GIF$|\.gif$|\.icns$|\.ICO$|\.ico$|\.JAR$|\.jar$|\.JPG$|\.jpg$|\.jpeg$|\.PCX$|\.pcx$|\.PNG$|\.png$|\.RES$|\.res$|\.SFX$|\.sfx$|\.WAV$|\.wav$'`; do + dos2unix "${line}" +done + +fi