install.sh: updates an existing install, asks on the terminal, no pacman -Sy

- finds an existing install and its version (the commit, recorded in share/summit/installed-version); rebuilds
  only when the source changed (--force always); an update replaces the engine's files but keeps its venv and
  models, and reuses the venv (uv 0.13 refuses 'uv venv' on an existing one, so a second run used to fail)
- questions are read from /dev/tty: under 'curl | sh' stdin is the script itself
- Arch: only missing packages are installed (pacman -T), without 'pacman -Sy' (a partial upgrade)
- sudo only when the prefix isn't writable; SUMMIT_REPO for testing
This commit is contained in:
alex committed 2026-11-24 17:12:17 +00:00
1 parent bcc03bd311
commit b282334af3
1 file changed
+114 -27
+114 -27
View File
@@ -9,8 +9,12 @@
# Python virtualenv (uv, Python 3.12, CUDA 12.8 torch only if an NVIDIA GPU
# is present).
#
# Run it again to update: it finds the existing install, says which version it has and which it gets, rebuilds
# only when the source changed, keeps the engine's venv (adding what new requirements need) and your data.
#
# Flags:
# --yes, -y don't ask before sudo steps
# --force rebuild and reinstall even when the installed version is the newest
# --dry-run print what would happen, change nothing
# --uninstall remove what this installer installed
# --help, -h show this message
@@ -18,11 +22,12 @@
# Environment:
# SUMMIT_PREFIX where to install (default /usr/local)
# SUMMIT_SRC_DIR build this checkout as it is (no clone, no git pull)
# SUMMIT_REPO clone and update from this git URL instead (testing)
set -eu
REPO_API="https://git.molberg.cloud/api/v1/repos/alex/summit"
REPO_GIT="https://git.molberg.cloud/alex/summit.git"
REPO_GIT="${SUMMIT_REPO:-https://git.molberg.cloud/alex/summit.git}"
PREFIX="${SUMMIT_PREFIX:-/usr/local}"
SHARE_DIR="$PREFIX/share/summit"
BIN_DIR="$PREFIX/bin"
@@ -31,6 +36,7 @@ APPS_DIR="$PREFIX/share/applications"
ICON_DIR="$PREFIX/share/icons/hicolor/64x64/apps"
ASSUME_YES=0
FORCE=0
DRY_RUN=0
UNINSTALL=0
@@ -46,6 +52,19 @@ run() {
fi
}
# Questions are read from the terminal: under `curl ... | sh` the script itself is on stdin.
ask() {
printf '%s [y/N] ' "$1"
if [ -r /dev/tty ] && reply="$(head -n 1 < /dev/tty 2>/dev/null)"; then :; else
printf '\n'
die "no terminal to ask on: run again with --yes"
fi
case "$reply" in
y|Y|yes|YES) return 0 ;;
*) return 1 ;;
esac
}
run_sudo() {
if [ "$(id -u)" -eq 0 ]; then
run "$@"
@@ -53,18 +72,23 @@ run_sudo() {
fi
if [ "$ASSUME_YES" -eq 0 ] && [ "$DRY_RUN" -eq 0 ]; then
printf ' needs sudo: %s\n' "$*"
printf ' proceed? [y/N] '
read -r reply
case "$reply" in
y|Y|yes|YES) ;;
*) die "aborted before: $*" ;;
esac
ask ' proceed?' || die "aborted before: $*"
fi
run sudo "$@"
}
# Files into the prefix: sudo only when it isn't writable (/usr/local is not; ~/.local is).
prefix_writable() { [ -w "$PREFIX" ] || { [ ! -e "$PREFIX" ] && [ -w "$(dirname "$PREFIX")" ]; }; }
run_prefix() {
if prefix_writable; then
run "$@"
else
run_sudo "$@"
fi
}
usage() {
sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'
sed -n '2,/^set -eu/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//'
}
# Tools Summit calls at run time. A missing one only disables a feature, so a failure here warns instead of
@@ -75,6 +99,7 @@ RUNTIME_TOOLS="ffmpeg xrandr xdg-open zenity"
for arg in "$@"; do
case "$arg" in
--yes|-y) ASSUME_YES=1 ;;
--force) FORCE=1 ;;
--dry-run) DRY_RUN=1 ;;
--uninstall) UNINSTALL=1 ;;
--help|-h) usage; exit 0 ;;
@@ -161,7 +186,15 @@ install_dependencies() {
step "Installing build and runtime dependencies for $DISTRO_FAMILY"
case "$DISTRO_FAMILY" in
arch)
run_sudo pacman -Sy --needed --noconfirm base-devel git curl pkgconf fontconfig
# Only what is missing (pacman -T needs no root), and no `pacman -Sy` without -u: on Arch that is a partial
# upgrade. If a package isn't in the local sync database, pacman says so: run `sudo pacman -Syu` first.
build_missing="$(pacman -T base-devel git curl pkgconf fontconfig 2>/dev/null || true)"
if [ -n "$build_missing" ]; then
# shellcheck disable=SC2086
run_sudo pacman -S --needed --noconfirm $build_missing
else
log " build tools: all there"
fi
runtime="ffmpeg xorg-xrandr xdg-utils zenity"
;;
debian)
@@ -198,7 +231,14 @@ install_dependencies() {
step "Installing the tools Summit runs (a failure here only disables a feature)"
# shellcheck disable=SC2086
case "$DISTRO_FAMILY" in
arch) run_sudo pacman -S --needed --noconfirm $runtime || log " warning: could not install: $runtime" ;;
arch)
runtime="$(pacman -T $runtime 2>/dev/null || true)"
if [ -n "$runtime" ]; then
run_sudo pacman -S --needed --noconfirm $runtime || log " warning: could not install: $runtime"
else
log " all there"
fi
;;
debian) run_sudo apt-get install -y $runtime || log " warning: could not install: $runtime" ;;
fedora) run_sudo dnf install -y $runtime || log " warning: could not install: $runtime" ;;
opensuse) run_sudo zypper install -y $runtime || log " warning: could not install: $runtime" ;;
@@ -287,6 +327,30 @@ install_native_package() {
esac
}
# What is installed already: the commit it was built from (written by this script since the Wayland update; older
# installs only have the binaries), or nothing.
VERSION_FILE="$SHARE_DIR/installed-version"
installed_version() {
if [ -f "$VERSION_FILE" ]; then
head -n 1 "$VERSION_FILE"
elif [ -x "$BIN_DIR/summit" ]; then
printf 'unknown (installed before versions were recorded)\n'
fi
}
detect_existing() {
INSTALLED="$(installed_version)"
if [ -n "$INSTALLED" ]; then
log " existing : Summit in $BIN_DIR, version $INSTALLED: this run updates it"
else
log " existing : none in $BIN_DIR"
fi
other="$(command -v summit 2>/dev/null || true)"
if [ -n "$other" ] && [ "$other" != "$BIN_DIR/summit" ]; then
log " note : another summit is on PATH at $other (a different SUMMIT_PREFIX?); it is left alone"
fi
}
build_from_source() {
step "No usable release package found, building from source"
ensure_rust
@@ -301,30 +365,52 @@ build_from_source() {
run mkdir -p "$(dirname "$SRC_DIR")"
run git clone "$REPO_GIT" "$SRC_DIR"
fi
NEW_VERSION="local checkout"
if git -C "$SRC_DIR" rev-parse --git-dir >/dev/null 2>&1; then
NEW_VERSION="$(git -C "$SRC_DIR" log -1 --format='%h (%cs)' 2>/dev/null || echo unknown)"
if [ -n "$(git -C "$SRC_DIR" status --porcelain 2>/dev/null)" ]; then NEW_VERSION="$NEW_VERSION + local changes"; fi
fi
if [ "$DRY_RUN" -eq 0 ] && [ "$FORCE" -eq 0 ] && [ "$INSTALLED" = "$NEW_VERSION" ] && [ "${NEW_VERSION#*local}" = "$NEW_VERSION" ] \
&& [ -x "$BIN_DIR/summit" ] && [ -x "$BIN_DIR/summit-gui" ] && [ -f "$SHARE_DIR/engine/run.py" ]; then
log " Summit $INSTALLED is already the newest: nothing to rebuild (--force rebuilds anyway)"
install_desktop_entry "$SRC_DIR/packaging"
return
fi
if [ -n "$INSTALLED" ]; then
log " updating $INSTALLED -> $NEW_VERSION"
fi
run cargo build --release --manifest-path "$SRC_DIR/Cargo.toml" -p summit -p summit-gui
run_sudo install -Dm755 "$SRC_DIR/target/release/summit" "$BIN_DIR/summit"
run_sudo install -Dm755 "$SRC_DIR/target/release/summit-gui" "$BIN_DIR/summit-gui"
run_sudo mkdir -p "$SHARE_DIR/engine"
run_sudo cp -r "$SRC_DIR/engine/." "$SHARE_DIR/engine/"
run_prefix install -Dm755 "$SRC_DIR/target/release/summit" "$BIN_DIR/summit"
run_prefix install -Dm755 "$SRC_DIR/target/release/summit-gui" "$BIN_DIR/summit-gui"
run_prefix mkdir -p "$SHARE_DIR/engine"
# An update replaces the engine's files (so ones removed upstream go too) but keeps its venv and models.
if [ -f "$SHARE_DIR/engine/run.py" ]; then
run_prefix find "$SHARE_DIR/engine" -mindepth 1 -maxdepth 1 ! -name .venv ! -name models -exec rm -rf {} +
fi
run_prefix cp -r "$SRC_DIR/engine/." "$SHARE_DIR/engine/"
install_desktop_entry "$SRC_DIR/packaging"
# The engine's venv is made in there next, without sudo (uv and the Python it downloads live in the user's home),
# so the folder has to belong to the user who runs Summit.
if [ "$(id -u)" -ne 0 ]; then
if [ "$(id -u)" -ne 0 ] && ! prefix_writable; then
run_sudo chown -R "$(id -u):$(id -g)" "$SHARE_DIR/engine"
fi
version_tmp="$(mktemp)"
printf '%s\n' "$NEW_VERSION" > "$version_tmp"
run_prefix install -Dm644 "$version_tmp" "$VERSION_FILE"
rm -f "$version_tmp"
}
install_desktop_entry() {
# The app menu entry, pointing at the installed binary by its full path (a custom SUMMIT_PREFIX is often not
# on the menu's PATH).
pkg="$1"
run_sudo install -Dm644 "$pkg/icons/summit.png" "$ICON_DIR/summit.png"
run_prefix install -Dm644 "$pkg/icons/summit.png" "$ICON_DIR/summit.png"
desktop_tmp="$(mktemp)"
sed "s|^Exec=summit-gui|Exec=$BIN_DIR/summit-gui|" "$pkg/summit.desktop" > "$desktop_tmp"
run_sudo install -Dm644 "$desktop_tmp" "$APPS_DIR/summit.desktop"
run_prefix install -Dm644 "$desktop_tmp" "$APPS_DIR/summit.desktop"
rm -f "$desktop_tmp"
if command -v update-desktop-database >/dev/null 2>&1; then
run_sudo update-desktop-database "$APPS_DIR" || true
run_prefix update-desktop-database "$APPS_DIR" || true
fi
}
@@ -357,7 +443,11 @@ setup_engine_venv() {
log " engine sources not found, skipping venv setup"
return
fi
run uv venv --python 3.12 "$engine_dir/.venv"
if "$engine_dir/.venv/bin/python" -c 'import sys; sys.exit(sys.version_info[:2] != (3, 12))' 2>/dev/null; then
log " keeping the existing venv ($engine_dir/.venv); installing what is new or missing in it"
else
run uv venv --clear --python 3.12 "$engine_dir/.venv"
fi
if [ "$GPU_VENDOR" = "nvidia" ]; then
# torch first: requirements.txt only says torch>=2.6, and PyPI's default wheel is built for a newer CUDA than
# many installed drivers support (seen: torch 2.15+cu132 on a driver that stops at CUDA 13.0).
@@ -375,6 +465,7 @@ do_install() {
log " distro family : $DISTRO_FAMILY (ID=$DISTRO_ID)"
log " GPU vendor : $GPU_VENDOR"
log " session type : $SESSION_TYPE"
detect_existing
log " will install : summit, summit-gui into $BIN_DIR"
log " engine : $SHARE_DIR/engine with its own venv"
if [ "$DRY_RUN" -eq 1 ]; then
@@ -382,12 +473,8 @@ do_install() {
fi
if [ "$ASSUME_YES" -eq 0 ] && [ "$DRY_RUN" -eq 0 ]; then
printf '\nProceed? [y/N] '
read -r reply
case "$reply" in
y|Y|yes|YES) ;;
*) die "aborted" ;;
esac
printf '\n'
ask 'Proceed?' || die "aborted"
fi
install_dependencies
@@ -413,8 +500,8 @@ do_install() {
do_uninstall() {
step "Uninstalling Summit"
run_sudo rm -f "$BIN_DIR/summit" "$BIN_DIR/summit-gui" "$APPS_DIR/summit.desktop" "$ICON_DIR/summit.png"
run_sudo rm -rf "$SHARE_DIR"
run_prefix rm -f "$BIN_DIR/summit" "$BIN_DIR/summit-gui" "$APPS_DIR/summit.desktop" "$ICON_DIR/summit.png"
run_prefix rm -rf "$SHARE_DIR"
log "Left in place: $SRC_DIR (build cache), ~/.config/summit, ~/.local/share/summit (your data)"
}