#! /bin/sh
# neuen Benutzer einrichten
if [ "$1" = "" ] ; then
	echo "Nicht so!"
	echo "schreibe es so: $0 *Name* "'[ *Gruppe* [ *Shell* ]]'
	exit 1
fi

if [ "$2" = "" ] ; then
  gruppe=users
else
  gruppe=$2
  shell=/bin/false
fi

if [ "$3" = "" ] ; then
  shell=/bin/bash
else
  shell=$3
fi

echo gruppe $gruppe
echo shell $shell

# Benutzer anlegen
useradd -g "$gruppe" -s "$shell" -m $1
# Paßwort erfragen
# passwd $1

# Konfiguration des Einwähl-Zugangs
# Daten erfragen:
echo -n "Bitte geben Sie Ihren POP3/Mailserver ein: " ; read mailer
echo -n "Bitte geben Sie Ihren Account ein: " ; read account
echo -n "Bitte geben Sie Ihr Einwahl-Passwort ein:" ; read pass 

# options....
echo "Schreibe options."$1
echo 'lock' > "/etc/ppp/options."$1
echo 'modem' >> "/etc/ppp/options."$1
echo 'defaultroute' >> "/etc/ppp/options."$1
echo 'asyncmap 0' >> "/etc/ppp/options."$1
echo 'mtu 1500' >> "/etc/ppp/options."$1
echo 'mru 1500' >> "/etc/ppp/options."$1
#echo "name "$account >> "/etc/ppp/options."$1
#echo "remotename fh-harz.de" >> "/etc/ppp/options."$1
echo "Ändere Zugriffsrechte"
chmod 600 /etc/ppp/options.$1 

# pap-secrets....
echo "Schreibe pap-secrets."$1
echo "$account 	fh-harz.de  $pass" > "/etc/ppp/pap-secrets."$1

# Zugriffsrechte....
echo "Ändere Zugriffrechte"
chmod 500 "/etc/ppp/pap-secrets."$1
#
echo -n "Bitte geben Sie Ihr Mailer-Passwort ein:"; read pass

# Fetchmail...
# .fetchmailrc
echo "Schreibe .fetchmailrc"
if [ "$mailer" = "" ] ; then
	mailer="mailer.fh-harz.de"
fi
#
# Löschen für den Fall, das es schon existiert....
# sonst kann es evtl nicht überschrieben werden....
#
if [ -f /home/$1/.fetchmailrc ] ; then
	rm /home/$1/.fetchmailrc
fi
#
echo 'poll '"$mailer"' protocol POP3 user '"$account"' password '"$pass"' is '"$1" > /home/$1/.fetchmailrc
echo "Ändere Zugriffsrechte"
chmod 600 /home/$1/.fetchmailrc
chown $1 /home/$1/.fetchmailrc

# pppd
# .pppdrc
echo "Schreibe .ppprc"
echo "name $account" > /home/$1/.ppprc
echo "remotename fh-harz.de" >> /home/$1/.ppprc
echo "Ändere Zugriffsrechte"
chmod 600 /home/$1/.ppprc
chown $1 /home/$1/.ppprc

echo "Soll vom user $user Mail abgerufen werden? [J/N]"; read mailget
if [ "$mailget" -ne "J" ] || [ "$mailget" -ne "j" ]
then
	rm /home/$1/popmail
else
  echo "Soll die Mail vom FH-Server geloescht werden? [J/N]"; read loesch
  if [ "$loesch" = "J" ] || [ "$loesch" = "j" ]
  then
	echo "Falls die Mail nicht mehr vom Hochschulserver geloescht werden soll, so loeschen Sie bitte diese Datei mit dem Kommando: rm /home/$1/killmail !" > /home/$1/killmail
  fi
fi


