From 5c97e0c02c2cd2057781d27a92b8840731b3fa80 Mon Sep 17 00:00:00 2001 From: aloslider <53711835+aloslider@users.noreply.github.com> Date: Sat, 24 Oct 2026 03:37:12 +0300 Subject: [PATCH] Split installation script to several ones; Add neovim update; --- .../run_once_install-neovim.sh.tmpl | 46 ------ ...nchange_before_10-install-packages.sh.tmpl | 134 ------------------ .../run_onchange_before_10-pacman.sh.tmpl | 29 ++++ .../run_onchange_before_11-paru.sh.tmpl | 51 +++++++ .../run_onchange_before_12-go.sh.tmpl | 28 ++++ .../run_onchange_before_13-nix.sh.tmpl | 37 +++++ .../run_onchange_before_14-flatpak.sh.tmpl | 37 +++++ .../run_onchange_before_15-neovim.sh.tmpl | 53 +++++++ 8 files changed, 235 insertions(+), 180 deletions(-) delete mode 100755 .chezmoiscripts/run_once_install-neovim.sh.tmpl delete mode 100755 .chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl create mode 100755 .chezmoiscripts/run_onchange_before_10-pacman.sh.tmpl create mode 100755 .chezmoiscripts/run_onchange_before_11-paru.sh.tmpl create mode 100755 .chezmoiscripts/run_onchange_before_12-go.sh.tmpl create mode 100755 .chezmoiscripts/run_onchange_before_13-nix.sh.tmpl create mode 100755 .chezmoiscripts/run_onchange_before_14-flatpak.sh.tmpl create mode 100755 .chezmoiscripts/run_onchange_before_15-neovim.sh.tmpl diff --git a/.chezmoiscripts/run_once_install-neovim.sh.tmpl b/.chezmoiscripts/run_once_install-neovim.sh.tmpl deleted file mode 100755 index c3de18f..0000000 --- a/.chezmoiscripts/run_once_install-neovim.sh.tmpl +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -{{ if eq .chezmoi.osRelease.id "nixos" }} -exit 0 -{{ end }} - -set -euo pipefail - -echo "Installing Neovim..." - -SRC_DIR="${HOME}/apps/neovim" -BIN_DIR="${HOME}/.local" -BIN_PATH="${BIN_DIR}/bin/nvim" -BUILD_TYPE="RelWithDebInfo" -BRANCH="master" - -if [[ -x "${BIN_PATH}" ]]; then - echo "Neovim already installed at ${BIN_PATH}" - exit 0 -fi - -echo "Installing neovim from source" -echo "Target folder: ${SRC_DIR}" -echo "Branch: ${BRANCH}" -echo "Build type: ${BUILD_TYPE}" - -{{ if or (eq .chezmoi.osRelease.id "arch") (eq .chezmoi.osRelease.id "cachyos") }} -sudo pacman -S --noconfirm --needed base-devel cmake ninja curl git -{{ end }} - -mkdir -p "${HOME}/apps" - -if [[ -d "${SRC_DIR}/src" ]]; then - cd "${SRC_DIR}/src" - git fetch --all --prune - git checkout "${BRANCH}" - git pull -else - git clone https://github.com/neovim/neovim.git "${SRC_DIR}/src" - cd "${SRC_DIR}/src" - git checkout "${BRANCH}" -fi - -cd "${SRC_DIR}/src" -rm -rf ${SRC_DIR}/build -make CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX=${BIN_DIR} -DMIN_LOG_LEVEL=1" CMAKE_BUILD_TYPE=${BUILD_TYPE} -make install diff --git a/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl b/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl deleted file mode 100755 index 564a757..0000000 --- a/.chezmoiscripts/run_onchange_before_10-install-packages.sh.tmpl +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" - -# 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") }} - -if [ "$UPDATE" = "1" ]; then - sudo pacman -Syu --noconfirm -else - echo "Skipping system refresh+upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" -fi - -# install packages -pkgs=() -{{ range .packages.arch }} -pacman -Q "{{ . }}" &>/dev/null || pkgs+=("{{ . }}") -{{ end }} -((${#pkgs[@]})) && sudo pacman -S --noconfirm --needed "${pkgs[@]}" - -# Paru + AUR -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 - -# Updates only when requested, otherwise install packages that are missing and leave the installed version. -aur_pkgs=() -{{ range .packages.aur }} -name="{{ . }}" -if [ "$UPDATE" = "1" ] || ! pacman -Q "$name" &>/dev/null; then - aur_pkgs+=("$name") -fi -{{ end }} - -if [[ ${#aur_pkgs[@]} -gt 0 ]]; then - if [ "$UPDATE" = "1" ]; then - echo "Installing latest AUR packages..." - paru -Su --noconfirm - paru -S --noconfirm --needed "${aur_pkgs[@]}" - else - echo "Installing AUR packages..." - paru -S --noconfirm --needed "${aur_pkgs[@]}" - fi -elif [ "$UPDATE" != "1" ]; then - echo "Skipping AUR upgrades (CHEZMOI_SYSTEM_UPDATE!=1)" -fi -{{ end }} - -# Go packages -go_pkgs=() - -if ! command -v go >/dev/null 2>&1; then - echo "Go is not installed, skipping packages installation..." -else - # Install packages - {{ range .packages.go }} - name="{{ .id }}" - - # Update package version - version="" - if [ "$UPDATE" = "1" ]; then - version="latest" - else - version="{{ .version | default "latest" }}" # default to latest instead of fail - fi - go install "${name}@${version}" - {{ end }} -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" - - # Latest bumps flake.lock, (same as for go), otherwise install from the existing lock. - if [ -d "$FLAKE_DIR" ] && [ -f "$FLAKE_DIR/flake.nix" ]; then - if [ "$UPDATE" = "1" ]; then - echo "Updating Nix packages to latest..." - nix flake update --flake "$FLAKE_DIR" - nix profile upgrade --all - nix profile install "$FLAKE_DIR" || true - else - echo "Skipping Nix profile upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" - if [ -f "$FLAKE_DIR/flake.lock" ]; then - nix profile install --no-update-lock-file "$FLAKE_DIR" || true - else - nix profile install "$FLAKE_DIR" || true - fi - fi - fi -fi - -# Flatpak -if ! command -v flatpak > /dev/null 2>&1; then - echo "Flatpak not installed, skipping apps installation..." -else - if [ "$UPDATE" = "1" ]; then - flatpak update -y --noninteractive - else - echo "Skipping Flatpak update (CHEZMOI_SYSTEM_UPDATE!=1)" - fi - {{ range .packages.flatpak_remotes }} - flatpak remote-add --if-not-exists --system "{{ .name }}" "{{ .url }}" || true - {{ end }} - - {{ range .packages.flatpak }} - remote="{{ .remote | default "flathub" }}" - branch="{{ .branch | default "stable" }}" - app="{{ .id }}" - if ! flatpak info --system "$app//$branch" &>/dev/null; then - echo "Installing Flatpak: $app ($remote/$branch)" - flatpak install -y --system --noninteractive "$remote" "$app//$branch" - fi - {{ end }} -fi - -echo "Done" diff --git a/.chezmoiscripts/run_onchange_before_10-pacman.sh.tmpl b/.chezmoiscripts/run_onchange_before_10-pacman.sh.tmpl new file mode 100755 index 0000000..3ade08c --- /dev/null +++ b/.chezmoiscripts/run_onchange_before_10-pacman.sh.tmpl @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Re-run when CHEZMOI_SYSTEM_UPDATE changes. +# {{ env "CHEZMOI_SYSTEM_UPDATE" | default "0" }} +{{ if eq .chezmoi.osRelease.id "nixos" }} +exit 0 +{{ end }} +{{ if not (or (eq .chezmoi.osRelease.id "arch") (eq .chezmoi.osRelease.id "cachyos")) }} +exit 0 +{{ end }} + +UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" + +echo "Installing pacman packages..." + +if [ "$UPDATE" = "1" ]; then + sudo pacman -Syu --noconfirm +else + echo "Skipping system refresh+upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" +fi + +pkgs=() +{{ range .packages.arch }} +pacman -Q {{ . | trim | quote }} &>/dev/null || pkgs+=({{ . | trim | quote }}) +{{ end }} +((${#pkgs[@]})) && sudo pacman -S --noconfirm --needed "${pkgs[@]}" + +echo "Done" diff --git a/.chezmoiscripts/run_onchange_before_11-paru.sh.tmpl b/.chezmoiscripts/run_onchange_before_11-paru.sh.tmpl new file mode 100755 index 0000000..6775af4 --- /dev/null +++ b/.chezmoiscripts/run_onchange_before_11-paru.sh.tmpl @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Re-run when CHEZMOI_SYSTEM_UPDATE changes. +# {{ env "CHEZMOI_SYSTEM_UPDATE" | default "0" }} +{{ if eq .chezmoi.osRelease.id "nixos" }} +exit 0 +{{ end }} +{{ if not (or (eq .chezmoi.osRelease.id "arch") (eq .chezmoi.osRelease.id "cachyos")) }} +exit 0 +{{ end }} + +UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" + +echo "Installing AUR packages..." + +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 + +# Updates only when requested, otherwise install packages that are missing and leave the installed version. +aur_pkgs=() +{{ range .packages.aur }} +name={{ . | trim | quote }} +if [ "$UPDATE" = "1" ] || ! pacman -Q "$name" &>/dev/null; then + aur_pkgs+=("$name") +fi +{{ end }} + +if [[ ${#aur_pkgs[@]} -gt 0 ]]; then + if [ "$UPDATE" = "1" ]; then + echo "Installing latest AUR packages..." + paru -Su --noconfirm + paru -S --noconfirm --needed "${aur_pkgs[@]}" + else + echo "Installing AUR packages..." + paru -S --noconfirm --needed "${aur_pkgs[@]}" + fi +elif [ "$UPDATE" != "1" ]; then + echo "Skipping AUR upgrades (CHEZMOI_SYSTEM_UPDATE!=1)" +fi + +echo "Done" diff --git a/.chezmoiscripts/run_onchange_before_12-go.sh.tmpl b/.chezmoiscripts/run_onchange_before_12-go.sh.tmpl new file mode 100755 index 0000000..f655fdd --- /dev/null +++ b/.chezmoiscripts/run_onchange_before_12-go.sh.tmpl @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Re-run when CHEZMOI_SYSTEM_UPDATE changes. +# {{ env "CHEZMOI_SYSTEM_UPDATE" | default "0" }} +{{ if eq .chezmoi.osRelease.id "nixos" }} +exit 0 +{{ end }} + +UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" + +echo "Installing Go packages..." + +if ! command -v go >/dev/null 2>&1; then + echo "Go is not installed, skipping packages installation..." +else + {{ range .packages.go }} + name={{ .id | quote }} + if [ "$UPDATE" = "1" ]; then + version="latest" + else + version={{ .version | default "latest" | quote }} + fi + go install "${name}@${version}" + {{ end }} +fi + +echo "Done" diff --git a/.chezmoiscripts/run_onchange_before_13-nix.sh.tmpl b/.chezmoiscripts/run_onchange_before_13-nix.sh.tmpl new file mode 100755 index 0000000..a3ebc20 --- /dev/null +++ b/.chezmoiscripts/run_onchange_before_13-nix.sh.tmpl @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Re-run when CHEZMOI_SYSTEM_UPDATE changes. +# {{ env "CHEZMOI_SYSTEM_UPDATE" | default "0" }} +{{ if eq .chezmoi.osRelease.id "nixos" }} +exit 0 +{{ end }} + +UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" + +echo "Installing 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" + + # Latest bumps flake.lock, otherwise install from the existing lock. + if [ -d "$FLAKE_DIR" ] && [ -f "$FLAKE_DIR/flake.nix" ]; then + if [ "$UPDATE" = "1" ]; then + echo "Updating Nix packages to latest..." + nix flake update --flake "$FLAKE_DIR" + nix profile upgrade --all + nix profile install "$FLAKE_DIR" || true + else + echo "Skipping Nix profile upgrade (CHEZMOI_SYSTEM_UPDATE!=1)" + if [ -f "$FLAKE_DIR/flake.lock" ]; then + nix profile install --no-update-lock-file "$FLAKE_DIR" || true + else + nix profile install "$FLAKE_DIR" || true + fi + fi + fi +fi + +echo "Done" diff --git a/.chezmoiscripts/run_onchange_before_14-flatpak.sh.tmpl b/.chezmoiscripts/run_onchange_before_14-flatpak.sh.tmpl new file mode 100755 index 0000000..b8897d6 --- /dev/null +++ b/.chezmoiscripts/run_onchange_before_14-flatpak.sh.tmpl @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Re-run when CHEZMOI_SYSTEM_UPDATE changes. +# {{ env "CHEZMOI_SYSTEM_UPDATE" | default "0" }} +{{ if eq .chezmoi.osRelease.id "nixos" }} +exit 0 +{{ end }} + +UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" + +echo "Installing Flatpak apps..." + +if ! command -v flatpak > /dev/null 2>&1; then + echo "Flatpak not installed, skipping apps installation..." +else + if [ "$UPDATE" = "1" ]; then + flatpak update -y --noninteractive + else + echo "Skipping Flatpak update (CHEZMOI_SYSTEM_UPDATE!=1)" + fi + {{ range .packages.flatpak_remotes }} + flatpak remote-add --if-not-exists --system {{ .name | quote }} {{ .url | quote }} || true + {{ end }} + + {{ range .packages.flatpak }} + remote={{ .remote | default "flathub" | quote }} + branch={{ .branch | default "stable" | quote }} + app={{ .id | quote }} + if ! flatpak info --system "$app//$branch" &>/dev/null; then + echo "Installing Flatpak: $app ($remote/$branch)" + flatpak install -y --system --noninteractive "$remote" "$app//$branch" + fi + {{ end }} +fi + +echo "Done" diff --git a/.chezmoiscripts/run_onchange_before_15-neovim.sh.tmpl b/.chezmoiscripts/run_onchange_before_15-neovim.sh.tmpl new file mode 100755 index 0000000..3affff8 --- /dev/null +++ b/.chezmoiscripts/run_onchange_before_15-neovim.sh.tmpl @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Re-run when CHEZMOI_SYSTEM_UPDATE changes. +# {{ env "CHEZMOI_SYSTEM_UPDATE" | default "0" }} +{{ if eq .chezmoi.osRelease.id "nixos" }} +exit 0 +{{ end }} + +UPDATE="${CHEZMOI_SYSTEM_UPDATE:-0}" + +echo "Installing Neovim..." + +SRC_DIR="${HOME}/apps/neovim" +BIN_DIR="${HOME}/.local" +BIN_PATH="${BIN_DIR}/bin/nvim" +BUILD_TYPE="RelWithDebInfo" +BRANCH="master" + +if [[ -x "${BIN_PATH}" && "$UPDATE" != "1" ]]; then + echo "Neovim already installed at ${BIN_PATH}" + echo "Skipping rebuild (CHEZMOI_SYSTEM_UPDATE!=1)" + exit 0 +fi + +if [[ "$UPDATE" = "1" && -x "${BIN_PATH}" ]]; then + echo "Updating Neovim at ${BIN_PATH}" +else + echo "Installing Neovim from source" +fi +echo "Target folder: ${SRC_DIR}" +echo "Branch: ${BRANCH}" +echo "Build type: ${BUILD_TYPE}" + +{{ if or (eq .chezmoi.osRelease.id "arch") (eq .chezmoi.osRelease.id "cachyos") }} +sudo pacman -S --noconfirm --needed base-devel cmake ninja curl git +{{ end }} + +mkdir -p "${HOME}/apps" + +if [[ -d "${SRC_DIR}/src" ]]; then + git -C "${SRC_DIR}/src" fetch --all --prune + git -C "${SRC_DIR}/src" checkout "${BRANCH}" + git -C "${SRC_DIR}/src" pull --ff-only +else + git clone https://github.com/neovim/neovim.git "${SRC_DIR}/src" + git -C "${SRC_DIR}/src" checkout "${BRANCH}" +fi + +make -C "${SRC_DIR}/src" CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX=${BIN_DIR} -DMIN_LOG_LEVEL=1" CMAKE_BUILD_TYPE="${BUILD_TYPE}" +make -C "${SRC_DIR}/src" install + +echo "Done"