#!/bin/sh

localectl set-locale LANG=en_US.utf8

mkdir -p /etc/net/ifaces/vmbr0
touch /etc/net/ifaces/vmbr0/options
printf "stp AUTO off\nsetfd AUTO 0\n" > /etc/net/ifaces/vmbr0/brctl

. /etc/sysconfig/clock; echo $ZONE > /etc/timezone; ln -sf /usr/share/zoneinfo/$ZONE /etc/localtime

if ! grep -q ip6 /etc/hosts; then
    printf "\n# The following lines are desirable for IPv6 capable hosts\n\
::1     ip6-localhost ip6-loopback\n\
fe00::0 ip6-localnet\n\
ff00::0 ip6-mcastprefix\n\
ff02::1 ip6-allnodes\n\
ff02::2 ip6-allrouters\n\
ff02::3 ip6-allhosts\n" >> /etc/hosts
update_chrooted conf
fi

if ! grep -q LC_PVE_TICKET /etc/openssh/sshd_config; then
    N=$(($(sed -n '/^AcceptEnv/{=}' /etc/openssh/sshd_config | tail -1) + 1))
    sed -i "${N}i AcceptEnv LC_PVE_TICKET\n" /etc/openssh/sshd_config
    systemctl restart sshd
fi
if ! grep -q LC_PVE_TICKET /etc/openssh/ssh_config; then
    N=$(($(sed -n '/^[[:space:]]*SendEnv/{=}' /etc/openssh/ssh_config | tail -1) + 1))
    sed -i "${N}i \ \ \ \ SendEnv LC_PVE_TICKET\n" /etc/openssh/ssh_config
fi

install -m644 /usr/share/doc/pve-cluster/rrdcached.sysconfig /etc/sysconfig/rrdcached
mkdir -p /var/lib/rrdcached/{db,journal}

systemctl start syslogd rrdcached ksmtuned crond lxcfs openvswitch nfs-client.target
systemctl enable syslogd rrdcached ksmtuned crond lxcfs openvswitch nfs-client.target

if [ -f /lib/systemd/system/chronyd.service ]; then
    NTPD="chronyd"
else
    NTPD="ntpd"
fi
systemctl start $NTPD
systemctl enable $NTPD
