Ubuntu – Debian/Ubuntu set preseed mirror variable via early/run command

debianpreseedUbuntu

I need to know how can I add this to preseeding via d-i early/command or d-i preseed/run to set my mirror inside preseed.cfg from /proc/cmdline argument.

If I do:

d-i preseed/run string ws/ubuntu.sh

#!/bin/sh
     for x in `cat /proc/cmdline`; do
             case $x in RPHOST*)
                     eval $x

                     d-i mirror/http/hostname string ${RPHOST}
                     d-i mirror/http/mirror string ${RPHOST}
                     d-i apt-setup/security_host string ${RPHOST}
                     ;;
             esac; 
done

it fails.

It works well in the CentOS kickstart %pre section but i have no clue how to do it via debian/ubuntu preseeding.

Best Answer

after some research on debconf i came up with this solution:

in your preseed.cfg you call the script via:

d-i preseed/run string ws/ubuntu.sh    // subdir from preseed file location

content of ubuntu.sh:

#!/bin/sh
echo "Start ubuntu.sh runscript" >> /var/log/syslog
for x in `cat /proc/cmdline`; do
        case $x in RPHOST*)
                eval $x
                HOST=$RPHOST
                echo "d-i mirror/http/hostname string ${HOST}" > /tmp/mirror.cfg
                echo "d-i mirror/http/mirror string ${HOST}" >> /tmp/mirror.cfg
                echo "d-i apt-setup/security_host string ${HOST}" >> /tmp/mirror.cfg
                ;;
        esac;
done
// add´s values to /var/lib/cdebconf/question.dat
debconf-set-selections /tmp/mirror.cfg

works good @ 12.04.2 LTS !