Debian

在 Debian 無人值守預置安裝期間向使用者顯示消息

  • August 17, 2021

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 並重新啟動,無論如何,我正在嘗試自動完成解除安裝和重新啟動):

在此處輸入圖像描述

您將受到很大限制,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包)腳本模板

引用自:https://serverfault.com/questions/1073618