summaryrefslogtreecommitdiffstats
path: root/.local/bin/kindle
blob: 31930cace8b86a6767f895c9cf1cc568e838f6f4 (plain) (blame)
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
#!/bin/bash

# Jailbroken Kindle manager. Updates KoReader install, syncs stored epubs
# Requires curl, jq, rclone and unzip

# variables
kindle_path="$(find /mnt/ -type d -name 'kindle' | head -1)"
destination_directory="$kindle_path/_books"

# functions
function library_sync {
	printf "Sycing remote library to Kindle... "
	remote_library="drive-media:literature/books"
	rclone sync "$remote_library" "$destination_directory"
	# logging? status?
	printf "done\n"
	}
function reader_update {
	printf "Downloading latest KoReader... "
	koreader_upstream="https://api.github.com/repos/koreader/koreader/releases/latest"
	koreader_architecture="kindlepw2"
	koreader_latest="$(curl -s "$koreader_upstream" | jq -r '.assets[].browser_download_url' | grep "$koreader_architecture")"
	working_directory="$(mktemp -d)"
	cd "$working_directory"
	wget -q "$koreader_latest"
	printf "done\n"
	printf "Removing old application... "
	rm -f "$kindle_path/extension" "$kindle_path/koreader"
	printf "done\n"
	printf "Upgrading application... "
	for i in *.zip; do unzip -qfo "$i" -d "$kindle_path"; done
	printf "done\n"
	printf "Cleaning up temporary paths... "
	rm -r "$directory_temp"
	printf "done\n"
	}

case "$1" in
	sync) library_sync ;;
	update) reader_update ;;
	both) library_sync && reader_update ;;
	*) exit 1 ;;
esac