#!/bin/bash
# Init file for ASL firstboot
# Description: This detects if an ASL kernel is running on the system, and if
#	       so, sets it as default.
# chkconfig: 35 99 95
# config: /etc/sysconfig/asl-firstboot

# source function library
. /etc/rc.d/init.d/functions

# source asl config
. /etc/sysconfig/asl-firstboot
. /var/asl/lib/functions

get_distro


case "$1" in
	start)
		# If its off, exit
		if [ ! -f /etc/sysconfig/asl-firstboot ]; then
			exit 0
		fi

		if [ "$ASL_FIRSTBOOT" == "no" ]; then
			exit 0
		fi


		# check network
		for device in `/sbin/ifconfig -a | awk '/eth|ath/ {print $1}'`; do
                  if [ -f /asl-install-network-info ]; then
		    if grep -q $device /asl-install-network-info; then
			if [ "$DIST" == "el7" ]; then
				/usr/sbin/grub2-set-default 0
				/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
			else
				/usr/bin/perl -p -i -e "s/^default.*/default=0/" /boot/grub/grub.conf
			fi
			/sbin/chkconfig asl-firstboot off
			rm -f /asl-install-network-info
		    else
		      	# Diag
                      	/bin/dmesg  > /var/asl/tmp/kernel-diag
                      	/sbin/ifconfig -a >> /var/asl/tmp/kernel-diag

			# disable firstboot
			/sbin/chkconfig asl-firstboot off

                      	# reboot
                      	reboot
		    fi
                  fi
		done

		exit 0

		;;

	stop)
		exit 0
		;;
	*)
		echo $"Usage: $0 {start|stop}"
		exit 3
		;;
esac


# remove from chkconfig
