-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavensync
54 lines (44 loc) · 1.14 KB
/
avensync
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
52
53
54
#!/opt/bin/zsh
s=/volume1/music
t=/volumeUSB1/usbshare/mp3
d=/volume1/music/avensismusic
fl=/volume1/music/avensifl
# t=/volume1/downloads/avensitest
# d=/volume1/music/avensismusic_test
# fl=/volume1/music/avensifl_test
rs="/opt/bin/rsync --modify-window=1 -rtv --progress --no-p --no-g --delete --files-from=$fl"
cd $s
for i in $(< $d); do
if [[ ! -d $i ]]; then
if nd=$(find ${i%/*} -mindepth 1 -type d -iname "*${i##*/}"); then
echo "trying to replace $i with $nd"
sed -i "s|$i|$nd|" $d
else
local stop=yes
fi
fi
done
if [[ $stop == "yes" ]]; then
echo "First fix these entries please."
exit 0
fi
if [[ ! -e $fl ]] || [[ $d -nt $fl ]]; then
echo "Generating new filelist"
find $(< $d ) -maxdepth 1 -type f > $fl
fi
if ! mount | grep -q /volumeUSB1/usbshare; then
echo "gimme that SD card!" >&2
exit 1
fi
${=rs} $s $t/
echo "Cleanup? [y/N]"
read -rsk 1 answer
if [[ $answer != y ]]; then
exit 0
fi
find $t -type f -printf '%P\n'| while read i; do
if ! fgrep -q "$i" $fl; then
rm -v $t/$i
fi
done
find $t -depth -type d -empty -exec rmdir -v "{}" \;