在late_command
無人值守安裝的步驟中,我正在執行 shell 腳本:
d-i preseed/late_command string in-target /bin/sh -c './execute-script.sh'
當到達 Late_command 步驟時,UI(藍色背景,灰色視窗)顯示「正在執行預置…」訊息:
我想知道是否有任何方法可以根據正在execute-script.sh
執行的操作生動地顯示其他訊息。
我天真地認為使用帶有 echoes 的常規 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
而且可能不值得付出努力。我認為您根本無法通過 script run 來完成此操作in-target
。我確實在 Debian Buster 中成功使用了以下預置片段和腳本。它會更改Running Preseed...
顯示三次的文字。它將顯示
Step A
Step B
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