#!/bin/bash # Executed by init script INITHOOKS_DEFAULT=/etc/default/inithooks . $INITHOOKS_DEFAULT if [ ! $FORCE_INTERACTIVE ]; then # redirect stdout/stderr when running on an hvc0 console (e.g. Amazon EC2) if grep -qs console=hvc0 /proc/cmdline; then LOGFILE=/var/log/inithooks.log touch $LOGFILE; chmod 640 $LOGFILE echo "Redirecting output to $LOGFILE" exec > >(tee $LOGFILE|logger -t hvc0 -s 2>/dev/console) 2>&1 fi fi exec_scripts() { SCRIPT_DIR=$1 [ -d $SCRIPT_DIR ] || return 0 for SCRIPT in $(find $SCRIPT_DIR -type f | sort); do [ -e $INITHOOKS_CONF ] && . $INITHOOKS_CONF [ -x $SCRIPT ] || continue $SCRIPT done return 0 } set_firstboot_status() { STATUS=$1 sed -i "s|RUN_FIRSTBOOT=\(.*\)|RUN_FIRSTBOOT=$STATUS|" $INITHOOKS_DEFAULT } [ -e $INITHOOKS_CONF ] && . $INITHOOKS_CONF export INITHOOKS_CONF=$INITHOOKS_CONF if [ "$(echo $RUN_FIRSTBOOT | tr [A-Z] [a-z] )" = "true" ]; then exec_scripts $INITHOOKS_PATH/firstboot.d set_firstboot_status false fi exec_scripts $INITHOOKS_PATH/everyboot.d exit 0