在 Debian 无人值守预安装过程中向用户显示消息

在 Debian 无人值守预安装过程中向用户显示消息

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

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

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

在此处输入图片描述

我想知道是否有任何方法可以根据正在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 并重新启动,无论如何,我试图自动完成卸载和重新启动):

在此处输入图片描述

答案1

您将受到很大限制,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-installdebian-installer包)脚本模板

相关内容