Score:1

Showing message to the user during a Debian unattended preseeded installation

tr flag

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

Score:2
es flag

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.

Bil5 avatar
tr flag
Thanks for the great idea, based on it, why the following would not work? `d-i preseed/late_command string /bin/sh logs-observer.sh &; in-target --pass-stdout /bin/sh -c './my-target-script.sh > outputlog'` - `myscript.sh` would echoe the different steps a, b, c... they would be saved to `outputlog` - `logs-observer.sh` would run an infinite loop (until he reads "DONE") and read the last step wrote in the "shared" `outputlog` and update the message accordingly. Of course, the steps would be defined beforehand in `logs-observer.sh`, likewise you did in your `my-script.sh` file.
Andrew Lowther avatar
es flag
@Bil5 that might work but sounds very complicated. I would have the `logs-observer.sh` script call `in-target ./my-target-script.sh` inside of it. `in-target` is simply a script in the installer environment that wraps a command inside some chroot setup. It can be called from your script and does not have to be called directory from `late_command`
Bil5 avatar
tr flag
your suggestion works flawlessly many thanks, however, doing the way you said (`in-target ./my-target-script.sh` and from it calling `/bin/sh logs-observer.sh`), I'm unable to make work any `db_progress INFO` command when calling it directly from the `logs-observer.sh` (having of course sourced `confmodule` & generated the template beforehand). The only way I found, is doing it directly from `my-target-script.sh`, and thus both scripts have to communicate each other and a log file is the only way I found. Any thought?
Andrew Lowther avatar
es flag
I guess it depends how specific you want the UI updates to be. I added to the sample script to show how it can update the UI and then run a command or script. This includes the ability to run a command or script `in-target`. The UI can only be updated again after the command or script finishes.
Bil5 avatar
tr flag
I can confirm that this way works well, and I figured out a way to call every debconf command from the installer script. I'm now facing another tough issue, after I'm done with the script, instead of automatically exiting the installer, ejecting the cdrom and rebooting (as configured in the preseed and successfully tested before debconf stuff), it goes back to the installer menu and doesn't allow to simply reboot without relaunching the installation. I noticed this message in syslog: `Menu item 'finish-install' succeeded but requested to be left Unconfigured`
Bil5 avatar
tr flag
I added the current version of the script I'm trying out in my first comment so we can discuss it.
Bil5 avatar
tr flag
After reflection it might be out of the scope of my initial question, I wanted here to see some messages in the installer, and thanks to your answer it works. It sounds cleaner to create another subject for my new concern. Thank you again. https://serverfault.com/questions/1074794/debian-installer-wont-exit-after-preseeded-installation
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.