-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auto_Books_Calibre.sh
71 lines (68 loc) · 3.37 KB
/
Auto_Books_Calibre.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
65
66
67
68
69
70
71
#!/bin/bash
# -*- ENCODING: UTF-8 -*-
if [ "$(ls /Books_Calibre/*.epub 2>/dev/null)" ]; then
URL="https://api.telegram.org/botTOKENBOT/sendMessage"
APIARGS="chat_id=CHATIDBOT&text="
echo "-------------------------------------------------------------"
echo "| Books Found to upload to Calibre |"
echo "-------------------------------------------------------------"
MsgTelegram="|---------------------------------------------------------|"
MsgTelegram=$MsgTelegram"%0A| Found Books to upload to Calibre |"
MsgTelegram=$MsgTelegram"%0A| "$(date)" |"
TelegramAPI=`curl -s -d "$APIARGS$MsgTelegram" $URL 2>&1`
date
echo "- Books to Add: "
MsgTelegram=" - Books to Add: %0A"
Books=/Books_Calibre/*.epub
for i in $Books
do
Book=$(echo $i | sed 's/á/a/g' | sed 's/Á/A/g' | sed 's/é/e/g' | sed 's/É/E/g' | sed 's/í/i/g' | sed 's/Í/I/g' | sed 's/ó/o/g' | sed 's/Ó/O/g' | sed 's/ú/u/g' | sed 's/Ú/U/g' | sed 's/ñ/n/g' | sed 's/Ñ/N/g' | sed 's/ü/u/g' | sed 's/Ü/U/g')
mv "$i" "$Book" 2>/dev/null
BookName=$(echo $Book | rev | awk -v FS='/' '{print $1}' | rev)
echo $BookName
MsgTelegram=$MsgTelegram" · "$BookName"%0A "
done
TelegramAPI=`curl -s -d "$APIARGS$MsgTelegram" $URL 2>&1`
echo ""
echo "-------------------------------------------------------------"
echo " Adding Books to Calibre"
echo "-------------------------------------------------------------"
calibredb add /Books_Calibre/* --with-library=/books --recurse
echo " Books Added to Calibre Library"
echo ""
echo "-------------------------------------------------------------"
echo " Backing up books .epub"
echo "-------------------------------------------------------------"
Books=/Books_Calibre/*.epub
for i in $Books
do
BookName=$(echo $i | rev | awk -v FS='/' '{print $1}' | rev)
echo "Copying... " "$BookName" " to /Books_Calibre_Backup"
CopyBook=$(cp -v "$i" /Books_Calibre_Backup)
echo $CopyBook
done
echo ""
echo " Backup Completed"
echo ""
echo "-------------------------------------------------------------"
echo " Cleaning Books Folder"
echo "-------------------------------------------------------------"
echo $(rm -rv /Books_Calibre/*)
echo " Done!!"
echo ""
echo "-------------------------------------------------------------"
echo " Backing up Calibre Library"
echo "-------------------------------------------------------------"
echo ""
cp -Ruv /books/* /Backup_Library
echo ""
echo "-------------------------------------------------------------"
echo " Library Backup Completed"
echo "-------------------------------------------------------------"
echo "####################################################################"
echo ""
MsgTelegram="| Process Completed "
MsgTelegram=$MsgTelegram"%0A| "$(date)" |"
MsgTelegram=$MsgTelegram"---------------------------------------------------------|"
TelegramAPI=`curl -s -d "$APIARGS$MsgTelegram" $URL 2>&1`
fi