#!/bin/sh
#
# Writes the final sources.list file
#

CHROOT=$(mount | grep proc | grep calamares | awk '{print $3}' | sed -e "s#/proc##g")

# re-generate ssh host keys
echo rebuild ssl keys
chroot $CHROOT sh -c 'dpkg -l openssh-server | grep -e "^ii" && (rm /etc/ssh/ssh_host_*; dpkg-reconfigure openssh-server)' || true
chroot $CHROOT sh -c 'dpkg-reconfigure ssl-cert' || true

echo disable ssh by default
# Disable openssh-server - now enabled by default since parrot 5.0
chroot $CHROOT sh -c 'systemctl disable ssh' || true

echo unlock held packages
# Unlock kernel packages
chroot $CHROOT sh -c 'apt-mark showhold | while read pkg; do apt-mark unhold $pkg; done' || true

# Set Parrot hostname
echo parrot > $CHROOT/etc/hostname

cat <<EOF > $CHROOT/etc/hosts
# Host addresses
127.0.0.1  localhost
127.0.1.1  parrot
::1        localhost ip6-localhost ip6-loopback
ff02::1    ip6-allnodes
ff02::2    ip6-allrouters
# Others
EOF

cat << EOF > $CHROOT/etc/apt/sources.list
# This file is empty, feel free to
# add here your custom APT repositories

# The default Parrot repositories are NOT here. Take a look at
#    /etc/apt/sources.list.d/parrot.list


#############
#  WARNING  #
#############

# ADDING EXTERNAL REPOSITORIES MAY HARM YOUR SYSTEM,
# MAY INTRODUCE MALWARE, CAUSE INSTABILITY OR
# CAUSE PERMANENT DATA LOSS
#    DO IT WISELY

# if the default servers are unavailable or too slow
# open /etc/apt/sources.list.d/parrot.list
# and follow the instructions to choose a faster server
# or read https://www.parrotsec.org/docs/mirrors/mirrors-list/ for more info
EOF
echo disabling live autologin hook
rm $CHROOT/etc/lightdm/lightdm.conf.d/live-autologin.conf || true

cat << EOF > /etc/lightdm/lightdm.conf
[Seat:*]
greeter-hide-users=false
greeter-allow-guest=false
#autologin-guest=false
#autologin-user=
#autologin-user-timeout=0
#exit-on-failure=false
EOF


echo removing unneeded packages
chroot $CHROOT sh -c 'apt -y purge live-boot live-config live-config-doc live-config-systemd live-tools calamares-settings-parrot'
chroot $CHROOT sh -c 'apt -y autoremove'


exit 0
