-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.sh
executable file
·60 lines (50 loc) · 1.55 KB
/
convert.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
#!/bin/bash
###
which dirname 1>/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo "ERROR: Program 'dirname' isn't installed, please install it first!"
echo "TIP: Package 'coreutils' on Fedora/CentOS by: yum/dnf install coreutils"
echo "TIP: Package 'coreutils' on Debian/Ubuntu by: apt-get/aptitude install coreutils"
exit 1;
fi
which basename 1>/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo "ERROR: Program 'basename' isn't installed, please install it first!"
echo "TIP: Package 'coreutils' on Fedora/CentOS by: yum/dnf install coreutils"
echo "TIP: Package 'coreutils' on Debian/Ubuntu by: apt-get/aptitude install coreutils"
exit 1;
fi
### Constants ###
readonly BASE_DIR="`dirname $0`"
readonly RUN_ENV="bash"
readonly DOC2TXT="$BASE_DIR/doc2txt.sh"
readonly PDB2TXT="$BASE_DIR/pdb2txt.sh"
readonly RECODE="$BASE_DIR/recode.sh"
### Variables ###
INPUT_DIR="$BASE_DIR/input/"
OUTPUT_DIR="$BASE_DIR/output/"
DONE_DIR="$BASE_DIR/done/"
### Functions ###
### MAIN ###
files=( $INPUT_DIR* )
echo "Loaded ${#files[@]}"
for file in "${files[@]}"; do
echo "- $file"
file_base="`basename "$file"`"
file_name="${file_base%.*}"
file_ext="${file_base##*.}"
echo "=> $file_name ($file_ext)"
file_out="${OUTPUT_DIR}$file_name.txt"
reuslt=1
if [ "$file_ext" == "pdb" ]; then
$PDB2TXT "$file" "$file_out"
result=$?
elif [ "$file_ext" == "doc" ] || [ "$file_ext" == "rtf" ]; then
$DOC2TXT "$file" "$file_out"
result=$?
fi
if [ -f "$file_out" ] && [ $result -eq 0]; then
mv "$file" "$DONE_DIR"
$RECODE "$file_out"
fi
done