#!/bin/bash

VER="D2"

function intro() {
	echo
	echo "This is a script for creating an initial configuration for the msn client."
	echo "Any problems or questions regarding it, email albertogli@telpin.com.ar."
	echo
	echo "Now you will have to answer a few questions. If you are in doubt, press ENTER and the harmless default will be used."
	echo "If you want to abort any time, just press CTRL+C"
	echo
}

function get_email() {
	echo "* Email"
	echo "This is the email address you use with your msn account, usually (but not necesarily) a hotmail.com account."
	while [ -z "$EMAIL" ]; do
		read -p "Please insert your email address: " EMAIL
		echo
	done
	echo
	export EMAIL
}

function get_pass() {
	echo "* Password"
	echo "Your email address' password. Note that the characters won't be displayed for security issues."
	while [ -z "$PASS" ]; do
		read -s -p "Please insert your password: " PASS
		echo
	done
	echo
	export PASS
}

function create_dirs() {
	mkdir "$HOME/.msn" 2> /dev/null
	mkdir "$HOME/.msn/history" 2> /dev/null
	chmod -R og-rwx "$HOME/.msn"
}

function create_rc() {
	if [ -s "$HOME/.msn/msnrc" ]; then
		echo "Error: file $HOME/.msn/msnrc already exists!"
		exit
	fi
	touch "$HOME/.msn/msnrc"
	chmod -R 0600 "$HOME/.msn/msnrc"
	echo "# msn client configuration file" >> "$HOME/.msn/msnrc"
	echo "# created automatically by the msnsetup script (version $VER)" >> "$HOME/.msn/msnrc"
	echo >> "$HOME/.msn/msnrc"
	echo "email = $EMAIL" >> "$HOME/.msn/msnrc"
	echo "password = $PASS" >> "$HOME/.msn/msnrc"
	echo >> "$HOME/.msn/msnrc"
}	


# main
intro
get_email
get_pass
echo "Creating the directory hierachy ($HOME/.msn)"
create_dirs
echo "Creating the configuration file ($HOME/.msn/msnrc)"
create_rc
echo "Done! run 'msn' to start the client"



