2

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

Bil5
  • 143
  • 5

1 Answers1

2

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.

Andrew Lowther
  • 231
  • 1
  • 3
  • 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. – Bil5 Aug 11 '21 at 04:43
  • 1
    @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` – Andrew Lowther Aug 11 '21 at 16:05
  • 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? – Bil5 Aug 12 '21 at 08:53
  • 1
    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. – Andrew Lowther Aug 16 '21 at 22:47
  • 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 Aug 17 '21 at 01:54
  • I added the current version of the script I'm trying out in my first comment so we can discuss it. – Bil5 Aug 17 '21 at 02:35
  • 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 – Bil5 Aug 17 '21 at 09:30