make patching more robust. backup original html and patch fresh on every container start.
This commit is contained in:
parent
6a40fe344c
commit
2add5238b8
2 changed files with 19 additions and 14 deletions
|
|
@ -20,9 +20,6 @@ if [ ! -f "$OBSIDIAN_DIR/index.html" ]; then
|
||||||
/tmp/obsidian-pkg/opt/Obsidian/resources/obsidian.asar \
|
/tmp/obsidian-pkg/opt/Obsidian/resources/obsidian.asar \
|
||||||
"$OBSIDIAN_DIR"
|
"$OBSIDIAN_DIR"
|
||||||
|
|
||||||
echo "[ignis] Patching..."
|
|
||||||
node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR"
|
|
||||||
|
|
||||||
rm -rf /tmp/obsidian.deb /tmp/obsidian-deb /tmp/obsidian-pkg
|
rm -rf /tmp/obsidian.deb /tmp/obsidian-deb /tmp/obsidian-pkg
|
||||||
|
|
||||||
echo "[ignis] Obsidian v${OBSIDIAN_VERSION} ready."
|
echo "[ignis] Obsidian v${OBSIDIAN_VERSION} ready."
|
||||||
|
|
@ -30,7 +27,8 @@ else
|
||||||
echo "[ignis] Obsidian already set up."
|
echo "[ignis] Obsidian already set up."
|
||||||
fi
|
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/ignis-ui.js "$OBSIDIAN_DIR/ignis-ui.js"
|
||||||
cp /app/dist/shim-loader.js "$OBSIDIAN_DIR/shim-loader.js"
|
cp /app/dist/shim-loader.js "$OBSIDIAN_DIR/shim-loader.js"
|
||||||
cp /app/images/favicon.png "$OBSIDIAN_DIR/favicon.png"
|
cp /app/images/favicon.png "$OBSIDIAN_DIR/favicon.png"
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,21 @@ if (!asarDir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function patchHtml(filePath) {
|
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}`);
|
console.warn(`[patch] Skipping (not found): ${filePath}`);
|
||||||
return;
|
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");
|
let html = fs.readFileSync(filePath, "utf-8");
|
||||||
|
|
||||||
// Remove CSP meta tag
|
// Remove CSP meta tag
|
||||||
|
|
@ -27,18 +37,15 @@ function patchHtml(filePath) {
|
||||||
"\n",
|
"\n",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Inject favicon into <head>
|
// Inject ignis assets before the first <script> tag
|
||||||
html = html.replace(
|
const ignisBlock =
|
||||||
"</head>",
|
' <link rel="icon" type="image/png" href="favicon.png">\n' +
|
||||||
' <link rel="icon" type="image/png" href="favicon.png">\n</head>',
|
' <script type="text/javascript" src="ignis-ui.js"></script>\n' +
|
||||||
);
|
' <script type="text/javascript" src="shim-loader.js"></script>\n';
|
||||||
|
|
||||||
// Inject ignis-ui and shim-loader before the first <script> tag
|
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
'<script type="text/javascript"',
|
'<script type="text/javascript"',
|
||||||
'<script type="text/javascript" src="ignis-ui.js"></script>\n' +
|
ignisBlock + '<script type="text/javascript"',
|
||||||
'<script type="text/javascript" src="shim-loader.js"></script>\n' +
|
|
||||||
'<script type="text/javascript"',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
fs.writeFileSync(filePath, html);
|
fs.writeFileSync(filePath, html);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue