#!/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|"")


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

		# To allow NFS mounts to work and as well as fud_eth
		# functionality to work, we are doing the below workaround
		rm -f /bin/mount
		cd /bin
		ln -s busybox mount	
		# Return back to the original directory
		cd /

		# install the ECC handler
		insmod /usr/local/module/ecc.ko

		# Loading the agent driver module
		insmod /usr/local/module/agentdrv.ko

		mknod -m 666 /dev/agentdrv c $(grep agentdrv /proc/devices | sed 's/agentdrv//') 0;

		# 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 666 /dev/i2c/0
		
		# Create these two files for logging users
		touch /var/run/utmp
		touch /var/log/wtmp

		# Create a temp dir for Account Lockout
		mkdir /tmp/auth
		chmod 755 /tmp/auth
        
		if [ -f /var/run/InTestFixture ]; then
			# If in DIAG mode
			echo "DIAGS MODE"
			# Bring the ethernet up manually since eth0 is dissabled
			# by the kernel and firewall is not run in DIAGS mode.
			# No need to do this for NORMAL mode, since firewall does
			# this job.
			# Loading the agent driver module
			ifup eth0
			/usr/local/bin/set_debugmode.sh
			/usr/local/bin/diag
		else 
			# If in normal mode
			echo "NORMAL MODE"

			# 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

			# Older ONTAP version do not always do a CONFIG_START
			# In those cases, we will need to up-convert dns config
			# file.
			/usr/local/bin/rlm_conf.sh dns_config
			
			# Starting the agentd, eventd and seld
			/usr/local/bin/agentd 
			/usr/local/bin/eventd
			/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 console logger
			/usr/local/bin/logger
	
			# 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 diagd 
			/usr/local/bin/diagd

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

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

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

			# Starting the asupd
			/usr/local/bin/asupd
	
			# Starting the collect diagnostics
			/usr/local/bin/coll_diags

			# Starting RSAD
			/usr/local/bin/rsad

			# Starting healthd
			/usr/local/bin/healthd

			# Starting Passowrd Authentication Lockout daemon
			/usr/local/bin/passwd_auth

			# Enabling root login & priv test for Golden RLM
			# Golden RLM has /mnt/logs/var/RLM_debugmode present
			if [ -f "/mnt/logs/var/RLM_debugmode" ] ; then
			    sleep 10 
                  	    /usr/local/bin/set_debugmode.sh
			fi
			if ! [ -f /mnt/logs/etc/ssh/ssh_host_key ]; then
				touch /mnt/logs/etc/copyStart;
				cp -f /etc/ssh/ssh_host_key /mnt/logs/etc/ssh/ssh_host_key;
				cp -f /etc/ssh/ssh_host_key.pub /mnt/logs/etc/ssh/ssh_host_key.pub;
				cp -f /etc/ssh/ssh_host_dsa_key /mnt/logs/etc/ssh/ssh_host_dsa_key;
				cp -f /etc/ssh/ssh_host_dsa_key.pub /mnt/logs/etc/ssh/ssh_host_dsa_key.pub;
				cp -f /etc/ssh/ssh_host_rsa_key /mnt/logs/etc/ssh/ssh_host_rsa_key;
				cp -f /etc/ssh/ssh_host_rsa_key.pub /mnt/logs/etc/ssh/ssh_host_rsa_key.pub;
				rm -f /mnt/logs/etc/copyStart;
			fi
																							
		fi
		;;
	stop)
            ;;  
        *)
	    echo "Usage: local {start|stop}" >&2
	    exit 1
	    ;; 
esac
