#!/bin/bash

config=/usr/src/linux/.config

#Live media hostname
echo "livecd" > /etc/hostname

#Calamares
shopt -s extglob
emerge --autounmask-write=y --ask --deep --newuse app-admin/calamares
while [ $? -ne 0 ]; do
  dispatch-conf && emerge --autounmask-write=y --ask --deep --newuse app-admin/calamares
done

#Extended globbing by default
echo "shopt -s extglob" >> /etc/profile

#RAM Compression
emerge --autounmask-write=y --deep --newuse --tree --complete-graph sys-block/zram-init
sed -i "s/CONFIG_ZRAM=.*/CONFIG_ZRAM=m/" /usr/src/linux/.config
sed -i "s/CONFIG_ZRAM_WRITEBACK=.*/CONFIG_ZRAM_WRITEBACK=y" /usr/src/linux/.config
sed -i "s/CONFIG_ZRAM_MEMORY_TRACKING=.*/CONFIG_ZRAM_MEMORY_TRACKING=y" /usr/src/linux/.config
sed -i "s/ExecStart.*/ExecStart=\/bin\/bash -c \"source /etc/profile && modprobe zram && zram-init -s2 -azstd -Lzram_swap $(($(free -m | cut -c16-20 | head -n2 | tail -n1)*3))\"/" /lib/systemd/system/zram-swap.service


#Plymouth
sed -i "s/.*PLYMOUTH.*/PLYMOUTH=\"yes\"/" /etc/genkernel.conf
sed -i "s/.*PLYMOUTH_THEME.*/PLYMOUTH_THEME=\"bgrt\"/" /etc/genkernel.conf
genkernel initramfs

#GRUB Plymouth entry
sed -i "s/.*GRUB_CMDLINE_LINUX_DEFAULT.*/GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash zram.num_devices=1\"/" /etc/default/grub
sed -i "s/.*GRUB_GFXMODE.*/GRUB_GFXMODE=\"1366x768x24\"/" /etc/default/grub
sed -i "s/.*GRUB_TIMEOUT.*/GRUB_TIMEOUT=0/" /etc/default/grub
sed -i "s/.*GRUB_GFXPAYLOAD_LINUX.*/GRUB_GFXPAYLOAD_LINUX=keep/" /etc/default/grub

#Root password
passwd

#Automatic login
systemctl enable gdm.service
sed -i "3a AutomaticLoginEnable=true" /etc/gdm/custom.conf
sed -i "4a AutomaticLogin=root" /etc/gdm/custom.conf


#Enable GNOME Shell extensions
gnome-shell-extension-tool -e dash-to-panel@jderose9.github.com
gnome-shell-extension-tool -e user-theme@gnome-shell-extensions.gcampax.github.com
gnome-shell-extension-tool -e desktop-icons@csoriano

#More window controls than just "Close"
echo "gtk-decoration-layout = appmenu:minimize,maximize,close" >> /etc/gtk-3.0/settings.ini

#Arc Theme
sed -i "s/gtk-theme-name.*/gtk-theme-name\ \=\ Arc/" /etc/gtk-3.0/settings.ini 
sed -i "s/gtk-icon-theme-name.*/gtk-icon-theme-name\ \=\ Arc/" /etc/gtk-3.0/settings.ini

#Don't disadvantage those with slower hardware
sed -i "s/MAKEOPTS/#MAKEOPTS/" /etc/portage/make.conf
