Show Message During Debian Unattended Preseeded Installation – How to Guide

debconfdebianpreseedstdoutunattended

During the late_command step of an unattended installation, I'm running a shell script :

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

When the late_command step is reached, the UI (blue background, grey window) displays a "Running preseed…" message :

enter image description here

I'm wondering if there is any way to lively displaying other messages based on what the execute-script.sh is doing.

I naively thought that using the regular STDOUT with echoes would do the trick but it seems more complicated.

My searches so far brought to my attention a potential use of debconf but I haven't been able to find any way.

Current version of my script reshaped according to @Andrew answer :

#!/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;
) &

The previous script will result in the following :

enter image description here

And leads back to the installer menu (choosing Finish the installation will actually run again the preseeded part and fail, choosing Abort will not unmount the ISO and reboot, anyways, I'm trying to have both the unmounting and the reboot automically done) :

enter image description here

Best Answer

You will be pretty limited by debconf and it may not be worth the effort. I don't think you'll be able to do it at all with a script run in-target. I did have success using the following preseed snippet and script with Debian Buster. It changes the text where Running Preseed... is displayed three times. It will show

  1. Step A
  2. Step B
  3. Running c... (the "fallback" option)

Partial preseed file to download and run a script.

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

Contents of 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

The script and the templates file generated are based on the finish-install (debian-installer package) script and templates.