#!/usr/bin/env bash

# universal/essential-packages hash: {{ include (joinPath ".chezmoitemplates" "universal" "essential-packages") | sha256sum }}

{{- includeTemplate "universal/logg" }}

{{- $packages := splitList " " (includeTemplate "universal/essential-packages" .) }}
{{- $gpgDependencies := list
gnupg2
gnupg-agent
gnupg-curl
scdaemon
pcscd
-}}
{{- if .toolchains.gpg }}
{{- $packages = concat $packages $gpgDependencies -}}
{{- end }}
{{- $pyenvDependencies := list
"base-devel"
"openssl"
"zlib"
"xz"
"tk"
}}
{{- if .toolchains.python }}
{{- $packages = concat $packages $pyenvDependencies -}}
{{- end }}

logg 'Installing common dependencies using `pacman`'
logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}'

### Install base dependencies
sudo pacman -Sy --noconfirm --needed {{ $packages | sortAlpha | uniq | join " " -}}

### Install yay
if ! command -v yay > /dev/null; then
  logg 'Cloning yay from `https://aur.archlinux.org/yay.git` to `/usr/local/src/yay`'
  sudo git clone https://aur.archlinux.org/yay.git /usr/local/src/yay
  cd /usr/local/src/yay
  logg 'Installing yay via `sudo makepkg -si`'
  sudo makepkg -si
fi
