From ac46863b48b9f856e19dda456cca3acc00206870 Mon Sep 17 00:00:00 2001 From: Anton Volnuhin Date: Mon, 2 Mar 2026 18:35:11 +0300 Subject: [PATCH] harden install script and fix fish config portability Install script: - fix package availability (skim/fedora, fd-find/debian, direnv+goku/macos) - add CLI flags for non-interactive mode (--skip-timezone, --skip-neovim-bootstrap, etc.) - template STEPS count per OS for correct TUI layout - add brew shellenv for fresh Apple Silicon, timeout portability - pam_ssh_agent_auth availability check with warning for Fedora 42+ - fix fisher detection, authorized_keys whole-line dedup Fish config: - replace set -gx PATH with idempotent fish_add_path - guard direnv/cargo sourcing for missing tools - fix hardcoded /home/anton/ and /Users/anton/ paths - remove unused micromamba/conda setup Co-Authored-By: Claude Opus 4.6 (1M context) --- private_dot_config/private_fish/config.fish | 50 +++++------ run_onchange_after_install_main_deps.sh.tmpl | 88 ++++++++++++++++---- 2 files changed, 92 insertions(+), 46 deletions(-) diff --git a/private_dot_config/private_fish/config.fish b/private_dot_config/private_fish/config.fish index a710316..a7291e3 100644 --- a/private_dot_config/private_fish/config.fish +++ b/private_dot_config/private_fish/config.fish @@ -1,12 +1,12 @@ -set -gx PATH /usr/local/opt/coreutils/libexec/gnubin $PATH -set -gx PATH /opt/homebrew/coreutils/libexec/gnubin $PATH -set -gx PATH /opt/homebrew/bin $PATH -set -gx PATH /usr/local/bin $PATH -set -gx PATH /snap/bin $PATH +fish_add_path /opt/homebrew/bin +fish_add_path /opt/homebrew/coreutils/libexec/gnubin +fish_add_path /usr/local/opt/coreutils/libexec/gnubin +fish_add_path /usr/local/bin +fish_add_path /snap/bin +fish_add_path $HOME/.local/bin +fish_add_path $HOME/.cargo/bin +fish_add_path $HOME/.go/bin set -gx GOPATH $HOME/.go -set -gx PATH $HOME/.local/bin $PATH -set -gx PATH $HOME/.cargo/bin $PATH -set -gx PATH $HOME/.go/bin $PATH set -gx EDITOR nvim set fish_color_valid_path set -g fish_greeting @@ -73,23 +73,9 @@ function winbox ~/dev/winbox/run.sh& end -function conda - micromamba $argv -end - - -if [ -e /opt/homebrew/bin/micromamba ] - # >>> mamba initialize >>> - # !! Contents within this block are managed by 'mamba init' !! - set -gx MAMBA_EXE "/opt/homebrew/bin/micromamba" - set -gx MAMBA_ROOT_PREFIX "/Users/anton/micromamba" - $MAMBA_EXE shell hook --shell fish --root-prefix $MAMBA_ROOT_PREFIX | source - # <<< mamba initialize <<< -end - -if [ -e /home/anton/.nix-profile/etc/profile.d/nix.fish ]; - source /home/anton/.nix-profile/etc/profile.d/nix.fish; +if test -e $HOME/.nix-profile/etc/profile.d/nix.fish + source $HOME/.nix-profile/etc/profile.d/nix.fish end # The next line updates PATH for the Google Cloud SDK. @@ -98,7 +84,9 @@ if [ -f ~/dev/google-cloud-sdk/path.fish.inc ] end -direnv hook fish | source +if type -q direnv + direnv hook fish | source +end if [ -f ~/.config/op/plugins.sh ] source ~/.config/op/plugins.sh end @@ -106,14 +94,16 @@ end #fish_vi_key_bindings # bun -set --export BUN_INSTALL "$HOME/.bun" -set --export PATH $BUN_INSTALL/bin $PATH -source "$HOME/.cargo/env.fish" +set -gx BUN_INSTALL "$HOME/.bun" +fish_add_path $HOME/.bun/bin +if test -f "$HOME/.cargo/env.fish" + source "$HOME/.cargo/env.fish" +end -export PATH="$PATH:/Users/anton/dev/screenpipe/target/debug" +fish_add_path $HOME/dev/screenpipe/target/debug # Added by LM Studio CLI (lms) -set -gx PATH $PATH /Users/anton/.cache/lm-studio/bin +fish_add_path $HOME/.cache/lm-studio/bin # Added by OrbStack: command-line tools and integration # This won't be added again if you remove it. diff --git a/run_onchange_after_install_main_deps.sh.tmpl b/run_onchange_after_install_main_deps.sh.tmpl index 8a5f083..97a57b6 100644 --- a/run_onchange_after_install_main_deps.sh.tmpl +++ b/run_onchange_after_install_main_deps.sh.tmpl @@ -17,12 +17,46 @@ #Config +{{ if eq .chezmoi.os "darwin" -}} +STEPS=9 +{{ else if eq .chezmoi.os "freebsd" -}} +STEPS=9 +{{ else if eq .chezmoi.osRelease.id "ubuntu" -}} STEPS=14 +{{ else if eq .chezmoi.osRelease.id "debian" -}} +STEPS=13 +{{ else -}} +STEPS=12 +{{ end -}} PAD_LEN=4 BASE_PACKAGES="gnupg curl wget git" ACT_PACKAGES="ripgrep unzip htop fzf bat gawk jq nnn tmux mc nethogs ngrep mtr gcc" +# Non-interactive mode flags +ASSUME_YES=0 +NON_INTERACTIVE=0 +SKIP_TIMEZONE=0 +SKIP_AUTH_KEYS=0 +SKIP_SHELL_CHANGE=0 +SKIP_NVIM_BOOTSTRAP=0 + +while [ $# -gt 0 ]; do + case "$1" in + --yes) ASSUME_YES=1 ;; + --non-interactive) NON_INTERACTIVE=1 ;; + --skip-timezone) SKIP_TIMEZONE=1 ;; + --skip-authorized-keys) SKIP_AUTH_KEYS=1 ;; + --skip-shell-change) SKIP_SHELL_CHANGE=1 ;; + --skip-neovim-bootstrap) SKIP_NVIM_BOOTSTRAP=1 ;; + *) echo "Unknown option: $1"; exit 2 ;; + esac + shift +done + +# Timeout portability (macOS has gtimeout via coreutils, not timeout) +TIMEOUT_BIN="$(command -v timeout || command -v gtimeout || true)" + #Colors Green='\033[0;32m' # Green Blue='\033[0;34m' # Blue @@ -55,7 +89,8 @@ read #Setup -TERM_WIDTH_BASE=$(stty size|awk '{print $2}') +TERM_WIDTH_BASE=$(stty size 2>/dev/null | awk '{print $2}') +TERM_WIDTH_BASE=${TERM_WIDTH_BASE:-80} PADDING=$(printf "%${PAD_LEN}s") # 4 spaces of padding TERM_WIDTH=$(($TERM_WIDTH_BASE - $PAD_LEN)) USER=$(whoami) @@ -125,9 +160,14 @@ new_line "Update caches and upgrade packages" {{ else if eq .chezmoi.os "darwin" -}} - if ! type brew; then + if ! command -v brew >/dev/null 2>&1; then bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 2>&1|pad fi + if [ -x /opt/homebrew/bin/brew ]; then + eval "$(/opt/homebrew/bin/brew shellenv)" + elif [ -x /usr/local/bin/brew ]; then + eval "$(/usr/local/bin/brew shellenv)" + fi brew update 2>&1|pad {{ else if eq .chezmoi.osRelease.id "fedora" "almalinux" "rocky" -}} @@ -150,7 +190,7 @@ new_line "Install base packages" sudo pkg install --yes $BASE_PACKAGES py39-pipx direnv 2>&1|pad {{ else if eq .chezmoi.os "darwin" -}} - brew install -q $BASE_PACKAGES python pipx 2>&1|pad + brew install -q $BASE_PACKAGES python pipx direnv goku 2>&1|pad {{ else if eq .chezmoi.osRelease.id "fedora" -}} sudo dnf install $BASE_PACKAGES direnv kitty-terminfo util-linux-user pipx -y 2>&1|pad @@ -221,12 +261,24 @@ sudo pkg install --yes $ACT_PACKAGES neovim fish atuin lazygit fd-find pam_ssh_a brew install -q fish neovim $ACT_PACKAGES atuin jump fd sk dust lazygit 2>&1|pad {{ else if eq .chezmoi.osRelease.id "fedora" -}} - sudo dnf install neovim fish $ACT_PACKAGES fd-find skim pam_ssh_agent_auth -y 2>&1|pad + PAM_SSH_PKG="" + if dnf list --quiet pam_ssh_agent_auth >/dev/null 2>&1; then + PAM_SSH_PKG="pam_ssh_agent_auth" + else + echo -e "${Yello}WARNING: pam_ssh_agent_auth not available in repos. sudo via SSH agent won't work.${NC}" + fi + sudo dnf install neovim fish $ACT_PACKAGES fd-find ${PAM_SSH_PKG:+$PAM_SSH_PKG} -y 2>&1|pad new_line "via NIX" - nix-env -iA nixpkgs.atuin nixpkgs.jump nixpkgs.du-dust nixpkgs.lazygit 2>&1|pad + nix-env -iA nixpkgs.atuin nixpkgs.jump nixpkgs.du-dust nixpkgs.lazygit nixpkgs.skim 2>&1|pad {{ else if eq .chezmoi.osRelease.id "almalinux" "rocky" -}} - sudo dnf install neovim fish $ACT_PACKAGES fd-find pam_ssh_agent_auth -y 2>&1|pad + PAM_SSH_PKG="" + if dnf list --quiet pam_ssh_agent_auth >/dev/null 2>&1; then + PAM_SSH_PKG="pam_ssh_agent_auth" + else + echo -e "${Yello}WARNING: pam_ssh_agent_auth not available in repos. sudo via SSH agent won't work.${NC}" + fi + sudo dnf install neovim fish $ACT_PACKAGES fd-find ${PAM_SSH_PKG:+$PAM_SSH_PKG} -y 2>&1|pad new_line "via NIX" nix-env -iA nixpkgs.fish nixpkgs.neovim nixpkgs.direnv nixpkgs.atuin nixpkgs.jump nixpkgs.du-dust nixpkgs.lazygit 2>&1|pad @@ -238,7 +290,7 @@ new_line "via NIX" {{ else if eq .chezmoi.osRelease.id "debian" "ubuntu" -}} sudo apt-get install fish -y 2>&1|pad sudo apt-get install neovim -y 2>&1|pad - sudo apt-get install $ACT_PACKAGES libpam-ssh-agent-auth -y 2>&1|pad + sudo apt-get install $ACT_PACKAGES fd-find libpam-ssh-agent-auth -y 2>&1|pad new_line "via NIX" nix-env -iA nixpkgs.neovim nixpkgs.lazygit nixpkgs.jump nixpkgs.skim nixpkgs.du-dust nixpkgs.atuin 2>&1|pad @@ -251,18 +303,22 @@ mkdir ~/.ssh 2>/dev/null || true cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.old 2>/dev/null || true ##print only unique lines -cat ~/.ssh/authorized_keys.old <(echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPdqIDeRKDOh7NQDcqnmLH/6M0ys7Wt/SEnF6ZYqroiH") 2>/dev/null | awk '!seen[$1]++' > ~/.ssh/authorized_keys +cat ~/.ssh/authorized_keys.old <(echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPdqIDeRKDOh7NQDcqnmLH/6M0ys7Wt/SEnF6ZYqroiH") 2>/dev/null | awk 'NF && !seen[$0]++' > ~/.ssh/authorized_keys +if [ "$SKIP_NVIM_BOOTSTRAP" -eq 0 ]; then new_line "Waiting for neovim plugins and lsm compilations..." -timeout 60s nvim --headless -c "sleep 1" -c ":Lazy! sync" -c "sleep 10" -c "qa" 2>&1|pad -timeout 60s nvim --headless -c "sleep 1" -c ":MasonUpdate" -c "sleep 5" -c "qa" 2>&1|pad -timeout 60s nvim --headless -c "sleep 1" -c ":MasonInstall lua-language-server" -c "sleep 5" -c "qa" 2>&1|pad -timeout 60s nvim --headless -c "sleep 1" -c ":MasonInstall rust-analyzer" -c "sleep 5" -c "qa" 2>&1|pad -timeout 60s nvim --headless -c "sleep 1" -c ":TSUpdate" -c "sleep 5" -c "qa" 2>&1|pad +${TIMEOUT_BIN:+$TIMEOUT_BIN 60s} nvim --headless -c "sleep 1" -c ":Lazy! sync" -c "sleep 10" -c "qa" 2>&1|pad +${TIMEOUT_BIN:+$TIMEOUT_BIN 60s} nvim --headless -c "sleep 1" -c ":MasonUpdate" -c "sleep 5" -c "qa" 2>&1|pad +${TIMEOUT_BIN:+$TIMEOUT_BIN 60s} nvim --headless -c "sleep 1" -c ":MasonInstall lua-language-server" -c "sleep 5" -c "qa" 2>&1|pad +${TIMEOUT_BIN:+$TIMEOUT_BIN 60s} nvim --headless -c "sleep 1" -c ":MasonInstall rust-analyzer" -c "sleep 5" -c "qa" 2>&1|pad +${TIMEOUT_BIN:+$TIMEOUT_BIN 60s} nvim --headless -c "sleep 1" -c ":TSUpdate" -c "sleep 5" -c "qa" 2>&1|pad +fi {{ if eq .chezmoi.os "linux" -}} - new_line "Setting timezone to Moscow" - sudo timedatectl set-timezone Europe/Moscow + if [ "$SKIP_TIMEZONE" -eq 0 ]; then + new_line "Setting timezone to Moscow" + sudo timedatectl set-timezone Europe/Moscow + fi {{ end -}} new_line "Installing shell-gpt" @@ -270,7 +326,7 @@ pipx install shell-gpt 2>&1|pad new_line "Install fisher plugin manager for fish" ## Install fisher plugin manager for fish, so that we may update in after plugin list sync by chezmoi -if ! fish -c fisher &>/dev/null +if ! fish -c "type -q fisher" &>/dev/null then fish -c "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher update" 2>&1|pad fi