Add storage mode migration: internal NVMe vs USB flash, Settings tab, fix hardcoded /boot/ paths
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
$_myHost = vv_detect_host();
|
||||
$_vars = vv_conf_vars();
|
||||
$_confKey = strtoupper($_myHost) . '_STORAGE_MODE_INTERNAL';
|
||||
$_confVal = $_vars[$_confKey] ?? null;
|
||||
?>
|
||||
<style>
|
||||
.vv-set-card { background:#161616;border:1px solid #2a2a2a;border-radius:6px;padding:14px 16px;margin-bottom:14px; }
|
||||
.vv-set-hdr { font-size:11px;font-weight:700;color:#666;text-transform:uppercase;letter-spacing:.07em;margin-bottom:12px; }
|
||||
.vv-set-row { display:flex;justify-content:space-between;align-items:baseline;gap:8px;margin:4px 0; }
|
||||
.vv-set-lbl { font-size:11px;color:#444; }
|
||||
.vv-set-val { font-size:12px;color:#888;text-align:right;font-family:monospace; }
|
||||
.vv-set-badge { display:inline-block;font-size:10px;padding:2px 8px;border-radius:3px;font-weight:700;letter-spacing:.04em; }
|
||||
.vv-set-badge.internal { background:#0d1f0d;color:#4caf50;border:1px solid #1a3a1a; }
|
||||
.vv-set-badge.flash { background:#1a1200;color:#ffb74d;border:1px solid #3a2800; }
|
||||
.vv-set-badge.custom { background:#0a1a2a;color:#4a9eff;border:1px solid #1a3a5a; }
|
||||
.vv-set-sep { border:none;border-top:1px solid #1e1e1e;margin:10px 0; }
|
||||
.vv-set-btn { background:#1a1a1a;border:1px solid #333;color:#888;font-size:11px;padding:5px 14px;
|
||||
border-radius:3px;cursor:pointer;transition:border-color .15s,color .15s; }
|
||||
.vv-set-btn:hover { border-color:#555;color:#ccc; }
|
||||
.vv-set-btn:disabled { opacity:.4;cursor:default; }
|
||||
.vv-set-btn.primary { background:#1a2a1a;border-color:#2d4a2d;color:#4caf50; }
|
||||
.vv-set-btn.primary:hover { background:#223a22; }
|
||||
.vv-set-btn.warn { background:#1f1500;border-color:#3a2800;color:#ffb74d; }
|
||||
.vv-set-btn.warn:hover { background:#2a1e00; }
|
||||
.vv-set-out { background:#080808;border:1px solid #1a1a1a;border-radius:3px;padding:10px 12px;
|
||||
font-family:monospace;font-size:10px;color:#555;white-space:pre-wrap;word-break:break-all;
|
||||
max-height:320px;overflow-y:auto;margin-top:10px;display:none;
|
||||
scrollbar-width:none; }
|
||||
.vv-set-out::-webkit-scrollbar { display:none; }
|
||||
.vv-set-info { font-size:11px;color:#444;line-height:1.6;margin-bottom:10px; }
|
||||
.vv-set-warn-box { background:#1a1200;border:1px solid #3a2800;border-radius:4px;
|
||||
padding:8px 12px;font-size:11px;color:#ffb74d;margin-top:8px;display:none; }
|
||||
</style>
|
||||
|
||||
<div style="max-width:740px;margin:0 auto;">
|
||||
|
||||
<!-- Storage Location card -->
|
||||
<div class="vv-set-card" id="vv-stor-card">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;">
|
||||
<span class="vv-set-hdr" style="margin-bottom:0;">Storage Location</span>
|
||||
<span id="vv-stor-badge" class="vv-set-badge">…</span>
|
||||
</div>
|
||||
|
||||
<div id="vv-stor-info" style="font-size:11px;color:#3a3a3a;">Loading…</div>
|
||||
|
||||
<hr class="vv-set-sep">
|
||||
|
||||
<div class="vv-set-info">
|
||||
Varaverk stores all scripts, configuration, state files, and the git repository in
|
||||
<code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">SCRIPTS_DIR</code>.
|
||||
<br>
|
||||
<strong style="color:#555;">Internal NVMe/SSD</strong> — direct access, zero write-wear concern, git pull/push from boot volume.<br>
|
||||
<strong style="color:#555;">USB Flash</strong> — preserves flash lifetime. Requires array to be started. git pull syncs
|
||||
<code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">Plugin/</code>
|
||||
back to <code style="font-size:10px;color:#4a7a4a;background:#080808;padding:1px 4px;border-radius:2px;">/boot/</code>
|
||||
after each pull so the webUI always stays current.
|
||||
</div>
|
||||
|
||||
<div id="vv-stor-warn-flash" class="vv-set-warn-box">
|
||||
Array must be started for Varaverk to function in flash mode. The plugin tab is always accessible.
|
||||
</div>
|
||||
<div id="vv-stor-warn-noarray" class="vv-set-warn-box">
|
||||
Array is not started — cannot migrate to flash mode right now. Start the array first.
|
||||
</div>
|
||||
|
||||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px;">
|
||||
<button id="vv-stor-migrate-btn" class="vv-set-btn" onclick="vvStorMigrate()" style="display:none;"></button>
|
||||
<button class="vv-set-btn" onclick="vvStorLoad()" style="font-size:10px;padding:4px 10px;">↻ Refresh</button>
|
||||
<span id="vv-stor-fb" style="font-size:11px;color:#444;"></span>
|
||||
</div>
|
||||
|
||||
<pre class="vv-set-out" id="vv-stor-out"></pre>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var _vvStorData = null;
|
||||
|
||||
function vvStorLoad() {
|
||||
const info = document.getElementById('vv-stor-info');
|
||||
const badge = document.getElementById('vv-stor-badge');
|
||||
if (info) info.textContent = 'Loading…';
|
||||
|
||||
fetch('/plugins/varaverk/api/storage.php?action=status&_=' + Date.now())
|
||||
.then(r => r.json())
|
||||
.then(d => {
|
||||
_vvStorData = d;
|
||||
if (!d.ok) { if (info) info.textContent = 'Error loading status'; return; }
|
||||
_vvStorRender(d);
|
||||
})
|
||||
.catch(() => { if (info) info.textContent = 'Request failed'; });
|
||||
}
|
||||
|
||||
function _vvStorRender(d) {
|
||||
const badge = document.getElementById('vv-stor-badge');
|
||||
const info = document.getElementById('vv-stor-info');
|
||||
const btn = document.getElementById('vv-stor-migrate-btn');
|
||||
const wFlash = document.getElementById('vv-stor-warn-flash');
|
||||
const wArr = document.getElementById('vv-stor-warn-noarray');
|
||||
|
||||
// Badge
|
||||
if (badge) {
|
||||
badge.textContent = d.current_mode.toUpperCase();
|
||||
badge.className = 'vv-set-badge ' + d.current_mode;
|
||||
}
|
||||
|
||||
// Info grid
|
||||
const modeLabel = d.current_mode === 'internal' ? 'Internal NVMe/SSD' : d.current_mode === 'flash' ? 'USB Flash' : 'Custom';
|
||||
const detLabel = d.detected === 'internal' ? 'internal NVMe/SSD' : 'USB flash';
|
||||
const confBadge = d.conf_val === null ? '<span style="color:#3a3a3a;">not set</span>'
|
||||
: d.conf_val === 'true' ? '<span style="color:#4caf50;">true (internal)</span>'
|
||||
: '<span style="color:#ffb74d;">false (flash)</span>';
|
||||
const matchIcon = (d.current_mode === d.detected || d.current_mode === 'custom') ? '' :
|
||||
' <span style="color:#ef5350;">⚠ mismatch with conf</span>';
|
||||
|
||||
if (info) info.innerHTML = `
|
||||
<div style="display:grid;grid-template-columns:auto 1fr;gap:3px 16px;align-items:baseline;">
|
||||
<span style="color:#333;">Mode</span> <span style="color:#888;">${modeLabel}${matchIcon}</span>
|
||||
<span style="color:#333;">SCRIPTS_DIR</span> <code style="font-size:10px;color:#4a7a4a;">${d.current_dir}</code>
|
||||
<span style="color:#333;">Boot device</span> <span style="color:#555;">${d.boot_disk} <span style="color:#2a2a2a;">(${d.transport})</span></span>
|
||||
<span style="color:#333;">Auto-detect</span> <span style="color:#555;">${detLabel}</span>
|
||||
<span style="color:#333;">${d.conf_key}</span> <span>${confBadge}</span>
|
||||
</div>`;
|
||||
|
||||
// Warnings
|
||||
if (wFlash) wFlash.style.display = (d.current_mode !== 'flash' && d.detected === 'usb') ? '' : 'none';
|
||||
if (wArr) wArr.style.display = 'none';
|
||||
|
||||
// Migrate button
|
||||
if (btn) {
|
||||
if (d.current_mode === 'internal') {
|
||||
btn.textContent = 'Migrate to Flash (appdata)';
|
||||
btn.className = 'vv-set-btn warn';
|
||||
btn.dataset.to = 'flash';
|
||||
btn.style.display = '';
|
||||
} else if (d.current_mode === 'flash') {
|
||||
btn.textContent = 'Migrate to Internal (/boot)';
|
||||
btn.className = 'vv-set-btn primary';
|
||||
btn.dataset.to = 'internal';
|
||||
btn.style.display = '';
|
||||
} else {
|
||||
btn.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function vvStorMigrate() {
|
||||
const btn = document.getElementById('vv-stor-migrate-btn');
|
||||
const out = document.getElementById('vv-stor-out');
|
||||
const fb = document.getElementById('vv-stor-fb');
|
||||
const wArr = document.getElementById('vv-stor-warn-noarray');
|
||||
const to = btn?.dataset.to;
|
||||
if (!to) return;
|
||||
|
||||
// Flash guard: array must be started
|
||||
if (to === 'flash' && _vvStorData && !_vvStorData.array_started) {
|
||||
if (wArr) wArr.style.display = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const label = to === 'flash' ? 'Flash (appdata)' : 'Internal (/boot)';
|
||||
if (!confirm(`Migrate Varaverk storage to ${label}?\n\nThis will:\n• Copy all scripts, conf, and git repo to the new location\n• Update varaverk.cfg and master.conf\n• Delete the old location\n\nThe page will need a reload after migration.`)) return;
|
||||
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Migrating…';
|
||||
if (fb) fb.textContent = '';
|
||||
if (out) { out.textContent = 'Starting migration…\n'; out.style.display = ''; }
|
||||
|
||||
const fd = new FormData();
|
||||
fd.append('action', 'migrate');
|
||||
fd.append('to', to);
|
||||
|
||||
fetch('/plugins/varaverk/api/storage.php', { method: 'POST', body: fd })
|
||||
.then(r => r.json())
|
||||
.then(d => {
|
||||
btn.disabled = false;
|
||||
if (out) {
|
||||
out.textContent = d.output || '(no output)';
|
||||
out.scrollTop = out.scrollHeight;
|
||||
}
|
||||
if (d.ok) {
|
||||
btn.textContent = '✓ Done — reload page';
|
||||
btn.className = 'vv-set-btn primary';
|
||||
btn.onclick = () => location.reload();
|
||||
if (fb) { fb.style.color = '#4caf50'; fb.textContent = 'Migration complete — reload to apply'; }
|
||||
} else {
|
||||
btn.textContent = btn.dataset.to === 'flash' ? 'Migrate to Flash (appdata)' : 'Migrate to Internal (/boot)';
|
||||
if (fb) { fb.style.color = '#ef5350'; fb.textContent = 'Migration failed — see output above'; }
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
btn.disabled = false;
|
||||
btn.textContent = btn.dataset.to === 'flash' ? 'Migrate to Flash (appdata)' : 'Migrate to Internal (/boot)';
|
||||
if (fb) { fb.style.color = '#ef5350'; fb.textContent = 'Request failed: ' + e; }
|
||||
});
|
||||
}
|
||||
|
||||
vvStorLoad();
|
||||
</script>
|
||||
Reference in New Issue
Block a user