This repository has been archived by the owner on Nov 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fetch.sh
executable file
·95 lines (83 loc) · 2.62 KB
/
fetch.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Usage: fetch.sh [version]
# Or: fetch.sh version language translation abbreviation textdirection [auto]
# Or: bash <(./fetch.sh all)
# Or: bash <(./fetch.sh all-with-file translations.txt)
# Requirements: curl, unzip, grep, sed
LIST_URL='http://unbound.biola.edu/index.cfm?method=downloads.showDownloadMain'
DOWNLOAD_URL='http://unbound.biola.edu/index.cfm?method=downloads.downloadBible'
if [[ -z "$1" ]]; then
versions="$(curl -s "$LIST_URL" |\
grep -A 1 "<select name='version_download'>" | tail -1 |\
sed -r 's/ ?<option value='\''([^'\'']*)'\''>([^<]*)<\/option>/\1\t\2\n/g')"
select version in $(echo "$versions" | head -n -1 | cut -f2 | sed 's/[[:space:]]/./g'); do
version="$(echo "$versions" | grep -F "${version//./ }" | cut -f1)"
break
done
elif [[ "$1" = "all" ]]; then
curl -s "$LIST_URL" |\
grep -A 1 "<select name='version_download'>" | tail -1 |\
sed -r 's/ ?<option value='\''([^'\'']*)'\''>([^<]*)<\/option>/\1\t\2\n/g' |\
head -n -1 | cut -f1 |\
while read version; do
echo "$0" "$version"
done
exit
elif [[ "$1" = "all-with-file" ]]; then
LISTFILE="$2"
I=0
curl -s "$LIST_URL" |\
grep -A 1 "<select name='version_download'>" | tail -1 |\
sed -r 's/ ?<option value='\''([^'\'']*)'\''>([^<]*)<\/option>/\1\t\2\n/g' |\
head -n -1 | cut -f1 |\
while read version; do
I=$((I+1))
LINE="$(grep -v '^#' "$LISTFILE" | sed "${I}q;d")"
language="$(echo "$LINE" | cut -f 2)"
translation="$(echo "$LINE" | cut -f 3)"
abbreviation="$(echo "$LINE" | cut -f 4)"
textdirection="$(echo "$LINE" | cut -f 5)"
echo "$0" "'$version'" "'$language'" "'$translation'" "'$abbreviation'" "'$textdirection'" "auto"
done
exit
else
version="$1"
fi
echo "Going to download $1..."
rm -rf tmp
mkdir tmp
cd tmp
curl \
--location --progress-bar \
--data-urlencode "version_download=$version" \
"$DOWNLOAD_URL" > bible.zip
unzip bible.zip >/dev/null
rm bible.zip
if [[ "$6" = "auto" ]]; then
file="$(ls -S | grep -v 'NRSVA\|html' | head -1)"
else
echo "Which file should I convert?"
select file in $(ls -S *.txt); do
break
done
fi
if [ "$#" -ge 5 ]; then
language="$2"
translation="$3"
abbreviation="$4"
textdirection="$5"
else
read -p "Language: " language
read -p "Translation: " translation
read -p "Abbreviation: " abbreviation
read -p "Text direction: " textdirection
fi
newfile="$(../convert.sh \
-l "$language" -d "$textdirection" -t "$translation" -a "$abbreviation" \
-i "$file")"
cd ..
mkdir -p Bibles
cp "tmp/$newfile" Bibles
cp tmp/*.html "Bibles/${newfile/\.txt/}-copyright.html"
rm -r tmp
echo "Successfully downloaded $newfile."