summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile2
-rwxr-xr-xinstall_prepare.sh9
-rw-r--r--modules/unicode/unicode.js20
-rw-r--r--package.json2
4 files changed, 12 insertions, 21 deletions
diff --git a/Dockerfile b/Dockerfile
index b0c51b3..15a5afc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM alpine:3.11 AS builder
+FROM alpine:3.12 AS builder
RUN apk add --no-cache npm g++
diff --git a/install_prepare.sh b/install_prepare.sh
new file mode 100755
index 0000000..2b39985
--- /dev/null
+++ b/install_prepare.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -xeuo pipefail
+
+abbrgen_execname="modules/abbrgen/abbreviation_gen_`uname`"
+test -f "$abbrgen_execname" || \
+ g++ -Wall -Wextra -std=c++11 -O3 -o "$abbrgen_execname" modules/abbrgen/abbreviation_gen.cpp
+
+test -f modules/unicode/UnicodeData.txt || \
+ curl -Ls 'https://www.unicode.org/Public/13.0.0/ucd/UnicodeData.txt' >modules/unicode/UnicodeData.txt
diff --git a/modules/unicode/unicode.js b/modules/unicode/unicode.js
index a937796..4a7f75a 100644
--- a/modules/unicode/unicode.js
+++ b/modules/unicode/unicode.js
@@ -105,25 +105,7 @@ module.exports = function (app, io, moddir) {
if (fs.existsSync(dataFilePath)) {
importDatabase(fs.readFileSync(dataFilePath).toString());
} else {
- console.log("Downloading UnicodeData.txt...");
-
- https.get("https://www.unicode.org/Public/13.0.0/ucd/UnicodeData.txt", res => {
- if (res.statusCode != 200) {
- console.log(`Could not download UnicodeData.txt: status code ${res.statusCode}`);
- return;
- }
-
- res.setEncoding("utf8");
- let buffer = "";
- res.on("data", data => buffer += data);
- res.on("end", () => {
- fs.writeFileSync(dataFilePath, buffer);
- console.log("Downloaded UnicodeData.txt");
- importDatabase(buffer);
- });
- }).on("error", err => {
- console.log("Error downloading UnicodeData.txt:", err);
- });
+ throw new Error("UnicodeData.txt doesn't exist! Be sure to run ./install_prepare.sh");
}
app.get("/unicode", (req, res) => {
diff --git a/package.json b/package.json
index 08b9de9..10573f2 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,7 @@
"url": "https://github.com/tomsmeding/webserver"
},
"scripts": {
- "prepare": "g++ -Wall -Wextra -std=c++11 -O3 -o modules/abbrgen/abbreviation_gen_$(uname) modules/abbrgen/abbreviation_gen.cpp"
+ "prepare": "./install_prepare.sh"
},
"author": "Tom Smeding <tom.smeding@gmail.com> (http://tomsmeding.com)",
"license": "MIT"