
# Install cifs software.
CifsSoftware ()
{
    #https://pimylifeup.com/raspberry-pi-mount-usb-drive/
    
    echo
    echo "cifs-utils: The SMB/CIFS protocol provides support for"
    echo "cross-platform file sharing with Microsoft Windows,"
    echo "OS X, and other Unix systems."
    echo "------------------------------------------------------"
    echo
    apt-get -y install cifs-utils
    apt-get -y install libpam-mount
    apt-get -y install libpam-winbind
    apt-get -y install gvfs-backends
    apt-get -y install smbclient
    apt-get -y install smbutils
    apt-get -y install exfat-fuse
    apt-get -y install exfat-utils
    apt-get -y install dmsetup
    apt-get -y install fusesmb
}

#-----------------------------------------------------------------------

# Installs and sets up Kodi.
KodiSetup ()
{
    #http://forum.kodi.tv/showthread.php?tid=230035
    #https://seo-michael.co.uk/how-to-install-exodus-on-kodi-krypton/
    #http://fusion.tvaddons.ag/
    #http://fusion.tvaddons.ag/kodi-repos/english/repository.exodus-1.0.1.zip

    wget http://fusion.tvaddons.ag/kodi-repos/english/repository.exodus-1.0.1.zip -O /home/pi/repository.exodus-1.0.1.zip

    apt-get -y install kodi
    sudo systemctl enable kodi.service
}

#-----------------------------------------------------------------------

# Install and sets up Samba.
SambaSetup ()
{
    echo
    echo "system-config-samba: is a graphical user interface for"
    echo "creating, modifying, and deleting samba shares and users."
    echo "---------------------------------------------------------"
    echo
    apt-get -y install install samba
    apt-get -y install samba-common
    apt-get -y install python-glade2
    apt-get -y install system-config-samba

    #Creating additional users and the samba group
    groupadd samba

    #Add the users to the samba group
    usermod -a -G samba pi
    usermod -a -G samba root

    #Create the shares in the home dir.
    mkdir -p /home/cifs
    mkdir -p /home/cifs/data01
    mkdir -p /home/cifs/data02

    #Change permissions for the shares.
    chown -R pi:samba /home/cifs
    chmod -R 775 /home/cifs
    chmod -R g+s /home/cifs

    #Create file for system-config-samba to run
    touch /etc/libuser.conf

    #Restart the samba server.
    service smbd restart
}

#-----------------------------------------------------------------------

# Installs and sets up SSH.
SSHSetup ()
{
    #http://raspberrypiprogramming.blogspot.co.uk/2014/07/how-to-execute-x11-applications-from.html
    echo
    echo "This metapackage is a convenient way to install both"
    echo "the OpenSSH client and the OpenSSH server."
    echo "----------------------------------------------------"
    echo
    apt-get -y install ssh
    systemctl enable ssh
}

#-----------------------------------------------------------------------

# Extra utils.
UtilsSoftware ()
{
    apt-get -y install gksu
    apt-get -y install leafpad
    apt-get -y install pcmanfm
}

#-----------------------------------------------------------------------

VPNSetup ()
{
    #https://ipaddress.pro/
    #https://brianhornsby.com/kodi_addons/openvpn
    #wget https://www.privateinternetaccess.com/openvpn/openvpn.zip -O /etc/openvpn/openvpn.zip

    apt-get -y install openvpn
    apt-get -y install psmisc

    wget http//chris.dci.vc/linux/openvpn.zip -O /etc/openvpn/openvpn.zip
    wget https://github.com/brianhornsby/script.openvpn/releases/download/v2.1.0/script.openvpn-2.1.0.zip -O /home/pi/script.openvpn-2.1.0.zip

    unzip /etc/openvpn/openvpn.zip
}

#-----------------------------------------------------------------------

# Zip / archive utils
ZipSoftware ()
{
    echo
    echo "Unrar: Can extract files from .rar archives."
    echo "--------------------------------------------"
    echo
    apt-get -y install unrar

    echo
    echo "p7zip: Can extract files from .7z archives."
    echo "-------------------------------------------"
    echo
    apt-get -y install p7zip-full
    
    echo
    echo "Adding extras for pcmanfm."
    echo "--------------------------"
    echo
    apt-get install -y file-roller
}

#-----------------------------------------------------------------------
#-- Setup function
#-----------------------------------------------------------------------

# The main setup function.
Setup ()
{
    apt-get --force-yes --ignore-hold update
    
    CifsSoftware
    KodiSetup
    SambaSetup
    SSHSetup
    UtilsSoftware
    ZipSoftware
    VPNSetup
}

#=======================================================================
#-- Main part of the script.
#=======================================================================

Setup
sudo reboot
