-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_onchange_install-packages.sh.tmpl
More file actions
109 lines (96 loc) · 4.88 KB
/
run_onchange_install-packages.sh.tmpl
File metadata and controls
109 lines (96 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# Install packages (runs when Brewfile or Pacfile changes)
# chezmoi:template:hash {{ if eq .chezmoi.os "darwin" }}{{ include "Brewfile" | sha256sum }}{{ else if eq .chezmoi.os "linux" }}{{ include "Pacfile" | sha256sum }}{{ end }}
# =============================================================================
{{ if eq .chezmoi.os "darwin" -}}
echo "[packages] Installing Homebrew packages..."
if command -v brew &>/dev/null; then
brew bundle install --file="{{ .chezmoi.sourceDir }}/Brewfile" 2>&1 | sed 's/^/ /'
else
echo " WARNING: Homebrew not installed. Install from https://brew.sh/"
fi
# Install LiteLLM proxy via pipx.
# WHY pipx: isolates litellm and its heavy dependency tree from the system Python.
# WHY python3.13: litellm's grpcio wheel is prebuilt for 3.13 on macOS arm64;
# older Python versions require a source build that fails without Xcode headers.
# WHY google-cloud-aiplatform inject: litellm's [proxy] extra does not pull in the
# Vertex AI SDK automatically; it is required for Claude models via Vertex.
# IDEMPOTENT: only installs if litellm is not already listed by pipx.
if command -v pipx &>/dev/null; then
if ! pipx list --short 2>/dev/null | grep -q '^litellm '; then
echo "[packages] Installing litellm proxy..."
pipx install 'litellm[proxy]' --python python3.13 2>&1 | sed 's/^/ /'
pipx inject litellm 'google-cloud-aiplatform>=1.38' 2>&1 | sed 's/^/ /'
fi
# Patch LiteLLM to drop top_p when temperature is also present for Vertex Claude models.
# Vertex AI rejects requests specifying both parameters, and AI-SDK passes both by default.
LITELLM_TRANSFORM="$HOME/.local/pipx/venvs/litellm/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py"
if [ -f "$LITELLM_TRANSFORM" ]; then
if ! grep -q 'data.pop("top_p", None)' "$LITELLM_TRANSFORM"; then
echo " [packages] Patching LiteLLM Vertex AI transformation to drop top_p..."
sed -i '' 's/data\.pop("output_format", None)/data.pop("output_format", None)\n if "temperature" in data and "top_p" in data:\n data.pop("top_p", None)/' "$LITELLM_TRANSFORM"
fi
fi
else
echo " WARNING: pipx not found. Install litellm manually: pipx install 'litellm[proxy]'"
fi
# Ensure the log directory exists before launchd starts the service.
# Logs: stdout → proxy.log, stderr → proxy.err (configured in the plist).
mkdir -p "$HOME/.local/share/litellm"
# (Re)load the LiteLLM launchd service so config changes take effect immediately.
# The plist is deployed by chezmoi to ~/Library/LaunchAgents/ and starts the proxy
# at login. We unload first (|| true so it does not fail on first-ever install)
# then reload to pick up any updated config.yaml or plist changes.
if [ -f "$HOME/Library/LaunchAgents/com.litellm.proxy.plist" ]; then
launchctl unload "$HOME/Library/LaunchAgents/com.litellm.proxy.plist" 2>/dev/null || true
launchctl load "$HOME/Library/LaunchAgents/com.litellm.proxy.plist" 2>&1 | sed 's/^/ /'
echo "[packages] LiteLLM proxy service loaded."
fi
{{ else if eq .chezmoi.os "linux" -}}
echo "[packages] Installing Arch Linux packages from Pacfile..."
PACFILE="{{ .chezmoi.sourceDir }}/Pacfile"
if [ ! -f "$PACFILE" ]; then
echo " ERROR: Pacfile not found at $PACFILE"
exit 1
fi
# Parse Pacfile: strip comments and blank lines
PACKAGES=$(grep -v '^#' "$PACFILE" | grep -v '^$' | tr '\n' ' ')
if [ -z "$PACKAGES" ]; then
echo " No packages to install."
exit 0
fi
# Refresh package database first (avoids stale mirror 404 errors)
echo " Refreshing package database..."
sudo pacman -Sy 2>&1 | sed 's/^/ /'
# Ensure required locales are generated to prevent perl warnings
echo " Ensuring locales are generated..."
if grep -q '^#en_GB.UTF-8 UTF-8' /etc/locale.gen 2>/dev/null; then
sudo sed -i 's/^#en_GB.UTF-8 UTF-8/en_GB.UTF-8 UTF-8/' /etc/locale.gen
LOCALE_CHANGED=1
fi
if grep -q '^#it_IT.UTF-8 UTF-8' /etc/locale.gen 2>/dev/null; then
sudo sed -i 's/^#it_IT.UTF-8 UTF-8/it_IT.UTF-8 UTF-8/' /etc/locale.gen
LOCALE_CHANGED=1
fi
if [ "${LOCALE_CHANGED:-0}" -eq 1 ]; then
sudo locale-gen 2>&1 | sed 's/^/ /'
fi
if command -v yay &>/dev/null; then
# yay handles both official repos and AUR
# --needed skips already-installed packages
# --noconfirm avoids interactive prompts
echo " Using yay (official + AUR)..."
yay -S --needed --noconfirm $PACKAGES 2>&1 | sed 's/^/ /'
elif command -v pacman &>/dev/null; then
# Fallback to pacman (official repos only -- AUR packages will fail)
echo " WARNING: yay not found, using pacman (AUR packages will be skipped)."
echo " Install yay first: https://github.com/Jguer/yay"
sudo pacman -S --needed --noconfirm $PACKAGES 2>&1 | sed 's/^/ /' || true
else
echo " ERROR: Neither yay nor pacman found. Is this Arch Linux?"
exit 1
fi
echo " Done."
{{ end -}}