#ProxmoxCT Note use privileged container with nesting enabled  #

#Prerequisite packages
export DEBIAN_FRONTEND=noninteractive
apt install --no-install-recommends wget gnupg2 apt-transport-https -y

#Webin repo
wget -qO - https://download.webmin.com/jcameron-key.asc | sudo apt-key add -
echo "deb https://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list

#Wsdd(Web Service Discovery host daemon) repo
wget -O - https://pkg.ltec.ch/public/conf/ltec-ag.gpg.key|apt-key add -
echo "deb https://pkg.ltec.ch/public/ `lsb_release -cs` main" > /etc/apt/sources.list.d/wsdd.list

#Install
apt update
debconf-set-selections <<<"samba-common samba-common/do_debconf boolean true"
apt install --no-install-recommends samba samba-vfs-modules cron nfs-kernel-server webmin openssh-server nano nload htop avahi-daemon avahi-utils wsdd -y

#Webmin config
sed -i -e '/port=/c\port=80' -e 's/ssl=/c\ssl=0/g' -e 's/ipv6=/c\ipv6=0/g' /etc/webmin/miniserv.conf
echo "servers=Services & Tools" >> /etc/webmin/webmin.catnames
cat << 'EOF' >> /etc/webmin/webmin.cats
filter=cluster 
exports=servers
filemin=servers
useradmin=servers
mailboxes=
EOF


#Samba config
sed -i -e '/map to guest =/c\map to guest = never' /etc/samba/smb.conf

#Avahi config
cat << 'EOF' >> /etc/avahi/services/smb.service
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
   <type>_smb._tcp</type>
   <port>445</port>
 </service>
 <service>
   <type>_device-info._tcp</type>
   <port>0</port>
   <txt-record>model=RackMac</txt-record>
 </service>
</service-group>
EOF

#Restart services
systemctl enable --now smbd nfs-kernel-server webmin avahi-daemon wsdd
systemctl restart smbd nfs-kernel-server webmin avahi-daemon wsdd