refactor(install): improve modular architecture and error handling

- Remove redundant installation checks in arduino.sh, git.sh
- Add bash shell enforcement in install.sh to prevent compatibility issues
- Streamline Arduino CLI installation logic for both Arch and other systems
- Improve Git and Lazygit installation messaging consistency
- Update install usage instructions for better clarity
- Enhance shell compatibility by enforcing bash execution
This commit is contained in:
marvin.dietermann
2026-04-10 11:51:03 +02:00
parent ee0b7f5009
commit 040839862d
9 changed files with 125 additions and 69 deletions

View File

@@ -3,12 +3,10 @@
step "7/9 — Installing Arduino CLI + board cores"
if ! command -v arduino-cli &>/dev/null; then
if $IS_ARCH; then
$PKG_INSTALL arduino-cli
else
curl -kfsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sudo sh
fi
if $IS_ARCH; then
$PKG_INSTALL arduino-cli
else
curl -kfsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sudo sh
fi
info "Arduino CLI installed: $(arduino-cli version 2>/dev/null | head -1)"
@@ -22,15 +20,19 @@ arduino-cli config add board_manager.additional_urls \
arduino-cli core update-index
info "Installing AVR core..."
info "Installing/updating AVR core..."
arduino-cli core install arduino:avr
info "Installing ESP32 core..."
info "Installing/updating ESP32 core..."
arduino-cli core install esp32:esp32
info "Installing ESP8266 core..."
info "Installing/updating ESP8266 core..."
arduino-cli core install esp8266:esp8266
# Common libs
# Upgrade all installed cores to latest
arduino-cli core upgrade
# Common libs (install is idempotent, upgrade updates them)
arduino-cli lib install "Servo" "ArduinoJson" "Adafruit Unified Sensor" "DHT sensor library" 2>/dev/null || true
info "Board cores & libraries installed"
arduino-cli lib upgrade 2>/dev/null || true
info "Board cores & libraries installed/updated"

View File

@@ -67,6 +67,17 @@ end_quiet_mode() {
echo ""
}
# ── Config backup helper ─────────────────────────────────────────
BACKUP_DIR="$HOME/.config/archduino/backups/$(date +%Y%m%d_%H%M%S)"
backup_config() {
local src="$1"
[[ ! -e "$src" ]] && return 0
mkdir -p "$BACKUP_DIR"
cp -a "$src" "$BACKUP_DIR/"
info "Backed up $(basename "$src") → $BACKUP_DIR/"
}
# ── Detect environment ──────────────────────────────────────────
IS_WSL=false
[[ -f /proc/version ]] && grep -qi microsoft /proc/version && IS_WSL=true

View File

@@ -3,18 +3,17 @@
step "8/9 — Setting up Git + Lazygit"
if ! command -v lazygit &>/dev/null; then
if $IS_ARCH; then
$PKG_INSTALL lazygit
else
LAZYGIT_VERSION=$(curl -ks "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | jq -r '.tag_name' | sed 's/v//')
curl -kLo /tmp/lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf /tmp/lazygit.tar.gz -C /tmp lazygit
sudo mv /tmp/lazygit /usr/local/bin/
fi
if $IS_ARCH; then
$PKG_INSTALL lazygit
else
LAZYGIT_VERSION=$(curl -ks "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | jq -r '.tag_name' | sed 's/v//')
curl -kLo /tmp/lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf /tmp/lazygit.tar.gz -C /tmp lazygit
sudo mv /tmp/lazygit /usr/local/bin/
fi
info "Lazygit installed"
info "Lazygit installed/updated"
mkdir -p ~/.config/lazygit
backup_config ~/.config/lazygit/config.yml
write_lazygit_config ~/.config/lazygit/config.yml
info "Lazygit configured with $THEME_DISPLAY_NAME"

View File

@@ -23,21 +23,54 @@ fi
step "6/9 — Setting up NvChad"
if [[ ! -d "$HOME/.config/nvim/lua" ]]; then
for d in ~/.config/nvim ~/.local/share/nvim ~/.local/state/nvim ~/.cache/nvim; do
[[ -d "$d" ]] && mv "$d" "${d}.bak.$(date +%s)"
done
git clone https://github.com/NvChad/starter ~/.config/nvim
rm -rf ~/.config/nvim/.git
info "NvChad starter cloned"
NVIM_CFG="$HOME/.config/nvim"
NVCHAD_FRESH=false
# ── Detect existing config ──────────────────────────────────────
if [[ -d "$NVIM_CFG/lua" ]]; then
if [[ -f "$NVIM_CFG/lua/chadrc.lua" ]]; then
# NvChad detected — update in place
info "Existing NvChad config detected, updating..."
elif grep -rq "LazyVim" "$NVIM_CFG/lua/" 2>/dev/null || [[ -f "$NVIM_CFG/lazyvim.json" ]]; then
# LazyVim detected — migrate to NvChad
warn "LazyVim config detected, migrating to NvChad..."
for d in "$NVIM_CFG" ~/.local/share/nvim ~/.local/state/nvim ~/.cache/nvim; do
if [[ -d "$d" ]]; then
backup_config "$d"
rm -rf "$d"
fi
done
NVCHAD_FRESH=true
else
# Unknown config — back up and install fresh
warn "Unknown Neovim config detected, backing up..."
for d in "$NVIM_CFG" ~/.local/share/nvim ~/.local/state/nvim ~/.cache/nvim; do
if [[ -d "$d" ]]; then
backup_config "$d"
rm -rf "$d"
fi
done
NVCHAD_FRESH=true
fi
else
info "Neovim config already exists, skipping NvChad clone"
# No config at all — fresh install
NVCHAD_FRESH=true
fi
# ── Theme ───────────────────────────────────────────────────────
mkdir -p ~/.config/nvim/lua
if $NVCHAD_FRESH; then
git clone https://github.com/NvChad/starter "$NVIM_CFG"
rm -rf "$NVIM_CFG/.git"
info "NvChad starter cloned"
fi
cat >~/.config/nvim/lua/chadrc.lua <<EOF
# ── Clear NvChad theme cache so the new theme takes effect ──────
rm -rf ~/.local/share/nvim/lazy/base46/lua/base46/themes 2>/dev/null || true
rm -rf ~/.cache/nvim/base46 2>/dev/null || true
# ── Theme ───────────────────────────────────────────────────────
mkdir -p "$NVIM_CFG/lua"
cat >"$NVIM_CFG/lua/chadrc.lua" <<EOF
---@type ChadrcConfig
local M = {}
@@ -49,9 +82,9 @@ return M
EOF
# ── Arduino plugin ──────────────────────────────────────────────
mkdir -p ~/.config/nvim/lua/plugins
mkdir -p "$NVIM_CFG/lua/plugins"
cat >~/.config/nvim/lua/plugins/arduino.lua <<'LUA'
cat >"$NVIM_CFG/lua/plugins/arduino.lua" <<'LUA'
return {
{
"stevearc/vim-arduino",
@@ -65,9 +98,9 @@ return {
LUA
# ── LSP (clangd) ───────────────────────────────────────────────
mkdir -p ~/.config/nvim/lua/configs
mkdir -p "$NVIM_CFG/lua/configs"
cat >~/.config/nvim/lua/configs/lspconfig.lua <<'LUA'
cat >"$NVIM_CFG/lua/configs/lspconfig.lua" <<'LUA'
local configs = require "nvchad.configs.lspconfig"
local on_attach = configs.on_attach
@@ -91,7 +124,7 @@ lspconfig.clangd.setup {
LUA
# ── Keymaps ─────────────────────────────────────────────────────
cat >~/.config/nvim/lua/mappings.lua <<'LUA'
cat >"$NVIM_CFG/lua/mappings.lua" <<'LUA'
require "nvchad.mappings"
local map = vim.keymap.set

View File

@@ -3,11 +3,7 @@
step "Finalizing shell config"
# Append archduino block to .zshrc if not already present
if ! grep -q "ARCHDUINO" ~/.zshrc 2>/dev/null; then
cat >>~/.zshrc <<'ZSHRC'
# ── ARCHDUINO CONFIG ────────────────────────────────────────────
ZSHRC_BLOCK='# ── ARCHDUINO CONFIG ────────────────────────────────────────────
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
export PATH="$HOME/.local/bin:$PATH"
@@ -30,11 +26,21 @@ alias acm="arduino-cli monitor"
alias acb="arduino-cli board list"
alias lg="lazygit"
alias v="nvim"
# ── END ARCHDUINO ───────────────────────────────────────────────
ZSHRC
info "Shell config updated"
# ── END ARCHDUINO ───────────────────────────────────────────────'
if grep -q "ARCHDUINO CONFIG" ~/.zshrc 2>/dev/null; then
# Update: replace existing block
backup_config ~/.zshrc
# Remove old block and write new one
sed -i '/^# ── ARCHDUINO CONFIG/,/^# ── END ARCHDUINO/d' ~/.zshrc
echo "" >> ~/.zshrc
echo "$ZSHRC_BLOCK" >> ~/.zshrc
info "Shell config updated (replaced Archduino block)"
else
info "Shell config already contains Archduino block"
# Fresh install: append block
echo "" >> ~/.zshrc
echo "$ZSHRC_BLOCK" >> ~/.zshrc
info "Shell config updated"
fi
# ── WSL2 extras ─────────────────────────────────────────────────

View File

@@ -3,15 +3,14 @@
step "3/9 — Installing Starship"
if ! command -v starship &>/dev/null; then
if $IS_ARCH; then
$PKG_INSTALL starship
else
curl -ksS https://starship.rs/install.sh | sh -s -- -y
fi
if $IS_ARCH; then
$PKG_INSTALL starship
else
curl -ksS https://starship.rs/install.sh | sh -s -- -y
fi
info "Starship installed"
info "Starship installed/updated"
mkdir -p ~/.config
backup_config ~/.config/starship.toml
write_starship_config ~/.config/starship.toml
info "Starship configured with $THEME_DISPLAY_NAME"

View File

@@ -3,17 +3,16 @@
step "4/9 — Installing Zellij"
if ! command -v zellij &>/dev/null; then
if $IS_ARCH; then
$PKG_INSTALL zellij
else
curl -kL https://github.com/zellij-org/zellij/releases/latest/download/zellij-x86_64-unknown-linux-musl.tar.gz | tar xz -C /tmp
sudo mv /tmp/zellij /usr/local/bin/
fi
if $IS_ARCH; then
$PKG_INSTALL zellij
else
curl -kL https://github.com/zellij-org/zellij/releases/latest/download/zellij-x86_64-unknown-linux-musl.tar.gz | tar xz -C /tmp
sudo mv /tmp/zellij /usr/local/bin/
fi
info "Zellij installed"
info "Zellij installed/updated"
mkdir -p ~/.config/zellij/layouts
backup_config ~/.config/zellij/config.kdl
write_zellij_config ~/.config/zellij/config.kdl
cat >~/.config/zellij/layouts/arduino.kdl <<'LAYOUT'

View File

@@ -13,10 +13,12 @@ fi
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
[[ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]] &&
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
for plugin in zsh-autosuggestions zsh-syntax-highlighting; do
if [[ ! -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
git clone "https://github.com/zsh-users/$plugin" "$ZSH_CUSTOM/plugins/$plugin"
else
git -C "$ZSH_CUSTOM/plugins/$plugin" pull --quiet 2>/dev/null || true
fi
done
[[ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]] &&
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
info "Zsh plugins installed"
info "Zsh plugins installed/updated"