This repository was archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-dropbox-awake.sh
executable file
·64 lines (61 loc) · 2.33 KB
/
is-dropbox-awake.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
#!/bin/bash
#
# This script monitors for when Dropbox has finished syncing.
#
# Todo:
# - Make this thing more efficient. It really shouldn't call `dropbox status` so
# many times to figure out one bit of info.
# - Read maxWaitTime from config file, default to 5 minutes
#
# Notes:
#
# I should probably incorporate this into the script, but for now:
#
# If you have too many files in Dropbox, it will not have permission to monitor
# to monitor all of the contents of the Dropbox folder. This can be fixed either
# by increasing the number of files that can be monitored. To do this until the
# next reboot, run:
# sudo sysctl fs.inotify.max_user_instances=256
# sudo sysctl fs.inotify.max_user_watches=1048576
# To do so perminantly, add the following lines to /etc/sysctl.conf
# fs.inotify.max_user_watches = 1048576
# fs.inotify.max_user_instances = 256
# Source: https://askubuntu.com/questions/247461/
startTime=$(date +%s)
maxWaitTime=300 # Time before erroring out in seconds
# Loop every 5 seconds until Dropbox says it's done
while [[ $(dropbox status) != "Up to date" ]] ; do
# If Dropbox is just starting up
if [[ $(dropbox status) == "Starting..." ]] ; then
echo -ne "\rDropbox hasn't woken up yet."
# Timeout if Dropbox is frozen
if [[ $(date +%s) -ge $startTime+$maxWaitTime ]] ; then
echo -ne "\rDropbox has been starting for five minutes."
echo -ne " You may need to restart it.\n"
exit 1
fi
# If Dropbox is indexing
elif [[ $(dropbox status | grep Indexing) == "Indexing..." ]] ; then
echo -ne "\rDropbox is making a todo list."
# If Dropbox is syncing
elif [[ $(dropbox status | grep Syncing | cut -d' ' -f 1) == "Syncing" ]]
then
echo -ne "\rDropbox is actually syncing (finally)."
elif [[ $(dropbox status) == "Dropbox isn't running!" ]] ; then
dropbox stop
killall dropbox
dropbox start
echo
echo -ne "\rDropbox was not running. I started it."
else
echo -ne "\rDropbox output an unrecognize message. Exiting script."
echo -ne "\nThe output of \`dropbox status\` is:\n"
dropbox status
exit 1
fi
sleep 5
done
# Celebrate if it's finally done
if [[ $(dropbox status) == "Up to date" ]] ; then
echo -ne "\rIT'S DONE!!!!\n"
fi