#!/usr/bin/env bash
set -euo pipefail

echo
echo "#################################"
echo "Start mylastarch-final"
echo "#################################"

echo "Permissions of important folders"
echo "#################################"
chmod 750 /etc/sudoers.d
chmod 750 /etc/polkit-1/rules.d
chgrp polkitd /etc/polkit-1/rules.d

echo "Copy /etc/skel to /root"
echo "#################################"
cp -aT /etc/skel/ /root/

echo "Cleanup autologin root"
echo "#################################"
rm -rf /etc/systemd/system/getty@tty1.service.d

echo "Setting editor to nano"
echo "#################################"
grep -qxF "EDITOR=nano" /etc/profile || echo "EDITOR=nano" >> /etc/profile

echo "Cleanup original files"
echo "#################################"
rm -f /etc/sudoers.d/g_wheel
rm -f /etc/polkit-1/rules.d/49-nopasswd_global.rules
rm -rf /etc/systemd/system/etc-pacman.d-gnupg.mount
rm -f /root/.automated_script.sh /root/.zlogin
mv -f /etc/mylastarch-release /etc/lsb-release

echo "Permission of root"
echo "#################################"
chmod -v 750 /root

echo "#################################"
echo "End mylastarch-final"
echo "#################################"
rm -f /usr/local/bin/mylastarch-final
