-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathods2db.sh
More file actions
executable file
·49 lines (37 loc) · 963 Bytes
/
ods2db.sh
File metadata and controls
executable file
·49 lines (37 loc) · 963 Bytes
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
#!/bin/bash
source $(dirname "$0")/common.sh
FORCE=
if [ "$1" = -f ]; then
FORCE=1
shift
fi
INPUT=$1
shift
OUTPUT=${1:-$DEFAULT_DBDSN}
shift
if [ -z "$INPUT" -o -z "$OUTPUT" ]; then
cat >&2 <<EOF
Usage: $0 [-f] file.ods [file.db]
-f force overwriting the output file
file.ods input OpenDocument Spreadsheet file
file.db output sqlite3 file. Default: \$DEFAULT_DBDSN
($DEFAULT_DBDSN)
EOF
exit 1
fi
if [ -n "$FORCE" -a -e "$OUTPUT" ]; then
{
echo "$0: Output file '$OUTPUT' already exists."
echo " Use -f to force overwrite."
} >&2
exit 3
fi
TMPDIR=$(mktemp --tmpdir -d exploratorium-ods2sql.XXXXXXXXXX)
"$SCRIPTDIR"/ods2csv.sh "$INPUT" "$TMPDIR" &&
"$SCRIPTDIR"/csv2sql.sh "$TMPDIR" > "$TMPDIR"/data.sql ||
exit 2
require_sqlite
sqlite3 "$TMPDIR"/output.db < "$DBDIR"/ddl.sql &&
sqlite3 "$TMPDIR"/output.db < "$TMPDIR"/data.sql &&
cp -f "$TMPDIR"/output.db "$OUTPUT"
[ -z "$DEBUG" ] && rm -rf "$TMPDIR"