#!/bin/bash
# configurers new server
# version 6-05-2023

# stop on error
set -e

# sources.list
now=$(date +"%d-%m-%y")
cd /tmp
wget https://vandervlis.nl/files/sources.list11
mv /etc/apt/sources.list /etc/apt/sources.list-$now
mv sources.list11 /etc/apt/sources.list

# remove contrib and nonfree:
# sed -i -e 's/main contrib non-free/main/g' /etc/apt/sources.list

apt-get -qq update

# unattended upgrades
apt-get -qqy install unattended-upgrades
if test -e /etc/apt/apt.conf.d/10periodic; then rm /etc/apt/apt.conf.d/10periodic; fi
wget https://vandervlis.nl/files/20auto-upgrades -O /etc/apt/apt.conf.d/20auto-upgrades
wget https://vandervlis.nl/files/50unattended-upgrades -O /etc/apt/apt.conf.d/50unattended-upgrades

# my firewall:
apt-get -qq install iptables
wget https://vandervlis.nl/files/firewall-server -O /usr/local/sbin/firewall
chmod +x /usr/local/sbin/firewall
wget https://www.vandervlis.nl/files/firewall-init -O /etc/init.d/firewall
chmod +x /etc/init.d/firewall
wget https://vandervlis.nl/files/firewall.service -O /lib/systemd/system/firewall.service
if ! test -e /lib/systemd/system/firewall.service; then
  ln -s /lib/systemd/system/firewall.service /etc/systemd/system/
fi
systemctl daemon-reload
systemctl enable firewall
nano /usr/local/sbin/firewall
systemctl start firewall
sleep 3

# nog wat
apt-get -qq install rsync locate

# install SSH server
apt-get -qqy install ssh

# ssh auto-pubkey installeren
if ! test -e /root/.ssh; then mkdir /root/.ssh; fi
if ! test -e /root/.ssh/authorized_keys; then touch /root/.ssh/authorized_keys; fi
if ! grep -q 'auto@laptopp' /root/.ssh/authorized_keys; then
  cd /root/.ssh
  wget https://vandervlis.nl/auto-pubkey -O /root/.ssh/auto-pubkey
  cat /root/.ssh/auto-pubkey >> /root/.ssh/authorized_keys
  chmod 600 /root/.ssh/authorized_keys
  cd
fi

echo
echo "klaar"

	

