summaryrefslogtreecommitdiff
path: root/bin/kindlenotes
blob: a1d33e189d9791ac7ba48ed3c809f3ed2caa2916 (plain)
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
#!/bin/bash

MNT=/mnt/kindle
DEST="$HOME/lib/Dropbox/Kindle notes"

kindle=$(blkid | awk -F: '/Kindle/ { print $1; exit; }')
filename=$(date +kindle_%F_%H%M.txt)
group=$(groups | awk '{print $1}')
sudo mkdir -p "$MNT"
mkdir -p "$DEST"

sudo umount $kindle
sudo mount $kindle $MNT

if [ -e "$DEST/$filename" ]; then
    echo >&2 ERROR: Won\'t clobber other Kindle notes
elif sudo mv --no-clobber \
    "$MNT/documents/My Clippings.txt" \
    "$DEST/$filename"; then
    sudo chown "$USER:$group" "$DEST/$filename"
    # remove the supporting file only if the clippings were moved successfully
    sudo rm -rf "$MNT/documents/My Clippings.sdr"
else
    echo >&2 ERROR: Couldn\'t move the clippings file
fi
        
sudo umount $kindle