#!/bin/bash
echo "Brukarnamn til hovudbrukar: "
read brukarnamn

echo "Setja upp laptop? [y for ja]"
read laptop

if [[ ! "$laptop" == "y" ]]; then
  echo "Installera FUNC? [y for ja]"
  read ifunc
fi

if [[ "$ifunc" == "y" ]]; then
	apt-get -y install python-openssl
	dpkg --force-architecture -i /home/dokument/600\ datateknisk/610\ innstalleringsfiler/615\ Linux/certmaster_0.24.9-1_i386.deb /home/dokument/600\ datateknisk/610\ innstalleringsfiler/615\ Linux/func_0.24.9-1_all.deb

	update-rc.d funcd defaults
	invoke-rc.d funcd start

	echo ">> Køyr dette på kanin:" > log.setup
	echo "   certmaster-ca --sign $(hostname)" > log.setup
fi

##############
# Cache av apt

#Lat maskinone bruka kanin som cache.
echo "Legg inn apt-cache"
echo 'Acquire::http::Proxy "http://kanin:3142";' > /etc/apt/apt.conf.d/90apt-cache

if [[ ! -f "/etc/apt/sources.list.d/medibuntu.list" ]]; then
    wget http://www.medibuntu.org/sources.list.d/karmic.list --output-document=/etc/apt/sources.list.d/medibuntu.list
    aptitude update
    apt-get install medibuntu-keyring && apt-get update && apt-get dist-upgrade
fi

apt-get install gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse gstreamer0.10-schroedinger gstreamer0.10-pitfdll gstreamer0.10-fluendo-mp3  thunderbird libdvdcss2 flashplugin-nonfree gnome-do vim openssh-server libpam-cracklib 

if [[ "$laptop" == "y" ]]; then
    # Gjer klientdelen av backup, frå backup-dokumentasjonen.
    scp odin@okse:docs/set_upp_backup_paa_klient.sh . && \
    chmod a+x set_upp_backup* && \
    ./set_upp_backup_paa_klient.sh -r && \
    su -c ./set_upp_backup_paa_klient.sh
else
    apt-get install ntp autofs portmap nfs-common auth-client-config libpam-ldap libnss-ldap 
fi
#sed -i "s/$(hostname)/$(hostname).neitileu.no $(hostname)/" /etc/hosts

###########
# Legg inn enkel brannmur (OBS; ENNO IKKJE TESTA)
ufw enable
ufw allow ssh


###########
# Fiks grub

sed -i 's/TIMEOUT=10/TIMEOUT=1/' /etc/default/grub
update-grub

################
# Legg til NFS
if [[ ! "$laptop" == "y" ]]; then
    if [[ ! -d /local-home ]]; then
        echo "Flytter home til local-home"

#Flytt den lokale brukaren si heimemappa vekk

        sed -i "s,home,local-home," /etc/passwd

#Lag ei ny heimemappa til nfs
        cd /; mv home/ local-home/
    fi

    if [[ ! -f /etc/auto.home ]]; then
        echo "Set upp automount"
## DETTE ER GAMLEMÅTEN
 #Test å kopla ho opp via NFS
 #    mkdir /home
 #    mount.nfs knutgeir:/home /home/
 #    ls /home/
 #Legg til i /etc/fstab
 #    echo "knutgeir:/home /home nfs rsize=8192,wsize=8192,timeo=14,intr" >> /etc/fstab

#Bruk autofs (nye måten)
        echo "/home	/etc/auto.home" >> /etc/auto.master
        echo "*	-rsize=8192,wsize=8192,timeo=14,intr	knutgeir:/home/&" > /etc/auto.home

        echo "/srv	/etc/auto.srv" >> /etc/auto.master
        echo "*	-rsize=8192,wsize=8192,timeo=14,intr	knutgeir:/srv/&" > /etc/auto.srv

    fi


##################
# Set upp OpenLDAP

#Debconf kjem fram, skriv inn fylgjande:

#    LDAP server Uniform Resource Identifier (uri):  ldap://ldap.neitileu.no/
#    Distinguished name of the search base (base):   dc=neitileu,dc=no
#    LDAP version:                                   3
#    Make local root database admin:                 Yes
#    Does LDAP database require login:               No
#    LDAP account for root:                          cn=admin,dc=neitileu,dc=no
#    LDAP root password:                             <root-passordet til LDAP>

#So skal me gjera litt endringar i configfili:

#    sed -i "s/#host 127.0.0.1/host ldap.neitileu.no/" /etc/ldap.conf
#    sed -i "s/#bind_policy hard/bind_policy soft/" /etc/ldap.conf
    #ln -s /etc/ldap.conf /etc/ldap/ldap.conf

    scp odin@okse:docs/filer/ldap.conf /etc/
###############
# Setja upp pam

#Endra PAM-innstillingane
    echo "Set upp PAM"
    auth-client-config -a -p ldap_example

#sed -i 's/minlen=8/minlen=6/' /etc/pam.d/common-password

    echo >> log.setup
    echo "Du MÅ seriøst starta maskini um att fyrr innlogging via GDM fungerer" >> log.setup
fi

###################
# Leggja inn rettar

#Pass på at nteu-brukaren hev alle dei gruppone han skal. So legg til nye adminer (kvar brukar er admin på eigen maskin)
echo "Gjer $brukarnamn til admin (osb)"
sed -i "s/nteu$/nteu,$brukarnamn/" /etc/group
grep $brukarnamn /etc/group

######################
# Leggja til skrivarar

if [[ ! -f "/etc/cups/ppd/store.ppd" ]]; then
    echo "Legg inn skrivarar"
    scp -r odin@okse:docs/filer/ppd/ odin@okse:docs/filer/printers.conf /etc/cups/
else
    echo "Skrivarar allereide lagt inn"
fi

#####################
# umask
if [[ ! -f "/etc/X11/Xsession.d/59umask" ]]; then
    echo "Fikser umask"
    echo "umask 0002" > /etc/X11/Xsession.d/59umask
else
    echo "Umask allereide fiksa"
fi



echo "##### FERDIG #####"
cat log.setup
