#ProxmoxCT Note use privileged container with nesting enabled  #

#EPEL Repo
rpm --rebuilddb
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8

#Webmin repo
cat << 'EOF' >> /etc/yum.repos.d/webmin.repo 
[Webmin]
name=Webmin
#baseurl=https://download.webmin.com/download/yum
mirrorlist=https://download.webmin.com/download/yum/mirrorlist
enabled=1
EOF
rpm --import https://download.webmin.com/jcameron-key.asc

#Install
dnf --setopt=install_weak_deps=False --best --refresh -y install samba samba-common cronie nfs-utils webmin openssh-server nano nload htop avahi wsdd

#Webin config
service webmin stop
systemctl start webmin
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
service webmin stop
systemctl enable --now smb nfs-server webmin avahi-daemon wsdd
systemctl restart smb nfs-server webmin avahi-daemon wsdd