core: 添加 http 显示安装日志

This commit is contained in:
bin456789 2023-07-08 16:02:06 +08:00
parent 2783f0ce5e
commit 9dfc148295
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -1,16 +1,19 @@
#!/bin/ash
# shellcheck shell=dash
# shellcheck disable=SC3047,SC3036,SC3010
# shellcheck disable=SC3047,SC3036,SC3010,SC3001
# alpine 默认使用 busybox ash
# 命令出错退出脚本,进入到登录界面,防止失联
# TODO: neet more test
# 命令出错终止运行,将进入到登录界面,防止失联
set -eE
# 显示输出到前台
# 似乎script更优雅但 alpine 不带 script 命令
# script -f/dev/tty0
exec >/dev/tty0 2>&1
# 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() {
@ -22,7 +25,8 @@ catch() {
error() {
color='\e[31m'
plain='\e[0m'
echo -e "${color}Error: $*$plain"
echo -e "${color}Error: $*${plain}"
wall "Error: $*"
}
add_community_repo() {
@ -81,6 +85,29 @@ is_efi() {
[ -d /sys/firmware/efi/ ]
}
setup_nginx() {
apk add nginx
cat <<EOF >/etc/nginx/http.d/default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
location = / {
root /;
try_files /reinstall.log /reinstall.log;
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
rc-service lighttpd start
}
# 提取 finalos/extra 到变量
for prefix in finalos extra; do
while read -r line; do
@ -94,6 +121,18 @@ $(xargs -n1 </proc/cmdline | grep "^$prefix" | sed "s/^$prefix\.//")
EOF
done
# 安装 nginx目标系统是 alpine 除外
# shellcheck disable=SC2154
if [ "$distro" != "alpine" ]; then
total_ram=$(free -m | awk '{print $2}' | sed -n '2p')
# 避免后面没内存安装程序谨慎起见512内存才安装
if [ $total_ram -gt 400 ]; then
# lighttpd 虽然运行占用内存少,但安装占用空间大
# setup_lighttpd
setup_nginx
fi
fi
# 找到主硬盘
# alpine 不自带lsblkliveos安装的软件也会被带到新系统所以不用lsblk
# xda=$(lsblk -dn -o NAME | grep -E 'nvme0n1|.da')