-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync_template.sh
executable file
·47 lines (39 loc) · 1.21 KB
/
sync_template.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
#!/usr/bin/env bash
[[ ! -d "$LOCAL_DIR" ]] && sudo mkdir "$LOCAL_DIR" && sudo chown -R "$USER:$USER" "$LOCAL_DIR" 2>"$LOG_FILE"
[[ ! -d "$MOUNT_FILE" ]] && sudo mkdir "$MOUNT_FILE" && sudo chown -R "$USER:$USER" "$MOUNT_FILE" 2>"$LOG_FILE"
doSynchronization()
{
sudo mount "$NODE_FILE" "$MOUNT_FILE" >> "$LOG_FILE" 2>&1
rsync -rtDvz --ignore-existing $LOCAL_DIR $ABSOLUTE_REMOTE_DIR >> "$LOG_FILE" 2>&1
sudo umount "$MOUNT_FILE"
}
echo "Starting Kindle Updater" >> "$LOG_FILE"
trap "rm -f $PIPE_FILE" EXIT
#If the pipe doesn't exist, create it
if [[ ! -p $PIPE_FILE ]]; then
mkfifo $PIPE_FILE
fi
#If the disk is already plugged on startup, do a syn
if [[ -e "$NODE_FILE" ]]
then
doSynchronization
fi
#Make the permanent loop to watch the usb connection
while true
do
if read line <$PIPE_FILE; then
#Test the message read from the fifo
if [[ "$line" == "connected" ]]
then
#The usb has been plugged, wait for disk to be mounted by KDE
while [[ ! -e "$NODE_FILE" ]]
do
sleep 1
done
doSynchronization
else
echo "Unhandled message from fifo : [$line]"
fi
fi
done
echo "Reader exiting"