Merge "Refactor the first boot routine."

This commit is contained in:
Jenkins 2013-05-20 18:38:45 +00:00 committed by Gerrit Code Review
commit 495381c2f5
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
}