AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1073618
Accepted
Bil5
Bil5
Asked: 2021-08-06 02:30:17 +0800 CST2021-08-06 02:30:17 +0800 CST 2021-08-06 02:30:17 +0800 CST

在 Debian 无人值守预置安装期间向用户显示消息

  • 772

在late_command无人值守安装的步骤中,我正在运行一个 shell 脚本:

d-i preseed/late_command string in-target /bin/sh -c './execute-script.sh'

当达到 late_command 步骤时,UI(蓝色背景,灰色窗口)显示“正在运行 preseed...”消息:

在此处输入图像描述

我想知道是否有任何方法可以根据execute-script.sh正在做的事情来生动地显示其他消息。

我天真地认为使用带有回声的常规 STDOUT 可以解决问题,但它似乎更复杂。

到目前为止,我的搜索引起了我的注意,debconf但我还没有找到任何方法。

我的脚本的当前版本根据@Andrew 的答案重新调整:

#!/bin/sh

. /usr/share/debconf/confmodule
. "./variables.sh"

logFile="/target${INSTALLATION_LOG_LOCATION}"
templatePath="/target/tmp/deployment_progress_tracker.templates"

cat > "${templatePath}" << 'EOF'
Template: deployment_progress_tracker/progress/fallback
Type: text
Description: ${STEP}...
EOF

debconf-loadtemplate deployment_progress_tracker "${templatePath}"
db_progress START 0 1 deployment_progress_tracker/progress

watchLogs () {
  deploymentDone=false
  while ! $deploymentDone
  do
    if [ -f "${logFile}" ]; then
      step=$(grep -E -o -a -h "Progress-step: .*" "${logFile}" | tail -1 | sed 's/Progress-step: //')
      if [ -z "${step##*$DEPLOYMENT_FINISHED*}" ]; then
        deploymentDone=true
      elif [ -n "${step}" ]; then
        db_subst deployment_progress_tracker/progress/fallback STEP "${step}"
        db_progress INFO deployment_progress_tracker/progress/fallback
      fi
    fi
    sleep 3
  done
}



(
  watchLogs;
  rm -f "${templatePath}";
  db_progress SET 1;
  sleep 1;
  db_progress STOP;
  db_unregister deployment_progress_tracker/progress;
) &

前面的脚本将产生以下结果:

在此处输入图像描述

并返回安装程序菜单(选择完成安装实际上将再次运行预置部分并失败,选择中止不会卸载 ISO 并重新启动,无论如何,我正在尝试自动完成卸载和重新启动):

在此处输入图像描述

debian unattended stdout preseed debconf
  • 1 1 个回答
  • 413 Views

1 个回答

  • Voted
  1. Best Answer
    Andrew Lowther
    2021-08-11T18:24:47+08:002021-08-11T18:24:47+08:00

    您将受到很大限制,debconf并且可能不值得付出努力。我认为您根本无法通过脚本运行来做到这一点in-target。我在 Debian Buster 中使用以下预置代码片段和脚本确实取得了成功。它会更改Running Preseed...显示三次的文本。它会显示

    1. Step A
    2. Step B
    3. Running c...(“后备”选项)

    用于下载和运行脚本的部分预置文件。

    d-i preseed/late_command string \
      wget -P /run http://REDACTED/my_script.sh ; \
      chmod 755 /run/my_script.sh ; \
      /run/my_script.sh
    

    的内容my_script.sh。

    #!/bin/sh
    
    . /usr/share/debconf/confmodule
    
    set -e
    
    # create a templates file with the strings for debconf to display
    cat > /run/my_script.templates << 'EOF'
    Template: my_script/progress/a
    Type: text
    Description: Step A
    
    Template: my_script/progress/b
    Type: text
    Description: Step B
    
    Template: my_script/progress/fallback
    Type: text
    Description: Running ${STEP}...
    EOF
    
    # use the utility to load the generated template file
    debconf-loadtemplate my_script /run/my_script.templates
    
    # pause just to show "Running Preseed..."
    sleep 2
    
    # foreach 3 steps tell debconf which template string to display
    for step in a b c; do
    
        if ! db_progress INFO my_script/progress/$step; then
            db_subst my_script/progress/fallback STEP "$step"
            db_progress INFO my_script/progress/fallback
        fi
    
        case $step in
            "a")
                # run commands or scripts in the installer environment (this uses the sleep command in the installer environment)
                sleep 10
                ;;
            "b")
                # run commands or scripts in the chroot environment (this uses the sleep command from the installed system)
                in-target sleep 10
                ;;
            "c")
                # just another sample step
                sleep 10
                ;;
        esac
    done
    

    生成的脚本和模板文件基于finish-install(debian-installer包)脚本和模板。

    • 2

相关问题

  • 关闭 FTP

  • 如何在同一台电脑上从 putty 连接 debian vmware

  • debian- 文件到包的映射

  • Debian Ubuntu 网络管理器错误 [关闭]

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve