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:
@@ -3,10 +3,15 @@
|
|||||||
# Archduino Install — TUI Arduino Development Environment
|
# Archduino Install — TUI Arduino Development Environment
|
||||||
# Works on both native Arch Linux and Arch/Ubuntu WSL2
|
# Works on both native Arch Linux and Arch/Ubuntu WSL2
|
||||||
#
|
#
|
||||||
# Usage: curl -kL <url> | bash
|
# Usage: chmod +x install.sh && ./install.sh
|
||||||
# or: chmod +x install.sh && ./install.sh
|
# or: bash install.sh
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Re-exec with bash if invoked via sh/dash
|
||||||
|
if [ -z "$BASH_VERSION" ]; then
|
||||||
|
exec bash "$0" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# ── Load helpers and detect environment ─────────────────────────
|
# ── Load helpers and detect environment ─────────────────────────
|
||||||
|
|||||||
@@ -3,12 +3,10 @@
|
|||||||
|
|
||||||
step "7/9 — Installing Arduino CLI + board cores"
|
step "7/9 — Installing Arduino CLI + board cores"
|
||||||
|
|
||||||
if ! command -v arduino-cli &>/dev/null; then
|
if $IS_ARCH; then
|
||||||
if $IS_ARCH; then
|
|
||||||
$PKG_INSTALL arduino-cli
|
$PKG_INSTALL arduino-cli
|
||||||
else
|
else
|
||||||
curl -kfsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sudo sh
|
curl -kfsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sudo sh
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
info "Arduino CLI installed: $(arduino-cli version 2>/dev/null | head -1)"
|
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
|
arduino-cli core update-index
|
||||||
|
|
||||||
info "Installing AVR core..."
|
info "Installing/updating AVR core..."
|
||||||
arduino-cli core install arduino:avr
|
arduino-cli core install arduino:avr
|
||||||
|
|
||||||
info "Installing ESP32 core..."
|
info "Installing/updating ESP32 core..."
|
||||||
arduino-cli core install esp32:esp32
|
arduino-cli core install esp32:esp32
|
||||||
|
|
||||||
info "Installing ESP8266 core..."
|
info "Installing/updating ESP8266 core..."
|
||||||
arduino-cli core install esp8266:esp8266
|
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
|
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"
|
||||||
|
|||||||
@@ -67,6 +67,17 @@ end_quiet_mode() {
|
|||||||
echo ""
|
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 ──────────────────────────────────────────
|
# ── Detect environment ──────────────────────────────────────────
|
||||||
IS_WSL=false
|
IS_WSL=false
|
||||||
[[ -f /proc/version ]] && grep -qi microsoft /proc/version && IS_WSL=true
|
[[ -f /proc/version ]] && grep -qi microsoft /proc/version && IS_WSL=true
|
||||||
|
|||||||
@@ -3,18 +3,17 @@
|
|||||||
|
|
||||||
step "8/9 — Setting up Git + Lazygit"
|
step "8/9 — Setting up Git + Lazygit"
|
||||||
|
|
||||||
if ! command -v lazygit &>/dev/null; then
|
if $IS_ARCH; then
|
||||||
if $IS_ARCH; then
|
|
||||||
$PKG_INSTALL lazygit
|
$PKG_INSTALL lazygit
|
||||||
else
|
else
|
||||||
LAZYGIT_VERSION=$(curl -ks "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | jq -r '.tag_name' | sed 's/v//')
|
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"
|
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
|
tar xf /tmp/lazygit.tar.gz -C /tmp lazygit
|
||||||
sudo mv /tmp/lazygit /usr/local/bin/
|
sudo mv /tmp/lazygit /usr/local/bin/
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
info "Lazygit installed"
|
info "Lazygit installed/updated"
|
||||||
|
|
||||||
mkdir -p ~/.config/lazygit
|
mkdir -p ~/.config/lazygit
|
||||||
|
backup_config ~/.config/lazygit/config.yml
|
||||||
write_lazygit_config ~/.config/lazygit/config.yml
|
write_lazygit_config ~/.config/lazygit/config.yml
|
||||||
info "Lazygit configured with $THEME_DISPLAY_NAME"
|
info "Lazygit configured with $THEME_DISPLAY_NAME"
|
||||||
|
|||||||
@@ -23,21 +23,54 @@ fi
|
|||||||
|
|
||||||
step "6/9 — Setting up NvChad"
|
step "6/9 — Setting up NvChad"
|
||||||
|
|
||||||
if [[ ! -d "$HOME/.config/nvim/lua" ]]; then
|
NVIM_CFG="$HOME/.config/nvim"
|
||||||
for d in ~/.config/nvim ~/.local/share/nvim ~/.local/state/nvim ~/.cache/nvim; do
|
NVCHAD_FRESH=false
|
||||||
[[ -d "$d" ]] && mv "$d" "${d}.bak.$(date +%s)"
|
|
||||||
|
# ── 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
|
done
|
||||||
git clone https://github.com/NvChad/starter ~/.config/nvim
|
NVCHAD_FRESH=true
|
||||||
rm -rf ~/.config/nvim/.git
|
else
|
||||||
info "NvChad starter cloned"
|
# 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
|
else
|
||||||
info "Neovim config already exists, skipping NvChad clone"
|
# No config at all — fresh install
|
||||||
|
NVCHAD_FRESH=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Theme ───────────────────────────────────────────────────────
|
if $NVCHAD_FRESH; then
|
||||||
mkdir -p ~/.config/nvim/lua
|
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
|
---@type ChadrcConfig
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -49,9 +82,9 @@ return M
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# ── Arduino plugin ──────────────────────────────────────────────
|
# ── 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 {
|
return {
|
||||||
{
|
{
|
||||||
"stevearc/vim-arduino",
|
"stevearc/vim-arduino",
|
||||||
@@ -65,9 +98,9 @@ return {
|
|||||||
LUA
|
LUA
|
||||||
|
|
||||||
# ── LSP (clangd) ───────────────────────────────────────────────
|
# ── 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 configs = require "nvchad.configs.lspconfig"
|
||||||
|
|
||||||
local on_attach = configs.on_attach
|
local on_attach = configs.on_attach
|
||||||
@@ -91,7 +124,7 @@ lspconfig.clangd.setup {
|
|||||||
LUA
|
LUA
|
||||||
|
|
||||||
# ── Keymaps ─────────────────────────────────────────────────────
|
# ── Keymaps ─────────────────────────────────────────────────────
|
||||||
cat >~/.config/nvim/lua/mappings.lua <<'LUA'
|
cat >"$NVIM_CFG/lua/mappings.lua" <<'LUA'
|
||||||
require "nvchad.mappings"
|
require "nvchad.mappings"
|
||||||
|
|
||||||
local map = vim.keymap.set
|
local map = vim.keymap.set
|
||||||
|
|||||||
@@ -3,11 +3,7 @@
|
|||||||
|
|
||||||
step "Finalizing shell config"
|
step "Finalizing shell config"
|
||||||
|
|
||||||
# Append archduino block to .zshrc if not already present
|
ZSHRC_BLOCK='# ── ARCHDUINO CONFIG ────────────────────────────────────────────
|
||||||
if ! grep -q "ARCHDUINO" ~/.zshrc 2>/dev/null; then
|
|
||||||
cat >>~/.zshrc <<'ZSHRC'
|
|
||||||
|
|
||||||
# ── ARCHDUINO CONFIG ────────────────────────────────────────────
|
|
||||||
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
|
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
|
||||||
|
|
||||||
export PATH="$HOME/.local/bin:$PATH"
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
@@ -30,11 +26,21 @@ alias acm="arduino-cli monitor"
|
|||||||
alias acb="arduino-cli board list"
|
alias acb="arduino-cli board list"
|
||||||
alias lg="lazygit"
|
alias lg="lazygit"
|
||||||
alias v="nvim"
|
alias v="nvim"
|
||||||
# ── END ARCHDUINO ───────────────────────────────────────────────
|
# ── END ARCHDUINO ───────────────────────────────────────────────'
|
||||||
ZSHRC
|
|
||||||
info "Shell config updated"
|
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
|
else
|
||||||
info "Shell config already contains Archduino block"
|
# Fresh install: append block
|
||||||
|
echo "" >> ~/.zshrc
|
||||||
|
echo "$ZSHRC_BLOCK" >> ~/.zshrc
|
||||||
|
info "Shell config updated"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── WSL2 extras ─────────────────────────────────────────────────
|
# ── WSL2 extras ─────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -3,15 +3,14 @@
|
|||||||
|
|
||||||
step "3/9 — Installing Starship"
|
step "3/9 — Installing Starship"
|
||||||
|
|
||||||
if ! command -v starship &>/dev/null; then
|
if $IS_ARCH; then
|
||||||
if $IS_ARCH; then
|
|
||||||
$PKG_INSTALL starship
|
$PKG_INSTALL starship
|
||||||
else
|
else
|
||||||
curl -ksS https://starship.rs/install.sh | sh -s -- -y
|
curl -ksS https://starship.rs/install.sh | sh -s -- -y
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
info "Starship installed"
|
info "Starship installed/updated"
|
||||||
|
|
||||||
mkdir -p ~/.config
|
mkdir -p ~/.config
|
||||||
|
backup_config ~/.config/starship.toml
|
||||||
write_starship_config ~/.config/starship.toml
|
write_starship_config ~/.config/starship.toml
|
||||||
info "Starship configured with $THEME_DISPLAY_NAME"
|
info "Starship configured with $THEME_DISPLAY_NAME"
|
||||||
|
|||||||
@@ -3,17 +3,16 @@
|
|||||||
|
|
||||||
step "4/9 — Installing Zellij"
|
step "4/9 — Installing Zellij"
|
||||||
|
|
||||||
if ! command -v zellij &>/dev/null; then
|
if $IS_ARCH; then
|
||||||
if $IS_ARCH; then
|
|
||||||
$PKG_INSTALL zellij
|
$PKG_INSTALL zellij
|
||||||
else
|
else
|
||||||
curl -kL https://github.com/zellij-org/zellij/releases/latest/download/zellij-x86_64-unknown-linux-musl.tar.gz | tar xz -C /tmp
|
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/
|
sudo mv /tmp/zellij /usr/local/bin/
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
info "Zellij installed"
|
info "Zellij installed/updated"
|
||||||
|
|
||||||
mkdir -p ~/.config/zellij/layouts
|
mkdir -p ~/.config/zellij/layouts
|
||||||
|
backup_config ~/.config/zellij/config.kdl
|
||||||
write_zellij_config ~/.config/zellij/config.kdl
|
write_zellij_config ~/.config/zellij/config.kdl
|
||||||
|
|
||||||
cat >~/.config/zellij/layouts/arduino.kdl <<'LAYOUT'
|
cat >~/.config/zellij/layouts/arduino.kdl <<'LAYOUT'
|
||||||
|
|||||||
14
lib/zsh.sh
14
lib/zsh.sh
@@ -13,10 +13,12 @@ fi
|
|||||||
|
|
||||||
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
|
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
|
||||||
|
|
||||||
[[ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]] &&
|
for plugin in zsh-autosuggestions zsh-syntax-highlighting; do
|
||||||
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
|
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" ]] &&
|
info "Zsh plugins installed/updated"
|
||||||
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
|
|
||||||
|
|
||||||
info "Zsh plugins installed"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user