#!/bin/bash

set -e

### Switch to the script directory
_BASENAME=$(basename "$0")
_DIRNAME="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
cd "$_DIRNAME" || _exit 1
source scripts/functions.sh

### install packages
sed -i "s|^#Color.*|Color|" /etc/pacman.conf
sed -i "s|^#ParallelDownloads.*|ParallelDownloads = 10|" /etc/pacman.conf

#pacman -Syu --noconfirm
#pacman -S --noconfirm - < packages

### Configure tty
mkdir -p /etc/systemd/system/getty@tty1.service.d
ln -sf "${_DIRNAME}/links/tty/autologin.conf" /etc/systemd/system/getty@tty1.service.d/override.conf
ln -sf "${_DIRNAME}/links/tty/bash.bashrc" /etc/bash.bashrc
ln -sf "${_DIRNAME}/links/tty/bash.bashaliases" /etc/bash.bashaliases
ln -sf "${_DIRNAME}/links/tty/bash.bashexports" /etc/bash.bashexports
ln -sf "${_DIRNAME}/links/tty/inputrc" /etc/inputrc
ln -sf "${_DIRNAME}/links/tty/issue" /etc/issue

### Configure X11
cp ./templates/X11/.Xresources ./links/X11/.Xresources
_template "./links/X11/.Xresources"
ln -sf "${_DIRNAME}/links/X11/.Xresources" /etc/X11/xinit/.Xresources
ln -sf "${_DIRNAME}/links/X11/xinitrc" /etc/X11/xinit/xinitrc
ln -sf "${_DIRNAME}/links/X11/00-keyboard.conf" /etc/X11/xorg.conf.d/00-keyboard.conf
cp /usr/share/X11/xkb/symbols/us /usr/share/X11/xkb/symbols/us_qwerty-fr
curl https://raw.githubusercontent.com/qwerty-fr/qwerty-fr/master/linux/us_qwerty-fr >> /usr/share/X11/xkb/symbols/us_qwerty-fr
xrdb /etc/X11/xinit/.Xresources

### Configure i3
mkdir -p ~/.config/i3
ln -sf "${_DIRNAME}/links/i3wm/config" ~/.config/i3/config

### Configure rofi
cp ./templates/rofi/colors.rasi ./links/rofi/colors.rasi
_template "./links/rofi/colors.rasi"
mkdir -p ~/.config/rofi
mkdir -p ~/.local/share/rofi/themes
ln -sf "${_DIRNAME}/links/rofi/config.rasi" ~/.config/rofi/config.rasi
ln -sf "${_DIRNAME}/links/rofi/colors.rasi" ~/.local/share/rofi/themes/colors.rasi
ln -sf "${_DIRNAME}/links/rofi/disconnect.rasi" ~/.local/share/rofi/themes/disconnect.rasi
ln -sf "${_DIRNAME}/links/rofi/launcher.rasi" ~/.local/share/rofi/themes/launcher.rasi

### Configure polybar
cp ./templates/polybar/config.ini ./links/polybar/config.ini
_template "./links/polybar/config.ini"
ln -sf "${_DIRNAME}/links/polybar/config.ini" /etc/polybar/config.ini

### Configure dunst
cp ./templates/dunst/dunstrc ./links/dunst/dunstrc
_template "./links/dunst/dunstrc"
ln -sf "${_DIRNAME}/links/dunst/dunstrc" /etc/dunst/dunstrc

### Configure picom
ln -sf "${_DIRNAME}/links/picom/picom.conf" /etc/xdg/picom.conf

### Applications
mkdir -p ~/.local/share/applications
ln -sf "${_DIRNAME}/links/applications/code.desktop" ~/.local/share/applications/code.desktop
ln -sf "${_DIRNAME}/links/applications/teams.desktop" ~/.local/share/applications/teams.desktop
