forked from p7zip-project/p7zip
-
Notifications
You must be signed in to change notification settings - Fork 2
/
d2u-dir.sh
executable file
·51 lines (42 loc) · 1.7 KB
/
d2u-dir.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 <directory1/dos> <directory2/ux>"
echo "will copy contents of <dir1> to <dir2> 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