#!/bin/sh
# Kiran Kamity, 05/11/2004
# Sreen Tallam, 04/04/2008
# Sreen Tallam, 08/07/2008
# Any Netapp additions to the initial sequence of events that must run on
# the RLM go in this file
# Example: Adding user 'admin', etc...

case "$1" in
	start|"")

		#Change Serial port baudrate
		stty -F /dev/ttyS1 115200

		# create NetApp proc fs entries
		insmod /usr/local/module/procfsfile.ko

		# Change permisions of these directories
		chmod 755 /usr/bin
		chmod 755 /usr/lib
		chmod 755 /usr/sbin

        chmod +t /tmp
		chmod 755 /etc/
		chmod 755 /bin/
		chmod 755 /sbin/
		chmod 755 /var/
		chmod 755 /var/log/messages
		chmod 777 /mnt/logs/debug_logs
		chmod 777 /mnt/logs/debug_logs.1

		# Create these two files for logging users
		touch /var/run/utmp
		touch /var/log/wtmp

		# Create this file to keep notification sent to OnTap
		touch /var/run/notification
		# Create file for saving expander version
		touch /tmp/sas_version; chmod 666 /tmp/sas_version

		# Extract CLI help files from hlp.tgz.
		/bin/tar zxf /usr/local/hlp/hlp.tgz -C /usr/local/hlp
		if [ $? -ne 0 ]; then 
			echo "Error extracting help files for CLI" >> /var/log/messages
        fi

		# Starting the seld
		/usr/local/bin/seld

		# Starting the pktd_reader and pktd_writer	
		/usr/local/bin/pktd_reader 
		/usr/local/bin/pktd_writer 

		# Starting the selpktd
		/usr/local/bin/selpktd

		# Starting the isvcd
		/usr/local/bin/isvcd

		# Starting the console logger
		/usr/local/bin/consoled_logger

		# Starting the eventfifod
		/usr/local/bin/eventfifod

		# Starting the orftp daemons
		/usr/local/bin/orftp_sender
		/usr/local/bin/orftp_rcvr
		/usr/local/bin/fud_sp

		# Starting the trap daemon
		/usr/local/bin/trapd
	
		/usr/local/bin/configd

		# Starting the loopd
		/usr/local/bin/loopd

		# Starting the downbeat
		/usr/local/bin/f2rbeat

		# Starting the upbeat
		/usr/local/bin/r2fbeat

		# Starting the eventd
		/usr/local/bin/eventd
		
		# Starting the linkd
		/usr/local/bin/linkd

		# Starting the asupd
		/usr/local/bin/asupd

		# Starting passwd_auth
		/usr/local/bin/passwd_auth

		# Starting notification daemon
		/usr/local/bin/notifd

		# Starting resource monitor daemon
		/usr/local/bin/resource_monitor
		# Starting Switch API daemon
		/usr/local/bin/swapi_server

		# Starting Forensics API daemon
		/usr/local/bin/ontap_forensics

		# Starting splogd daemon
		/usr/local/bin/splogd

		# Starting Service Processor Command Server
		/usr/local/bin/spcs

		# Just in case Ontap does not boot yet
		touch /mnt/logs/etc/rlm_config_from_filer

		# Check for NetApp FRU access failure during boot
		# Rescan FRU if needed
		case `cat /var/run/platform` in
                	Absolut|Carnegie)
				/etc/init.d/fru_rescan.sh&
				;;
			*)
				;;
		esac

		# Try to fix the battery FC-MTO flag
		if [ -f "/var/run/Vespa" ]  || [ -f "/var/run/Helix" ] || [ -f "/var/run/Zuma" ]  ; then
			/usr/local/bin/batTool fixFCMTO
		fi

		# Initiating Auto update of battery firmware for Carnegie
		if [ -f "/var/run/Carnegie" ] ; then
			/etc/init.d/bat_update_bg.sh&
		fi
		
		# Enabling root login & priv test for Golden RLM
		# Golden RLM has /mnt/logs/var/RLM_debugmode present
		if [ -f "/mnt/logs/var/RLM_debugmode" ] || [ -e "/var/run/netboot_fw" ] ; then
			sleep 10
			/usr/local/bin/set_debugmode.sh
		fi

		if [ ! -f "/mnt/logs/etc/auth_keys" ] ; then
			touch /mnt/logs/etc/auth_keys
			chmod 644 /mnt/logs/etc/auth_keys
		fi

		current_boot_image=`/usr/local/bin/fw_printenv | grep image= | sed 's/image=//g'`;
		echo "Booting from" $current_boot_image
		version=$(/usr/local/bin/version.sh -e -r)
		echo "Current version: " $version
		sel_entry="Running $current_boot_image version $version"
		sel_entry=${sel_entry:0:45}
		/usr/local/bin/sel_logger "SP.notice" "$sel_entry"

		# Notify Ontap that the SP is up
		/usr/local/bin/run_cmd_when_ipmi_ready.sh "/usr/local/bin/notify 4" 30 &
		;;
	stop)
            ;;  
        *)
	    echo "Usage: local {start|stop}" >&2
	    exit 1
	    ;; 
esac
