-
Notifications
You must be signed in to change notification settings - Fork 5
/
check_health.sh
68 lines (54 loc) · 1.54 KB
/
check_health.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
#!/bin/bash
OUTPUTFOLDER=${TMP_DIR:-/tmp/cwa-book-downloader}
mkdir -p $TMP_DIR
OUTPUTFOLDER=${INGEST_DIR:-/cwa-book-ingest}
mkdir -p $OUTPUTFOLDER
# Get a list of files to process
# Check if a file was supplied through command line arguments
if [ "$#" -gt 0 ]; then
files=("$@")
else
files=($TMP_DIR*)
fi
# Total number of files
total_files=${#files[@]}
good=0
bad=0
manual=0
# Process files in the 'downloads' directory
for file in "${files[@]}"; do
# Skip if it's not a regular file
[ -f "$file" ] || continue
# Extract filename and extension
filenamewithext="${file##*/}"
filename="${filenamewithext%.*}"
fileextension="${filenamewithext##*.}"
case "$fileextension" in
epub|mobi|azw3|fb2|djvu|cbz|cbr)
# Attempt to convert the file to EPUB
ebook-convert "$file" "$OUTPUTFOLDER/$filename.epub" >/dev/null 2>&1
# if file exists in $OUTPUTFOLDER/$filename.epub then it is a good file
if [ -f "$OUTPUTFOLDER/$filename.epub" ]; then
good=$((good + 1))
else
bad=$((bad + 1))
fi
rm "$file"
;;
*)
# Move other files to the 'other' directory
rm "$file"
bad=$((manual + 1))
;;
esac
done
# Move to a new line after the progress bar completes
echo
echo "Out of $total_files, $good are good, $bad are corrupt and $manual need manual inspection"
if [ "$bad" -gt 0 ]; then
exit 2
fi
if [ "$manual" -gt 0 ]; then
exit 1
fi
exit 0