-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsqlite.sh
More file actions
executable file
·99 lines (74 loc) · 2.09 KB
/
sqlite.sh
File metadata and controls
executable file
·99 lines (74 loc) · 2.09 KB
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
#!/usr/bin/env bash
# sqlite.sh
#
# Downloads the official SQLite3 DB and builds it with extra compilation
# settings that allow for easier analysis
#
# Parameters:
# $1 is the directory in which the SQLite DB will be built in
# $2 is the name of the compiled SQLite binary
source "echof.sh"
SQLITE_DIR="$1"
SQLITE_BIN="$2"
SQLITE_URL_SRC='https://www.sqlite.org/2019/sqlite-amalgamation-3280000.zip'
SQLITE_ZIP_SRC=$(basename "${SQLITE_URL_SRC}")
SQLITE_OPTIONS="\
-lpthread \
-ldl \
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
-DSQLITE_OMIT_BTREECOUNT \
"
PREREQUISITES=(
'gcc'
'unzip'
'wget'
)
# Validate parameters and installed prerequisites
validate() {
if [[ -z "${SQLITE_DIR}" ]] ; then
echof "Parameter for sqlite build directory is undefined"
exit 1
elif [[ -z "${SQLITE_BIN}" ]] ; then
echof "Parameter for sqlite binary name is undefined"
exit 2
fi
for (( i = 0; i < ${#PREREQUISITES[@]} ; i++ )) ; do
if ! [[ -x "$(command -v ${PREREQUISITES[i]})" ]] ; then
echof "Prerequisite not found; please install with 'sudo apt install ${PREREQUISITES[i]}' and try again"
exit $(( 101 + i ))
fi
done
}
# Retrieve the sqlite source code and unpack the zip
unpack() {
if [[ -f "${SQLITE_BIN}" ]] ; then
echof "Binary file '${SQLITE_BIN}' already exists, so no need to recompile; exiting script"
exit 0
else
echof "Attempting to download and unpack source code"
fi
wget "${SQLITE_URL_SRC}"
unzip -j "${SQLITE_ZIP_SRC}"
rm -f "${SQLITE_ZIP_SRC}"
echof "Unpacking successful"
}
# Build the amalgamation
build() {
echof "Attempting to build source code"
gcc shell.c sqlite3.c ${SQLITE_OPTIONS} -o ${SQLITE_BIN}
rm -f *.c *.h
echof "Compilation successful"
}
main() {
validate
if [[ ! -d "${SQLITE_DIR}" ]] ; then
echof "Creating directory ${SQLITE_DIR}"
mkdir "${SQLITE_DIR}"
fi
echof "Changing to directory ${SQLITE_DIR}"
cd "${SQLITE_DIR}"
unpack
build
echof "Installation successful"
}
main