#!/bin/ash
#
# set_debugmode.sh:
# script to enable root logins for ssh and serial port
# and to create /var/run/PermitPrivTest that the CLI checks to permit 'priv test'
#

# ReturnOnError():
# Exit with an error code on error.
#
ReturnOnError() {
    if ! [ $1 -eq 0 ] ; then
        echo "Error in set_debugmode.sh"
    fi
}

diff /etc/ssh/sshd_config.debug /etc/ssh/sshd_config >> /dev/null
if ! [ $? = 0 ]; then
	cp /etc/ssh/sshd_config.debug /etc/ssh/sshd_config;
	ReturnOnError $?;

	/etc/init.d/ssh restart >> /var/log/messages;
	ReturnOnError $?;
fi

sed 's|root\:\*\:|root\:\$5\$kajVjGT7Eho1Gljv\$i6wSPx\/ZdB2eQ4jazpfeqUBkxn7\/0nabmKL\/zCn9XF3\:|' /etc/passwd > /etc/passwd.new;
mv /etc/passwd.new /mnt/logs/etc/passwd
ReturnOnError $?;

# Create /var/run/PermitPrivTest as root
echo "" > /var/run/PermitPrivTest;
ReturnOnError $?;
