diff --git a/CLAUDE.md b/CLAUDE.md index 5cf9b68..5ba8e57 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -16,7 +16,7 @@ cargo test --lib engine::tests::shake # one test (name filter) cargo clippy --all-targets && cargo fmt # both must stay clean (rustfmt.toml: max_width 140) cargo run --release -- demo out/ # render every effect to PNG, no display needed cargo run -- -vv --no-tray # run the daemon verbosely (-vv = debug for the sourizz crate only) -./install.sh [--uninstall] # user install into ~/.local +./install.sh [--uninstall] [--yes] # user install into ~/.local; offers to install Rust via rustup if cargo is missing ``` `examples/x11_probe.rs` is an end-to-end check against a running X11 daemon (also `fake_keys`, `mover` helpers). Run the daemon with an isolated config: `XDG_CONFIG_HOME= sourizz --no-tray`. The probe only touches its own test window, but a human moving the real mouse during the run makes it fail. diff --git a/README.fr.md b/README.fr.md index 9a81d60..8726813 100644 --- a/README.fr.md +++ b/README.fr.md @@ -41,7 +41,7 @@ Différences et manques : ## Installation -Il faut une [chaîne d'outils Rust](https://rustup.rs) stable récente (développé avec la 1.98 ; le projet utilise l'édition 2024). **Aucun paquet `-dev` n'est nécessaire** : la compilation est en Rust pur et charge `libxkbcommon` à l'exécution. La première compilation prend quelques minutes car la fenêtre de réglages embarque egui ; `cargo build --release --no-default-features` compile le démon seul. +Il faut une [chaîne d'outils Rust](https://rustup.rs) stable récente (développé avec la 1.98 ; le projet utilise l'édition 2024). **Aucun paquet `-dev` n'est nécessaire** : la compilation est en Rust pur et charge `libxkbcommon` à l'exécution. La première compilation prend quelques minutes car la fenêtre de réglages embarque egui ; `cargo build --release --no-default-features` compile le démon seul. Si Rust est absent, `./install.sh` propose de l'installer avec rustup (il faut `curl` ou `wget` et un éditeur de liens C comme `build-essential` ; ajoutez `--yes` pour ne pas poser la question). ```sh git clone sourizz && cd sourizz diff --git a/README.md b/README.md index 74a18d6..b6d1c32 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Differences and gaps: ## Install -You need a recent stable [Rust toolchain](https://rustup.rs) (developed with 1.98; the crate uses edition 2024). **No `-dev` packages are required**: the build is pure Rust and loads `libxkbcommon` at run time. The first build takes a few minutes because the settings window pulls in egui; `cargo build --release --no-default-features` builds the daemon alone. +You need a recent stable [Rust toolchain](https://rustup.rs) (developed with 1.98; the crate uses edition 2024). **No `-dev` packages are required**: the build is pure Rust and loads `libxkbcommon` at run time. The first build takes a few minutes because the settings window pulls in egui; `cargo build --release --no-default-features` builds the daemon alone. If Rust is missing, `./install.sh` offers to install it with rustup (it needs `curl` or `wget` and a C linker such as `build-essential`; add `--yes` to skip the question). ```sh git clone sourizz && cd sourizz diff --git a/install.sh b/install.sh index 1d77b39..8ad30a1 100755 --- a/install.sh +++ b/install.sh @@ -3,6 +3,7 @@ # ./install.sh build and install into ~/.local # PREFIX=/usr/local ./install.sh (run as root) system-wide # ./install.sh --uninstall +# ./install.sh --yes do not ask before installing Rust (rustup) when it is missing set -euo pipefail PREFIX="${PREFIX:-$HOME/.local}" @@ -12,7 +13,71 @@ ICONS="$PREFIX/share/icons/hicolor/scalable/apps" DOCS="$PREFIX/share/licenses/sourizz" cd "$(dirname "$0")" -if [[ "${1:-}" == "--uninstall" ]]; then +UNINSTALL=0 +ASSUME_YES=0 +for arg in "$@"; do + case "$arg" in + --uninstall) UNINSTALL=1 ;; + -y | --yes) ASSUME_YES=1 ;; + *) echo "Unknown option: $arg (see the header of this script)" >&2; exit 2 ;; + esac +done + +# Make sure `cargo` is available, installing Rust with rustup (https://rustup.rs) after asking if it is not. +ensure_rust() { + local cargo_env="${CARGO_HOME:-$HOME/.cargo}/env" + # rustup puts cargo in ~/.cargo/bin, which a non-login shell may not have in its PATH yet. + if [[ -f "$cargo_env" ]]; then + # shellcheck disable=SC1090 + . "$cargo_env" + fi + if command -v cargo >/dev/null; then + return 0 + fi + + echo "Rust (cargo) is not installed; it is needed to build Sourizz." + if ! command -v cc >/dev/null; then + echo "Rust also needs a C linker: install your distribution's build tools first (e.g. 'sudo apt install build-essential')." >&2 + exit 1 + fi + local fetch + if command -v curl >/dev/null; then + fetch=(curl --proto '=https' --tlsv1.2 -fsSL) + elif command -v wget >/dev/null; then + fetch=(wget -qO-) + else + echo "Install curl or wget, or install Rust yourself from https://rustup.rs, then run this script again." >&2 + exit 1 + fi + if [[ $ASSUME_YES -ne 1 ]]; then + if [[ ! -t 0 ]]; then + echo "Run this script again with --yes to install Rust with rustup, or install it from https://rustup.rs." >&2 + exit 1 + fi + local reply + read -r -p "Install it now with rustup (https://rustup.rs) into ${CARGO_HOME:-$HOME/.cargo}? [y/N] " reply + if [[ ! "$reply" =~ ^[Yy]$ ]]; then + echo "Aborted. Install Rust from https://rustup.rs and run this script again." >&2 + exit 1 + fi + fi + + # Download first, run second: a download cut short must not be executed. + local script + script="$(mktemp)" + trap "rm -f '$script'" EXIT + "${fetch[@]}" https://sh.rustup.rs > "$script" + sh "$script" -y --profile minimal + + if [[ -f "$cargo_env" ]]; then + # shellcheck disable=SC1090 + . "$cargo_env" + fi + command -v cargo >/dev/null || { echo "Rust was installed but cargo is still not in PATH; open a new terminal and run this script again." >&2; exit 1; } + echo "Rust installed. Open a new terminal (or run '. $cargo_env') to use cargo yourself." +} + +if [[ $UNINSTALL -eq 1 ]]; then rm -fv "$BIN/sourizz" "$BIN/sourizz-settings" "$APPS/sourizz.desktop" "$APPS/sourizz-settings.desktop" "$ICONS/sourizz.svg" "$DOCS/LICENSE" rmdir "$DOCS" 2>/dev/null || true rm -fv "${XDG_CONFIG_HOME:-$HOME/.config}/autostart/sourizz.desktop" @@ -20,7 +85,7 @@ if [[ "${1:-}" == "--uninstall" ]]; then exit 0 fi -command -v cargo >/dev/null || { echo "Rust is required: https://rustup.rs" >&2; exit 1; } +ensure_rust cargo build --release install -Dm755 target/release/sourizz "$BIN/sourizz"