44 línte
1.1 KiB
Bash
44 línte
1.1 KiB
Bash
#!/bin/sh
|
|
# fix-shared-js.sh — sostituisce la funzione getServerBaseUrl con window.location.origin
|
|
|
|
set -e
|
|
|
|
TARGET="/usr/local/share/lemonade-server/resources/static/js/shared.js"
|
|
TMP="$(mktemp)"
|
|
|
|
if [ ! -f "$TARGET" ]; then
|
|
echo "File non trovato: $TARGET"
|
|
exit 1
|
|
fi
|
|
|
|
# Copia il file in un temporaneo
|
|
cp "$TARGET" "$TMP"
|
|
|
|
# Rimuove il blocco della funzione esistente (apertura fino alla chiusura })
|
|
# e inserisce la nuova definizione. Usa awk per gestire blocchi multi-linea.
|
|
awk '
|
|
BEGIN { skip=0 }
|
|
/function[[:space:]]+getServerBaseUrl[[:space:]]*\(/ {
|
|
skip=1
|
|
next
|
|
}
|
|
skip==1 {
|
|
# cerca la chiusura della funzione (prima graffa singola a fine riga)
|
|
if ($0 ~ /^}/) {
|
|
skip=0
|
|
# inserisce la nuova funzione al posto di quella rimossa
|
|
print "function getServerBaseUrl() { return window.location.origin; }"
|
|
}
|
|
next
|
|
}
|
|
{ print }
|
|
' "$TMP" > "$TARGET"
|
|
|
|
# Verifica che la nuova funzione sia presente
|
|
if grep -q 'function getServerBaseUrl() { return window.location.origin; }' "$TARGET"; then
|
|
echo "Patch applicata con successo."
|
|
else
|
|
echo "Patch non riuscita: la nuova funzione non è stata trovata."
|
|
exit 1
|
|
fi
|