-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzwartrood
executable file
·64 lines (56 loc) · 1.4 KB
/
zwartrood
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
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# Change volume (disk) names here:
D1='T7Zwart'
D2='T7Rood'
# Mount point of external disks
M=/Volumes/
# Is the disk connected?
checkvol () {
[ -e "$M$1" -a -d "$M$1" -a -r "$M$1" -a -w "$M$1" ] || {
echo "Disk not found or not accessible: $1" >&2
exit 1
}
return 0
}
checkvol "$D1"
checkvol "$D2"
# Is rsync available?
APP=rsync
BIN="$(which $APP)"
[ -z "$BIN" ] && { echo "Command not found: $APP" >&2; exit 2; }
# Disk free space on MacOS or Linux:
OS="$(uname)"
if [ "$OS" = 'Darwin' ]; then
F1=$(df -g "$M$D1" | tail -n1 | awk '{print $4}')
F2=$(df -g "$M$D2" | tail -n1 | awk '{print $4}')
elif [ "$OS" = 'Linux' ]; then
F1=$(df -BG "$M$D1" | tail -n1 | awk '{print $4}' | grep -oP '\d+')
F2=$(df -BG "$M$D2" | tail -n1 | awk '{print $4}' | grep -oP '\d+')
else
echo "Unknown system: $OS" >&2
exit 3
fi
# Show disk free space and offer to opt out:
echo 'Free space on disk:'
echo
printf " %-15s %5u GB\n" "$D1" "$F1"
printf " %-15s %5u GB\n" "$D2" "$F2"
echo
IFS=
read -p "Completely synchronise disks $D1 and $D2? (y/N) " -n 1 -s -r
echo
# Do the thing if confirmed
if [[ "$REPLY" =~ ^[Yy]$ ]]
then
ARG='-auv --exclude=.Spotlight-V100 --exclude=.Trashes --exclude=.fseventsd --exclude=.DS_Store'
echo
echo " Synchronising from $D1 to $D2 ..."
echo
$APP $ARG "$M$D1/" "$M$D2/"
echo
echo " Synchronising from $D2 to $D1 ..."
echo
$APP $ARG "$M$D2/" "$M$D1/"
else
exit 4
fi