packages/uptime-kuma: add overrides and patches

This commit is contained in:
Max Headroom 2022-04-27 21:00:56 +02:00
parent 77c33ddba7
commit f7f961dde8
4 changed files with 94 additions and 0 deletions

View file

@ -54,4 +54,43 @@ in
--set NODE_PATH "$out/lib/node_modules/ghost/node_modules"
'';
};
puppeteer.dummy-build = {
# HACK: doesn't build, but we don't need it anywhere
configurePhase = "exit 0";
};
uptime-kuma.runtime-bugfixes = {
patches = [
./uptime-kuma/log-in-data-dir.patch
./uptime-kuma/chmod-database.patch
./uptime-kuma/data-dir-concat-with-slash.patch
];
};
uptime-kuma.build = {
# HACK: rollup.js is garbage and expects the contents of node_modules to not be symlinks
# obey its wishes by copying dependencies into place
preBuild = ''
cp -r node_modules $NIX_BUILD_TOP/node_modules_saved
find node_modules node_modules/@* -maxdepth 1 -type l -exec \
bash -c 'LOC=$(readlink -f {}); echo unsymlinking: {}; rm {}; cp -r $LOC {}' \;
chmod +w -R node_modules
find node_modules -mindepth 2 -name node_modules | xargs rm -rf
'';
preInstall = ''
echo restoring original node_modules directory
rm -rf node_modules
mv $NIX_BUILD_TOP/node_modules_saved node_modules
'';
postInstall = ''
makeWrapper $(command -v node) $out/bin/uptime-kuma \
--add-flags "server/server.js" \
--run "cd $out/lib/node_modules/uptime-kuma" \
--set NODE_PATH "$out/lib/node_modules/uptime-kuma/node_modules"
'';
};
}

View file

@ -0,0 +1,12 @@
diff --git a/server/server.js b/server/server.js
index 73ea3f5..31b8028 100644
--- a/server/server.js
+++ b/server/server.js
@@ -1541,6 +1541,7 @@ async function initDatabase(testMode = false) {
if (! fs.existsSync(Database.path)) {
log.info("server", "Copying Database");
fs.copyFileSync(Database.templatePath, Database.path);
+ fs.chmodSync(Database.path, 0o600);
}
log.info("server", "Connecting to the Database");

View file

@ -0,0 +1,30 @@
diff --git a/server/database.js b/server/database.js
index b17e7f4..7b77f84 100644
--- a/server/database.js
+++ b/server/database.js
@@ -74,13 +74,13 @@ class Database {
*/
static init(args) {
// Data Directory (must be end with "/")
- Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
- Database.path = Database.dataDir + "kuma.db";
+ Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data";
+ Database.path = Database.dataDir + "/kuma.db";
if (! fs.existsSync(Database.dataDir)) {
fs.mkdirSync(Database.dataDir, { recursive: true });
}
- Database.uploadDir = Database.dataDir + "upload/";
+ Database.uploadDir = Database.dataDir + "/upload/";
if (! fs.existsSync(Database.uploadDir)) {
fs.mkdirSync(Database.uploadDir, { recursive: true });
@@ -429,7 +429,7 @@ class Database {
static backup(version) {
if (! this.backupPath) {
log.info("db", "Backing up the database");
- this.backupPath = this.dataDir + "kuma.db.bak" + version;
+ this.backupPath = this.dataDir + "/kuma.db.bak" + version;
fs.copyFileSync(Database.path, this.backupPath);
const shmPath = Database.path + "-shm";

View file

@ -0,0 +1,13 @@
diff --git a/server/util-server.js b/server/util-server.js
index 39a2d90..ecb404a 100644
--- a/server/util-server.js
+++ b/server/util-server.js
@@ -528,7 +528,7 @@ exports.convertToUTF8 = (body) => {
let logFile;
try {
- logFile = fs.createWriteStream("./data/error.log", {
+ logFile = fs.createWriteStream((process.env.DATA_DIR || ".") + "/error.log", {
flags: "a"
});
} catch (_) { }