forked from ralfdonald/TingScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux.sh
executable file
·108 lines (89 loc) · 2.5 KB
/
linux.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
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
TING="${1}"
if [ -z "${1}" ] ; then
TING="$(grep '/TING\s' /proc/mounts |cut -d ' ' -f 2)"
if ! [ -d "${TING}/\$ting" ] ; then
TING=
fi
fi
if [ -z "${TING}" ]; then
echo "TING konnte nicht automatisch erkannt werden. Bitte gib den Mount-Point des TING-Stifts als Parameter mit."
echo "Usage: $0 [Ort des \$ting-Ordners]"
exit 1
fi
tingPath="$TING"
pngEnd="_en.png"
txtEnd="_en.txt"
oufEnd="_en.ouf"
scrEnd="_en.script"
# entfernt ^M aus Datei und schreibt die Zeilen neu
cleanFile () {
echo "Säubere File $1"
while read -r line
do
$(echo -n "$line" | tr -d $'\r' | grep "[0-9]" >> TBD_TEMP.TXT)
done < "$filename"
rm $1
mv TBD_TEMP.TXT $1
echo ""
}
# leert die ganze Datei
emptyFile () {
echo "Leere File $1"
echo ""
truncate --size=0 $1
}
checkFiles () {
echo "Prüfe Datei $3";
thumbMD5=$(cat $3 | grep "ThumbMD5:" | grep -ow "[0-9a-z]*");
s=$(echo "$1" | sed 's/^0*//')
if [ -z $thumbMD5 ]; then
echo "Kein Vorschaubild notwendig"
else
echo "Downloade Vorschaubild $1$pngEnd"
wget http://system.ting.eu/book-files/get/id/$s/area/en/type/thumb -O $2/$1$pngEnd
fi
fileMD5=$(cat $3 | grep "FileMD5:" | grep -ow "[0-9a-z]*")
if [ -z $fileMD5 ]; then
echo "Kein Buchfile notwendig"
else
echo "Downloade Buchfile $1$oufEnd"
wget http://system.ting.eu/book-files/get/id/$s/area/en/type/archive -O $2/$1$oufEnd
fi
scriptMD5=$(cat $3 | grep "ScriptMD5:" | grep -ow "[0-9a-z]*")
if [ -z $scriptMD5 ]; then
echo "Kein Scriptfile notwendig"
else
echo "Downloade Scriptfile $1$scrEnd"
wget http://system.ting.eu/book-files/get/id/$s/area/en/type/script -O $2/$1$scrEnd
fi
echo ""
}
getInfo () {
s=$(echo "$1" | sed 's/^0*//')
echo "short: $s"
wget http://system.ting.eu/book-files/get-description/id/"$s"/area/en -O "$2"/"$1""$3"
}
getFiles () {
bookId=$1
echo "Lade BuchId $bookId"
getInfo $bookId "$2" $txtEnd
checkFiles $bookId $2 "$2/$1$3$txtEnd"
echo ""
}
echo "Ort des \$ting-Ordner: $tingPath"
filename="$tingPath/\$ting/TBD.TXT"
if ! [ -f "$filename" ] ; then
filename="$tingPath/\$ting/tbd.txt"
fi
if [ "$(wc -l "$filename"|cut -d ' ' -f 1)" == 0 ] ; then
echo 'Kein fehlendes Buch gefunden.'
exit 0
fi
cleanFile "$filename"
while read -r line
do
export bookId=$(echo -n "$line" | tr -d $'\r' | grep "[0-9]")
getFiles "$bookId" "$tingPath/\$ting"
done < "$filename"
emptyFile "$filename"