#!/bin/sh

# Setup script for the Darwin Streaming Server

echo;echo Darwin Streaming Server Setup;echo

# prompt the user to enter the admin username
while [ "$username" = "" ]; do
	printf "In order to administer the Darwin Streaming Server you must create an administrator user [Note: The administrator user name cannot contain spaces, or single or double quote characters, and cannot be more than 255 characters long].\n"
	
	printf "Please enter a new administrator user name: "
	read username
	if [ "$username" = "" ]; then
		echo ""
		echo "Error: No username entered!"
		echo ""
	fi
done
echo ""

# prompt the user to enter the admin password
while [ "$password" = "" ]; do
	printf "\nYou must also enter a password for the administrator user [Note: The administrator password cannot contain spaces, or quotes, either single or double, and cannot be more than 80 characters long].\n"

	printf "Please enter a new administrator Password: "
	stty -echo
	read password
	stty echo
	echo ""
	printf "Re-enter the new administrator password: "
	stty -echo
	read password1
	stty echo
	if [ "$password" = "" ]; then
		echo ""
		echo "Error: No password entered!"
		echo ""
	fi
	if [ "$password" != "$password1" ]; then
		echo ""
		echo "Error: passwords entered do not match!"
		echo ""
		password=""
	fi

done
echo ""

# Add the new admin username to /etc/dss/qtusers
/usr/bin/qtpasswd -p $password $username

# Add the new admin username to /etc/dss/qtgroups
# and delete the default admin username
echo admin: $username > /etc/dss/qtgroups.tmp
mv -f /etc/dss/qtgroups.tmp /etc/dss/qtgroups

# Remove the default admin username to /etc/streaming/qtusers
/usr/bin/qtpasswd -F -d 'aGFja21l' > /dev/null

echo Setup Complete!
