-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcwa-glue.sh
41 lines (36 loc) · 1.22 KB
/
cwa-glue.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
#!/usr/bin/env bash
#
# Automate moving e-book files into the calibra-web-automated ingest directory
# https://github.com/sudonem/calibre-web-automated-glue
# Version: 1.0
# Date: 20205-03-16
#
# E-book file extensions WITHOUT the leading dot
ebook_extensions=("epub" "azw" "mobi" "pdf" "azw3" "azw4" "cbz" "cbr" "cb7" "docx" "html" "htmlz" "lit" "odt" "pdb" "rtf")
download_path='[PATH TO DOWNLOADED FILES]'
ingest_path='[PATH TO CWA INGEST DIRECTORY]'
# Set to "c" for copy mode, or "m" for move mode
move_or_copy="c"
# Generate list of new e-book files
for ext in "${ebook_extensions[@]}"; do
readarray -t temp_list < <(find "$download_path" -name "*.$ext")
file_list+=("${temp_list[@]}")
done
# Get file count for logger
file_count=${#file_list[@]}
# Move detected e-book files to calibre ingest path
if [ "$move_or_copy" == "m" ]; then
echo "Move mode enabled"
for book in "${file_list[@]}"; do
mv -u "$book" "$ingest_path"
done
logger -s "Moved $file_count calibre files from $download_path to $ingest_path"
exit 0
else
echo "Copying e-book files"
for book in "${file_list[@]}"; do
cp "$book" "$ingest_path"
done
logger -s "Copied $file_count calibre files from $download_path to $ingest_path"
exit 0
fi