Fixed memory consumption
This commit is contained in:
parent
c01ddf4940
commit
d0a682f1a3
@ -632,17 +632,21 @@ core_update() {
|
|||||||
esac
|
esac
|
||||||
url="$MIHOMO_BASE/mihomo-linux-$arch-$MIHOMO_VERSION.gz"
|
url="$MIHOMO_BASE/mihomo-linux-$arch-$MIHOMO_VERSION.gz"
|
||||||
log "updating mihomo core ${cur:-none} -> $MIHOMO_VERSION"
|
log "updating mihomo core ${cur:-none} -> $MIHOMO_VERSION"
|
||||||
# a failed download keeps the current core: fix/update still start nikki
|
# Streamed straight next to the binary: /tmp is RAM, and the unpacked core
|
||||||
rm -f /tmp/mihomo.gz /tmp/mihomo
|
# (~56 MB) plus the .gz do not fit on small routers. No .bak copy either (flash
|
||||||
if ! curl -fL -o /tmp/mihomo.gz "$url" || ! gunzip -f /tmp/mihomo.gz || ! chmod +x /tmp/mihomo ||
|
# space); an older core comes back with MIHOMO_VERSION in /etc/nikki/kit.env + fix.
|
||||||
[ "$(/tmp/mihomo -v 2>/dev/null | awk '{print $3; exit}')" != "$MIHOMO_VERSION" ]; then
|
# A failed download keeps the current core: fix/update still start nikki.
|
||||||
rm -f /tmp/mihomo.gz /tmp/mihomo
|
bin=$(command -v mihomo || echo /usr/bin/mihomo)
|
||||||
log "warning: core $MIHOMO_VERSION not installed (download or check failed: $url), keeping ${cur:-the current one}"
|
new=$bin.new
|
||||||
|
rm -f "$new" "$bin.bak" /tmp/mihomo.gz /tmp/mihomo
|
||||||
|
if ! curl -fsSL "$url" | gunzip > "$new" || ! chmod +x "$new" ||
|
||||||
|
[ "$("$new" -v 2>/dev/null | awk '{print $3; exit}')" != "$MIHOMO_VERSION" ]; then
|
||||||
|
rm -f "$new"
|
||||||
|
log "warning: core $MIHOMO_VERSION not installed (download, unpack or check failed: $url;" \
|
||||||
|
"free space in ${bin%/*}: $(df -h "${bin%/*}" 2>/dev/null | awk 'NR==2 {print $4}')), keeping ${cur:-the current one}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
bin=$(command -v mihomo || echo /usr/bin/mihomo)
|
mv "$new" "$bin"
|
||||||
[ -f "$bin" ] && cp "$bin" "$bin.bak"
|
|
||||||
mv /tmp/mihomo "$bin"
|
|
||||||
log "core: $(mihomo -v | head -n 1)"
|
log "core: $(mihomo -v | head -n 1)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user