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

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

# remove launcher from home desktop if not removed
rm $CHROOT/home/*/*/install-debian.desktop || true

# re-generate ssh host 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

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

# 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

exit 0
