Files
dotfiles/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl
T

79 lines
1.7 KiB
Cheetah
Executable File

#!/bin/sh
set -euo pipefail
# NixOS
{{ if eq .chezmoi.osRelease.id "nixos" }}
exit 0
{{ end }}
echo "Installing native packages..."
# Arch-based
{{ if or (eq .chezmoi.osRelease.id "arch") (eq .chezmoi.osRelease.id "cachyos") }}
sudo pacman -Sy --noconfirm
pkgs=()
{{ range .packages.arch }}
if ! pacman -Q "{{ . }}" &>/dev/null; then
pkgs+=("{{ . }}")
fi
{{ end }}
if [[ ${#pkgs[@]} -gt 0 ]]; then
echo "Installing pacman packages..."
sudo pacman -S --noconfirm --needed "${pkgs[@]}"
fi
if command -v paru >/dev/null 2>&1; then
echo "Paru is already installed."
else
sudo pacman -S --noconfirm --needed git base-devel
build_dir="$HOME/.cache/chezmoi-paru-build"
rm -rf "$build_dir"
mkdir -p "$build_dir"
git clone https://aur.archlinux.org/paru.git "$build_dir"
makepkg --dir "$build_dir" -si --noconfirm
rm -rf "$build_dir"
fi
aur_pkgs=()
{{ range .packages.aur }}
if ! pacman -Q "{{ . }}" &>/dev/null; then
aur_pkgs+=("{{ . }}")
fi
{{ end }}
if [[ ${#aur_pkgs[@]} -gt 0 ]]; then
echo "Installing AUR packages..."
paru -S --noconfirm --needed "${aur_pkgs[@]}"
fi
{{ end }}
# Go packages
go_pkgs=()
{{ range .packages.go }}
go_pkgs+=("{{ . }}")
{{ end }}
if ! command -v go >/dev/null 2>&1; then
echo "Go is not installed, skipping packages installation..."
else
for pkg in "${go_pkgs[@]}"; do
echo "Installing: $pkg"
go install "${pkg}@latest"
done
fi
# Nix packages
if ! command -v nix >/dev/null 2>&1; then
echo "Nix is not installed, skipping packages installation..."
else
FLAKE_DIR="$HOME/.config/nixpkgs"
if [ -d "$FLAKE_DIR" ] && [ -f "$FLAKE_DIR/flake.nix" ]; then
echo "Installing Nix packages..."
nix profile install "$FLAKE_DIR" || true
fi
fi
echo "Done"