-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_static_sqlite.sh
executable file
·72 lines (51 loc) · 1.81 KB
/
build_static_sqlite.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
#!/bin/sh
SQLITE_ZIP_URL='https://sqlite.org/2024/sqlite-amalgamation-3470000.zip'
SQLite_compressor='upx' # Program to use for compressing compiled sqlite
# Keep it empty as "" to disable compression
DockerImage='static-sqlite'
### No user intervention below this point ######################################
onErr(){
local msg errNum
msg="${1}"
errNum=$2
printf "Error[%i]: %s\n" ${errNum} "${msg}"
exit 1
}
errMsgDep="Cannot continue due to absence of required dependency"
ID=$(command -v id); [ $? -ne 0 ] && onErr "${errMsgDep}" 1
if [ $($ID -u) -eq 0 ]; then
SUDO=''
else
SUDO=$(command -v sudo); [ $? -ne 0 ] && SUDO=''
fi
DOCKER=$(command -v docker);
[ $? -eq 0 ] || onErr "Please install docker first..." 2
$SUDO $DOCKER version >/dev/null 2>&1
[ $? -ne 0 ] && {
errMsg="$(printf '\n You are not authorized to run docker,')"
errMsg="${errMsg}$(printf '\n try to "su -" into root account and try again.\n\n')"
onErr "${errMsg}" 3
}
cd ./docker
$SUDO $DOCKER build --rm --no-cache=true -t "${DockerImage}" . \
--build-arg URL_SQLITE_SOURCE_ZIP="${SQLITE_ZIP_URL}" \
--build-arg COMPRESS_SQLITE3="${SQLite_compressor}"
cd ..
printf "\n\n===== Taking ready to use static sqlite3 =======================================\n\n"
arch="${SQLITE_ZIP_URL##*/}"
workdir="${arch%.*}"
[ ! -d release ] && mkdir release
$SUDO $DOCKER run --rm -v $(pwd)/release:/release/ \
-it "${DockerImage}" \
cp -fv /app/${workdir}/sqlite3 /release/
cd release
echo "=============================="
ldd sqlite3
echo "------------------------------"
file sqlite3
echo "------------------------------"
echo '.version' | ./sqlite3
echo "=============================="
cd ..
# Cleanup the built image
$SUDO $DOCKER image rm "${DockerImage}" >/dev/null 2>&1