Refactor the first boot routine.

Setting up a routine to run at first time the system boot may vary from
distribution to distribution. This patch will remove the logic from the
diskimage-builder code and put it into the elements.

The base element will now deploy a dib-first-boot script and each OS
element will ensure that this script runs at rc.local time. By doing
that we will put the OS specific stuff in the OS elements and remove
the embedded code out of the img-function file.

Change-Id: I24c5d1b1185de5693f145347fe912245f1ba7dfe
This commit is contained in:
Lucas Alvares Gomes 2013-05-16 15:43:32 +01:00
parent 7e0fe78cf2
commit 02ee161e81
5 changed files with 73 additions and 20 deletions

11
elements/base/dib-first-boot Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
set -o xtrace
touch /var/log/first-boot.d.log
chmod 0600 /var/log/first-boot.d.log
run-parts /etc/first-boot.d >> /var/log/first-boot.d.log 2>&1
rm -fr /etc/first-boot.d
# delete itself
rm $0

View File

@ -0,0 +1,6 @@
#!/bin/bash
set -e
if [ -d /etc/first-boot.d ]; then
install -m 0755 -o root -g root $(dirname $0)/../dib-first-boot /usr/sbin/
fi

View File

@ -0,0 +1,35 @@
#!/bin/bash
set -e
if [ -d /etc/first-boot.d ]; then
rc_local=/etc/rc.d/rc.local
FILE_EXISTED=
if [ -f $rc_local ]
then
FILE_EXISTED=1
mv $rc_local $rc_local.REAL
fi
dd of=$rc_local <<EOF
#!/bin/bash
set -e
set -o xtrace
dib-first-boot
EOF
if [ $FILE_EXISTED ]
then
echo "mv $rc_local.REAL $rc_local" >> $rc_local
else
echo "rm \$0" >> $rc_local
fi
echo "exit 0" >> $rc_local
chmod 755 $rc_local
# Enable the service
systemctl enable rc-local.service
fi

View File

@ -0,0 +1,21 @@
#!/bin/bash
set -e
if [ -d /etc/first-boot.d ]; then
rc_local=/etc/rc.local
mv $rc_local $rc_local.REAL
dd of=$rc_local <<EOF
#!/bin/bash
set -e
set -o xtrace
dib-first-boot
mv $rc_local.REAL $rc_local
exit 0
EOF
chmod 755 $rc_local
fi

View File

@ -129,26 +129,6 @@ function prepare_first_boot () {
check_break before-first-boot run_in_target bash
if [ -d ${TMP_HOOKS_PATH}/first-boot.d ] ; then
sudo cp -t $TMP_MOUNT_PATH/etc/ -a $TMP_HOOKS_PATH/first-boot.d
if [ -f $TMP_MOUNT_PATH/etc/rc.local ] ; then
run_in_target mv /etc/rc.local /etc/rc.local.REAL
fi
sudo dd of=$TMP_MOUNT_PATH/etc/rc.local <<EOF
#!/bin/bash
set -e
set -o xtrace
touch /var/log/first-boot.d.log
chmod 0600 /var/log/first-boot.d.log
run-parts /etc/first-boot.d >> /var/log/first-boot.d.log 2>&1
rm -fr /etc/first-boot.d
rm -f /etc/rc.local
if [ -f /etc/rc.local.REAL ] ; then
mv /etc/rc.local.REAL /etc/rc.local
fi
exit 0
EOF
run_in_target chmod 755 /etc/rc.local
fi
check_break after-first-boot run_in_target bash
}