-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_eCal_data.sh
executable file
·53 lines (40 loc) · 1.22 KB
/
gen_eCal_data.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
#! /bin/bash
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
### User Settings
Enable_Wifi_check="no"
Wifi_SSID="WIFI_SSID"
Server_Address="[email protected]"
Cal_Output_Filename="eCal_output.js"
Server_Upload_Directory="/root/eCal/eCal-scripts/eCal-html/"
##### Script #####
generate_eCal_Json () {
icalPal="/usr/local/bin/icalPal"
FLAGS=(-o json)
scope="eventsToday"
output=$($icalPal $scope "${FLAGS[@]}")
echo "Contents"
echo $output
echo -n 'eCal_output = '$output';' > /tmp/$Cal_Output_Filename
}
upload_to_server () {
# Make sure ssh key is loaded
export SSH_AUTH_SOCK=$( ls /private/tmp/com.apple.launchd.*/Listeners )
# Upload file to server
if /usr/bin/rsync -av /tmp/$Cal_Output_Filename $Server_Address:$Server_Upload_Directory$Cal_Output_Filename ; then
echo "upload succeeded"
else
echo "upload failed"
fi
}
if [[ $Enable_Wifi_check = "yes" ]]; then
if [[ $(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F: '/ SSID/{print $2}') = '$Wifi_SSID' ]]; then
echo "On home network, running"
generate_eCal_Json
upload_to_server
else
echo "Not on home network, not running."
fi
else
generate_eCal_Json
upload_to_server
fi