#!/bin/bash
set -e
export DEBIAN_FRONTEND=noninteractive

echo "Removing useless stuff"
apt-get purge -y seclists firefox-esr qt4-designer qttools5-dev-tools texlive-latex-extra-doc texlive-pstricks-doc texlive-pictures-doc texlive-latex-recommended-doc texlive-latex-base-doc texlive-fonts-recommended-doc texlive-pstricks-doc python-mpltoolkits.basemap-data android-sdk libandroid* arduino leafpad xpra ferret minicom xpdf gvim imagemagick vega samba openjdk-9-* || true


echo "Manually enabling pulseaudio"
systemctl --user enable pulseaudio.service || true

echo "Manually enabling live-config"
systemctl enable live-config || true

echo "Doing some magic on networking stuff"
systemctl enable NetworkManager || true
systemctl enable resolvconf || true
#rm /etc/resolv.conf || true
#ln -s etc/resolvconf/run/resolv.conf etc/resolv.conf || true
mkdir -p /etc/systemd/network /etc/udev/rules.d
ln -sf /dev/null "/etc/systemd/network/90-mac-for-usb.link"
ln -sf /dev/null "/etc/systemd/network/99-default.link"
echo > "/etc/udev/rules.d/73-special-net-names.rules"

echo "Manually disabling inetd"
systemctl disable inetd || true

echo "Manually disabling couchdb"
systemctl disable couchdb || true

echo "Manually disabling mariadb"
systemctl disable mariadb || true

echo "Manually disabling openvpn"
systemctl disable openvpn || true

echo "Manualy disabling redis-server"
systemctl disable redis-server || true

echo "Manually disabling nginx"
systemctl disable nginx || true

echo "Manually disabling samba"
systemctl disable smbd samba || true

echo "Manually disabling snmpd"
systemctl disable snmpd || true

echo "Manually disabling nmbd"
systemctl disable nmbd || true

echo "Manually disabling snapd"
systemctl disable snapd || true

echo "Manually disabling openvas services"
systemctl disable openvas-scanner.service || true
systemctl disable openvas-manager.service || true
systemctl disable greenbone-security-assistant || true

echo "Manually disabling redsocks"
systemctl disable redsocks || true

echo "Manually disabling dradis"
systemctl disable dradis || true

echo "Manually disabling packagekit"
systemctl disable packagekit || true

echo "Manually disabling avahi-daemon"
systemctl disable avahi-daemon.socket || true
systemctl disable avahi-daemon.service || true

echo "Manually disabling colord-sane"
systemctl disable colord-sane.service || true

echo "Manually disaling phpsessionclean"
sudo systemctl disable phpsessionclean.timer || true

echo "Manually disabling apt-daily systemd timers"
sudo systemctl disable apt-daily-upgrade.timer || true
sudo systemctl disable apt-daily.time || true

echo "Purging the shit out of systemd"
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/redis-server.service || true
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/smbd.service || true
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/nmbd.service || true
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/snmp.service || true
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/openvas-scanner.service || true
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/openvas-manager.service || true
sed -i "s/WantedBy=multi-user.target//g" /lib/systemd/system/redsocks.service || true

echo "cleaning locales"
bleachbit -c system.localizations apt.autoclean apt.autoremove apt.package_lists deepscan.backup deepscan.ds_store deepscan.thumbs_db deepscan.tmp system.cache system.rotated_logs thumbnails.cache &> /dev/null && echo "done"


parrot-mirror-selector default

echo "adding additional modules to initramfs"
apt -y install initramfs-tools || true
echo "nls_ascii" >> /etc/initramfs-tools/modules
echo "ext4" >> /etc/initramfs-tools/modules
echo "btrfs" >> /etc/initramfs-tools/modules
#echo "zfs" >> /etc/initramfs-tools/modules

echo "Enabling cryptsetup initramfs support"
sed -i "s/#CRYPTSETUP=/CRYPTSETUP=y/" /etc/cryptsetup-initramfs/conf-hook || true

update-initramfs -c -u -t -k all || true
