core: 网页日志自动刷新并滚动到最底部

This commit is contained in:
bin456789 2023-07-09 00:04:18 +08:00
parent 9efe2552e3
commit 7443b18467
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -5,15 +5,6 @@
# 命令出错终止运行,将进入到登录界面,防止失联
set -eE
# 显示输出到前台
# 似乎script更优雅但 alpine 不带 script 命令
# script -f /dev/tty0
if [ -e /dev/ttyS0 ]; then
exec > >(tee /dev/tty0 /dev/ttyS0 /reinstall.log) 2>&1
else
exec > >(tee /dev/tty0 /reinstall.log) 2>&1
fi
trap 'error line $LINENO return $?' ERR
catch() {
@ -91,23 +82,55 @@ setup_nginx() {
server {
listen 80 default_server;
listen [::]:80 default_server;
location = / {
root /;
try_files /reinstall.log /reinstall.log;
types {
text/plain log;
}
try_files /reinstall.html /reinstall.html;
# types {
# text/plain log;
# }
}
}
EOF
# rc-service nginx start
nginx
}
setup_lighttpd() {
apk add lighttpd
ln -sf /reinstall.log /var/www/localhost/htdocs/index.html
ln -sf /reinstall.html /var/www/localhost/htdocs/index.html
rc-service lighttpd start
}
setup_tty_and_log() {
cat <<EOF >/reinstall.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="2">
</head>
<body>
<script>
window.onload = function() {
// history.scrollRestoration = "manual";
window.scrollTo(0, document.body.scrollHeight);
}
</script>
<pre>
EOF
# 显示输出到前台
# 似乎script更优雅但 alpine 不带 script 命令
# script -f /dev/tty0
if [ -e /dev/ttyS0 ]; then
exec > >(tee -a /dev/tty0 /dev/ttyS0 /reinstall.html) 2>&1
else
exec > >(tee -a /dev/tty0 /reinstall.html) 2>&1
fi
}
extract_env_from_cmdline() {
# 提取 finalos/extra 到变量
for prefix in finalos extra; do
while read -r line; do
@ -120,6 +143,10 @@ for prefix in finalos extra; do
$(xargs -n1 </proc/cmdline | grep "^$prefix" | sed "s/^$prefix\.//")
EOF
done
}
setup_tty_and_log
extract_env_from_cmdline
# 安装 nginx目标系统是 alpine 除外
# shellcheck disable=SC2154