diff --git a/files/www/cgi-bin/owrt-full-backup b/files/www/cgi-bin/owrt-full-backup index 1d25846..99c66a2 100644 --- a/files/www/cgi-bin/owrt-full-backup +++ b/files/www/cgi-bin/owrt-full-backup @@ -138,6 +138,19 @@ job_file() { printf '%s/%s.%s' "$JOB_DIR" "$1" "$2" } +format_seconds() { + local seconds minutes rest + seconds="$1" + case "$seconds" in ''|*[!0-9]*) seconds=0 ;; esac + minutes="$((seconds / 60))" + rest="$((seconds % 60))" + if [ "$minutes" -gt 0 ]; then + printf '%s мин %s сек' "$minutes" "$rest" + else + printf '%s сек' "$rest" + fi +} + download_file() { local file base file="$(param file)" @@ -263,12 +276,13 @@ echo "Старт: \$(date)" echo "Создание бэкапа запущено." $cmd code="\$?" -echo "Код выхода: \$code" echo "\$code" > "$(job_file "$id" code)" date +%s > "$(job_file "$id" finished)" if [ "\$code" = "0" ]; then + echo "Готово." echo done > "$status" else + echo "Ошибка: код выхода \$code" echo failed > "$status" fi rm -f "$script" @@ -463,7 +477,7 @@ backup_rows() { } render_job_panel() { - local id status meta log code_file started now elapsed title state_class state_text job_note button_text + local id status meta log code_file finished_file started finished now elapsed elapsed_text title state_class state_text job_note button_text code estimate_text id="$1" valid_job_id "$id" || return @@ -471,24 +485,36 @@ render_job_panel() { meta="$(job_file "$id" meta)" log="$(job_file "$id" log)" code_file="$(job_file "$id" code)" + finished_file="$(job_file "$id" finished)" started="$(sed -n 's/^started=//p' "$meta" 2>/dev/null | sed -n '1p')" title="$(sed -n 's/^title=//p' "$meta" 2>/dev/null | sed -n '1p')" + code="$(cat "$code_file" 2>/dev/null | sed -n '1p')" + finished="$(cat "$finished_file" 2>/dev/null | sed -n '1p')" [ -n "$title" ] || title="Создание бэкапа" case "$started" in ''|*[!0-9]*) started="$(date +%s)" ;; esac now="$(date +%s)" + if [ "$status" != "running" ]; then + case "$finished" in + ''|*[!0-9]*) ;; + *) [ "$finished" -ge "$started" ] 2>/dev/null && now="$finished" ;; + esac + fi elapsed="$((now - started))" + elapsed_text="$(format_seconds "$elapsed")" + estimate_text="" case "$status" in running) state_class="running" state_text="Выполняется" - job_note="Страница обновляется каждые 2 секунды. После завершения список архивов ниже обновится автоматически." + estimate_text=" · Примерно: 1-3 мин" + job_note="Страница обновляется каждые 2 секунды. Время примерное: большой overlay, ROM или медленная флешка могут идти дольше." button_text="Обновить лог" ;; done) state_class="ok" state_text="Завершено" - job_note="Готово. Список архивов ниже уже обновлен." + job_note="Готово. Архив уже появился в списке ниже." button_text="Обновить список" ;; failed) @@ -506,20 +532,22 @@ render_job_panel() { esac printf '
' "$state_class" - printf '

%s

Статус: %s · Время: %s сек' "$(h "$title")" "$(h "$state_text")" "$(h "$started")" "$(h "$elapsed")" - if [ -r "$code_file" ]; then - printf ' · Код выхода: %s' "$(h "$(cat "$code_file")")" + printf '

%s

Статус: %s · Время: %s%s' "$(h "$title")" "$(h "$state_text")" "$(h "$started")" "$(h "$elapsed_text")" "$(h "$estimate_text")" + if [ -n "$code" ] && [ "$code" != "0" ]; then + printf ' · Код ошибки: %s' "$(h "$code")" fi printf '

%s
' "$(self_url)" "$(h "$(param key)")" "$button_text" printf '

%s

Журнал выполнения
' "$(h "$job_note")" printf '
'
 	if [ -r "$log" ]; then
-		tail -n 120 "$log" | html_escape
+		tail -n 120 "$log" | sed 's/^Код выхода: 0$/Готово./' | html_escape
 	else
 		printf 'Лог пока пуст. Подожди пару секунд.\n' | html_escape
 	fi
 	printf '
' - printf '' + if [ "$status" = "running" ]; then + printf '' + fi printf '
' } @@ -558,7 +586,7 @@ $refresh_meta @media (prefers-color-scheme: dark) { :root { --bg: #111418; --panel: #181d23; --text: #eef2f6; --muted: #a6b0bf; --line: #2d3642; --accent: #6aa4ff; --bad: #ff9b91; --ok: #7ee0a3; } } * { box-sizing: border-box; } body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; } -main { max-width: 1180px; margin: 0 auto; padding: 18px; display: grid; gap: 14px; } +main { max-width: 1280px; margin: 0 auto; padding: 18px; display: grid; gap: 14px; } h1 { margin: 0; font-size: 22px; } h2 { margin: 0 0 12px; font-size: 16px; } p { margin: 6px 0; color: var(--muted); } @@ -588,6 +616,8 @@ button, .button { display: inline-flex; align-items: center; justify-content: ce .result-output, .console { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; } .console { max-height: 340px; } .console-title { margin: 12px 0 6px; font-weight: 700; } +.device-card, .create-card { min-width: 0; } +.device-disk { white-space: pre; font-size: 12px; } code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } pre { overflow: auto; background: rgba(127,127,127,.12); border-radius: 6px; padding: 10px; } table { width: 100%; border-collapse: collapse; } @@ -632,17 +662,17 @@ EOF cat < -
+

Устройство

Имя: $(h "$(system_value host)") Версия: $(h "$(system_value release)") Плата: $(h "$(system_value board)")
-
$(df -h 2>/dev/null | html_escape)
+
$(df -h 2>/dev/null | html_escape)
-
+

Создать бэкап