summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoran S. Diao <0@hairydiode.xyz>2019-11-24 05:08:35 -0800
committerHaoran S. Diao <0@hairydiode.xyz>2019-11-24 05:08:35 -0800
commit11a4bf7870191f44dc89faabba7197005a017d0f (patch)
tree6cee7261b8cbb3ec5862dc735455ac6304674260
Initial commit
-rw-r--r--Makefile8
-rw-r--r--README4
-rwxr-xr-xcalwrapper93
-rwxr-xr-xgetcalpass2
-rwxr-xr-xgetcaluser2
5 files changed, 109 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1e5f909
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+install: calwrapper getcalpass getcaluser
+ mkdir /etc/calwrapper
+ cp getcalpass /etc/calwrapper/getcalpass
+ cp getcaluser /etc/calwrapper/getcaluser
+ cp calwrapper /usr/bin/calwrapper
+uninstall: calwrapper getcalpass getcaluser
+ rm -r /etc/calwrapper
+ rm /usr/bin/calwrapper
diff --git a/README b/README
new file mode 100644
index 0000000..5f89b1a
--- /dev/null
+++ b/README
@@ -0,0 +1,4 @@
+Calwrapper is a file intended to be run manually that will periodically call
+vdirsyncer to sync locally a remote calDAV .ics store. It stores the username
+and password in environmental variables so it isn't the most secure, but it'
+more secure than storing it in a plainttext file. To install, run make.
diff --git a/calwrapper b/calwrapper
new file mode 100755
index 0000000..da0a46c
--- /dev/null
+++ b/calwrapper
@@ -0,0 +1,93 @@
+#!/bin/bash
+#state variable that determines if the main loop is running
+loop=true
+#time of next update
+nexttime=$(date +%s)
+#intervals between updates in seconds
+interval=60
+#time before an starts before a notification pops up
+remind=900
+#gets username and password
+read -p "username:" caluser
+export caluser
+read -s -p "password:" calpass
+echo ""
+export calpass
+#This has to be done at the beginning of every run of the script now, don't know
+#why, but if it isn't then vdirsyncer sync will refuse to run
+vdirsyncer discover
+#help message
+echo "Beginning to sync up caledar files, type \"q\" + enter to quit,
+\"s\" + enter to sync now,
+\"k\" + enter to launch khal in interactive mode,
+and \"a\" + enter to list agenda"
+while [ "$loop" == true ]; do
+ #w/ timeout of 1, read input
+ read -t 1 input
+ #handles quit, this is run at every loop and pretty much determines how
+ #slow the loop runs
+ if [ "$input" == "q" ]; then
+ loop=false
+ fi
+ if [ "$input" == "k" ]; then
+ khal interactive
+ #in case anything was editted
+ nexttime=$(date +%s)
+ fi
+ if [ "$input" == "a" ]; then
+ khal calendar
+ fi
+ if [ "$input" == "s" ]; then
+ nexttime=$(date +%s)
+ fi
+ #If the current time is greater than the next scheduled update, update
+ if [ $(date +%s) -ge $nexttime ]; then
+ echo starting sync at $(date +%s)
+ #syncs with remote calDAV server
+ vdirsyncer sync
+ #stores the old list of upcoming events so that we can compare
+ #after updating, this will create an error on the first run but
+ #this doesn't matter
+ mv ~/.vdirsyncer/events ~/.vdirsyncer/oldevents
+ #updates khal and also list any upcoming events
+ #determines in seconds the interval of time that khal limits
+ #itself to when looking for events (their start times have have
+ #to fall within this interval)
+ window=$(( (interval) * 3 ))s
+ #determines the time which khal is actually querying, this
+ #should be now + remind before time, window does not matter
+ #because we're testing for when an event passes out of the
+ #interval
+ testtime=$(( $(date +%s) + $remind ))
+ #now get the properly formated string representing the above
+ #time in a way khal understands
+ #Note: The below only works if the time format is set to be the
+ #same way in khal's config
+ timestring=$(date --date="@$testtime" "+%m/%d/%Y %I:%M %p")
+ echo Testing for upcoming events at $timestring
+ #writes upcoming events to events file to be diffed later
+ khal list $now $timestring --once --notstarted >> ~/.vdirsyncer/events
+ #checks to see if any changes in the upcoming events queue
+ #exists by diff'ing oldevents and events, then finding what was
+ #removed
+ difference=$(diff ~/.vdirsyncer/oldevents ~/.vdirsyncer/events | grep "<")
+ #only when an event is exiting the test interval do we care, so
+ #if $difference is "< No events" or empty, then we say that
+ # an event entered the interval or no change occured
+ #Schedules the next update, keeps adding $interval until we get
+ #one that's actually in the future, since it's not guaranteed
+ #that each update will take less than 1 $interval to run
+ if [ "$difference" == "" ]; then
+ echo No changes in upcoming events
+ elif [ "$difference" == "< No events" ]; then
+ echo an event entered the test interval
+ else
+ echo an event has exited the test interval
+ notify-send "$difference"
+ fi
+ while [ $(date +%s) -ge $nexttime ]; do
+ nexttime=$(( $nexttime + $interval))
+ done
+ echo next sync scheduled at $nexttime
+ fi
+done
diff --git a/getcalpass b/getcalpass
new file mode 100755
index 0000000..4a8cb96
--- /dev/null
+++ b/getcalpass
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo -n $calpass
diff --git a/getcaluser b/getcaluser
new file mode 100755
index 0000000..f2360a2
--- /dev/null
+++ b/getcaluser
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo -n $caluser