This repository has been archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsync.sh
executable file
·75 lines (65 loc) · 2.69 KB
/
rsync.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
echo 'OSX ServerSync V5'
displayNotification() {
if [[ -z "$1" || -z "$2" ]]; then
osascript -e 'display notification "Missing message or title. No notification passed."'
sleep 1
echo -e "Missing message or title. No notification passed."
return 1
else
osascript -e "display notification \"$1\" with title \"$2\""
sleep 1
echo "$1"
fi
return 0
}
lastUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
serverAddress='contoso.com'
serverDisk='MyCoolShareName'
serverDirectory='/test/' # Path below intended to be absolute - see rsync line
mountPoint="/Volumes/$serverDisk"
localDestination="/Users/$lastUser/Documents/test/"
connectionErrorTitle="Connection Failure!"
emptyErrorTitle="Sync Error"
pingError="The server $serverAddress is not responding.\nAre you connected to the office network?"
authError="Authentication to $serverAddress failed.\nContact an administrator if the issue persists."
emptyError="You do not have permission to view the folder. Please contact an administrator if issue persists."
ping -c 1 $serverAddress > /dev/null 2>&1
if [ $? != 0 ]; then
displayNotification "$pingError" "$connectionErrorTitle"
exit 1
fi
if [ ! -d $mountPoint ]; then
open afp://$serverAddress/$serverDisk # Alternates: mount -t afp, mount_afp
sleep 8
fi
if [ ! -d $mountPoint ]; then
displayNotification "$authError" "$connectionErrorTitle"
exit 2
fi
if find $mountPoint$serverDirectory -maxdepth 0 -empty | read -r; then
isEmpty=1
fi
if [ "$isEmpty" == 1 ]; then
displayNotification "$emptyError" "$emptyErrorTitle"
exit 3
else
osascript -e "tell app \"System Events\"
Activate
display dialog \"Synchronize and overwrite\n$serverAddress/$serverDisk$serverDirectory to\n$localDestination?\" buttons {\"OK\", \"Cancel\"} default button 1 with title \"Confirm folder synchronization?\" with icon caution
end tell" > /dev/null 2>&1
if [ $? == 0 ]; then
displayNotification "Synchronizing $serverDisk$serverDirectory to $localDestination" "Transferring.."
rsync -av "$mountPoint$serverDirectory" "$localDestination"
if [ $? == 0 ]; then
displayNotification "$serverAddress/$serverDisk$serverDirectory successfully transferred to $localDestination" "Transfer Complete!"
else
displayNotification "$serverDisk$serverDirectory failed to transfer." "Transfer Failed!"
exit 4
fi
else
displayNotification "Transfer cancelled by user." "Transfer cancelled."
exit 5
fi
fi
exit 0