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

94 lines
2.2 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") }}
pkgs=()
{{ range .packages.arch }}
if ! pacman -Q "{{ . }}" &>/dev/null; then
pkgs+=("{{ . }}")
fi
{{ end }}
if [[ ${#pkgs[@]} -gt 0 ]]; then
echo "Installing pacman packages..."
if [ -t 0 ]; then
while true; do
read -r -p "Run 'pacman -Sy' to refresh package databases? [y/N] " reply || { echo "(input ended/cancelled)"; break; }
reply="${reply:-N}"
case "$reply" in
[Yy]*) sudo pacman -Sy --noconfirm; break ;;
[Nn]*) echo "Skipping package database refresh (default: no update)."; break ;;
*) continue ;;
esac
done
else
if [ "${CHEZMOI_SYSTEM_UPDATE:-0}" = "1" ]; then
sudo pacman -Sy --noconfirm
fi
fi
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"