Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#!/bin/sh
# Lattice installer
# Usage: curl -fsSL https://forkzero.ai/lattice/install.sh | sh
#
# Environment variables:
# INSTALL_DIR Override install location (default: ~/.local/bin)
# VERSION Install a specific version (default: latest)

set -e

REPO="forkzero/lattice"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"

# Default to ~/.local/bin (user-writable, no sudo needed)
if [ -z "$INSTALL_DIR" ]; then
if [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
fi
fi

# Detect OS
OS="$(uname -s)"
Expand Down Expand Up @@ -65,6 +77,9 @@ fi
echo "Extracting..."
tar -xzf "$ARCHIVE"

# Ensure install directory exists
mkdir -p "$INSTALL_DIR"

# Install
BINARY_DIR="lattice-${VERSION}-${TARGET}"
if [ -w "$INSTALL_DIR" ]; then
Expand All @@ -74,6 +89,23 @@ else
sudo mv "${BINARY_DIR}/lattice" "$INSTALL_DIR/"
fi

# Check if install dir is in PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "Add ${INSTALL_DIR} to your PATH:"
SHELL_NAME="$(basename "$SHELL")"
case "$SHELL_NAME" in
zsh) echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.zshrc && source ~/.zshrc" ;;
bash) echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.bashrc && source ~/.bashrc" ;;
fish) echo " fish_add_path ${INSTALL_DIR}" ;;
*) echo " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;;
esac
echo ""
;;
esac

# Verify
if command -v lattice > /dev/null 2>&1; then
echo ""
Expand All @@ -82,8 +114,9 @@ if command -v lattice > /dev/null 2>&1; then
echo "Get started:"
echo " lattice init # Initialize a lattice"
echo " lattice --help # Show all commands"
echo " lattice help concepts # Learn the domain model"
else
echo ""
echo "Installed to ${INSTALL_DIR}/lattice"
echo "Add ${INSTALL_DIR} to your PATH if not already present."
echo "Make sure ${INSTALL_DIR} is in your PATH."
fi
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4445,7 +4445,9 @@ fn run_command(command: Commands) {
(
format!("Permission denied — cannot write to {}", exe),
if cfg!(unix) {
Some("Run with sudo: sudo lattice update")
Some(
"Reinstall to ~/.local/bin for sudo-free updates:\n INSTALL_DIR=~/.local/bin curl -fsSL https://forkzero.ai/lattice/install.sh | sh\nOr run: sudo lattice update",
)
} else {
None
},
Expand Down
19 changes: 10 additions & 9 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,16 @@ fn write_check_state(path: &std::path::Path, state: &UpdateCheckState) {
.and_then(|json| std::fs::write(path, json).ok());
}

fn print_update_notice(latest: &Version) {
fn print_update_notice(current: &Version, latest: &Version) {
eprintln!();
eprintln!(
"{}",
format!(
"A new version of lattice is available (v{}). Run 'lattice update' to install.",
latest
)
.dimmed()
" {} {} → {}",
"Update available:".yellow().bold(),
format!("v{}", current).dimmed(),
format!("v{}", latest).green().bold()
);
eprintln!(" Run {} to install", "lattice update".cyan());
eprintln!();
}

/// Print a one-line update notice to stderr if a newer version is available.
Expand Down Expand Up @@ -420,7 +421,7 @@ pub fn maybe_notify_update(command_name: Option<&str>) {
if let Ok(latest) = Version::parse(&state.latest_version)
&& latest > current
{
print_update_notice(&latest);
print_update_notice(&current, &latest);
}
return;
}
Expand Down Expand Up @@ -449,7 +450,7 @@ pub fn maybe_notify_update(command_name: Option<&str>) {
},
);
if latest > current {
print_update_notice(&latest);
print_update_notice(&current, &latest);
}
}
Err(_) => {
Expand Down
Loading