From 02ee161e8172bf9b7f0e1ed410961a298602ce7e Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Thu, 16 May 2013 15:43:32 +0100 Subject: [PATCH] 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 --- elements/base/dib-first-boot | 11 ++++++ .../base/finalise.d/01-install-dib-first-boot | 6 ++++ .../fedora/finalise.d/99-setup-first-boot | 35 +++++++++++++++++++ .../ubuntu/finalise.d/99-setup-first-boot | 21 +++++++++++ lib/img-functions | 20 ----------- 5 files changed, 73 insertions(+), 20 deletions(-) create mode 100755 elements/base/dib-first-boot create mode 100755 elements/base/finalise.d/01-install-dib-first-boot create mode 100755 elements/fedora/finalise.d/99-setup-first-boot create mode 100755 elements/ubuntu/finalise.d/99-setup-first-boot diff --git a/elements/base/dib-first-boot b/elements/base/dib-first-boot new file mode 100755 index 00000000..48a5bab9 --- /dev/null +++ b/elements/base/dib-first-boot @@ -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 diff --git a/elements/base/finalise.d/01-install-dib-first-boot b/elements/base/finalise.d/01-install-dib-first-boot new file mode 100755 index 00000000..39e544d4 --- /dev/null +++ b/elements/base/finalise.d/01-install-dib-first-boot @@ -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 diff --git a/elements/fedora/finalise.d/99-setup-first-boot b/elements/fedora/finalise.d/99-setup-first-boot new file mode 100755 index 00000000..7e787059 --- /dev/null +++ b/elements/fedora/finalise.d/99-setup-first-boot @@ -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 <> $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 diff --git a/elements/ubuntu/finalise.d/99-setup-first-boot b/elements/ubuntu/finalise.d/99-setup-first-boot new file mode 100755 index 00000000..4529d819 --- /dev/null +++ b/elements/ubuntu/finalise.d/99-setup-first-boot @@ -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 <> /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 }