core: 网页日志自动刷新并滚动到最底部
This commit is contained in:
parent
9efe2552e3
commit
7443b18467
75
trans.sh
75
trans.sh
@ -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,35 +82,71 @@ 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
|
||||
}
|
||||
# 提取 finalos/extra 到变量
|
||||
for prefix in finalos extra; do
|
||||
while read -r line; do
|
||||
if [ -n "$line" ]; then
|
||||
key=$(echo $line | cut -d= -f1)
|
||||
value=$(echo $line | cut -d= -f2-)
|
||||
eval "$key='$value'"
|
||||
fi
|
||||
done <<EOF
|
||||
|
||||
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
|
||||
if [ -n "$line" ]; then
|
||||
key=$(echo $line | cut -d= -f1)
|
||||
value=$(echo $line | cut -d= -f2-)
|
||||
eval "$key='$value'"
|
||||
fi
|
||||
done <<EOF
|
||||
$(xargs -n1 </proc/cmdline | grep "^$prefix" | sed "s/^$prefix\.//")
|
||||
EOF
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
setup_tty_and_log
|
||||
extract_env_from_cmdline
|
||||
|
||||
# 安装 nginx,目标系统是 alpine 除外
|
||||
# shellcheck disable=SC2154
|
||||
|
Loading…
Reference in New Issue
Block a user