From 2add5238b82991b6edec0a9fb48b4ab76119533f Mon Sep 17 00:00:00 2001 From: Nystik <236107-Nystik@users.noreply.gitlab.com> Date: Thu, 19 Mar 2026 16:23:04 +0100 Subject: [PATCH] make patching more robust. backup original html and patch fresh on every container start. --- scripts/entrypoint.sh | 6 ++---- scripts/patch-obsidian.js | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index ad4932e..d96bb28 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -20,9 +20,6 @@ if [ ! -f "$OBSIDIAN_DIR/index.html" ]; then /tmp/obsidian-pkg/opt/Obsidian/resources/obsidian.asar \ "$OBSIDIAN_DIR" - echo "[ignis] Patching..." - node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR" - rm -rf /tmp/obsidian.deb /tmp/obsidian-deb /tmp/obsidian-pkg echo "[ignis] Obsidian v${OBSIDIAN_VERSION} ready." @@ -30,7 +27,8 @@ else echo "[ignis] Obsidian already set up." fi -# Always copy latest bundles (they may have been updated between rebuilds) +# Always patch and copy latest bundles (they may have been updated between rebuilds) +node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR" cp /app/dist/ignis-ui.js "$OBSIDIAN_DIR/ignis-ui.js" cp /app/dist/shim-loader.js "$OBSIDIAN_DIR/shim-loader.js" cp /app/images/favicon.png "$OBSIDIAN_DIR/favicon.png" diff --git a/scripts/patch-obsidian.js b/scripts/patch-obsidian.js index e7dddc9..8d6dc75 100644 --- a/scripts/patch-obsidian.js +++ b/scripts/patch-obsidian.js @@ -14,11 +14,21 @@ if (!asarDir) { } function patchHtml(filePath) { - if (!fs.existsSync(filePath)) { + const backupPath = filePath + ".orig"; + + if (!fs.existsSync(filePath) && !fs.existsSync(backupPath)) { console.warn(`[patch] Skipping (not found): ${filePath}`); return; } + // Create backup of the original on first patch; restore from it on subsequent runs + if (!fs.existsSync(backupPath)) { + fs.copyFileSync(filePath, backupPath); + console.log(`[patch] Backed up original: ${backupPath}`); + } else { + fs.copyFileSync(backupPath, filePath); + } + let html = fs.readFileSync(filePath, "utf-8"); // Remove CSP meta tag @@ -27,18 +37,15 @@ function patchHtml(filePath) { "\n", ); - // Inject favicon into - html = html.replace( - "", - ' \n', - ); + // Inject ignis assets before the first \n' + + ' \n'; - // Inject ignis-ui and shim-loader before the first \n' + - '\n' + - '