From 5d5d4301b9ade8f0a5adbc3ca3cb13dae9c7b56a Mon Sep 17 00:00:00 2001 From: Chintan Patel <216989679+Chintanpatel24@users.noreply.github.com> Date: Thu, 10 Sep 2026 00:52:54 +0530 Subject: [PATCH] feat(update): add 'satra update' command and installer upgrade support - Detect existing binary in install.sh, replace cleanly, and use --force for cargo - Add 'satra update' command in main.rs to automate self-updating from GitHub - Update README.md with 'satra update' usage --- README.md | 14 ++++++++++++++ install.sh | 36 ++++++++++++++++++++++++++++-------- src/main.rs | 27 ++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d1177af..042f544 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,20 @@ A lightweight terminal-based process launcher and tracker. curl -sSL https://raw.githubusercontent.com/TattvaOrg/Satra/main/install.sh | bash ``` +## Updating + +Update Satra to the latest version at any time: + +```sh +satra update +``` + +Or re-run the installer: + +```sh +curl -sSL https://raw.githubusercontent.com/TattvaOrg/Satra/main/install.sh | bash +``` + ## Features - Detached process launching diff --git a/install.sh b/install.sh index 4cf440b..7605e4a 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,6 @@ #!/bin/bash set -e -echo "==> Installing Satra..." - ARCH=$(uname -m) case $ARCH in x86_64) @@ -21,17 +19,34 @@ BIN_DIR="${CARGO_HOME:-$HOME/.local}/bin" [ -d "$HOME/.local/bin" ] && BIN_DIR="$HOME/.local/bin" mkdir -p "$BIN_DIR" +IS_UPDATE=false +if [ -f "$BIN_DIR/satra" ]; then + IS_UPDATE=true + CURRENT_VERSION=$("$BIN_DIR/satra" --version 2>/dev/null || echo "existing") + echo "==> Existing Satra installation detected ($CURRENT_VERSION)." + echo "==> Updating Satra at $BIN_DIR/satra..." +else + echo "==> Installing Satra to $BIN_DIR/satra..." +fi + URL="https://github.com/TattvaOrg/Satra/releases/latest/download/satra-$TARGET_ARCH-linux" TMP_BIN=$(mktemp) trap 'rm -f "$TMP_BIN"' EXIT -echo "==> Downloading prebuilt binary from GitHub Releases..." +echo "==> Fetching prebuilt release binary..." if curl -sSfL "$URL" -o "$TMP_BIN" 2>/dev/null; then # Verify file is an executable binary and not an error page if file "$TMP_BIN" | grep -qE "ELF|executable"; then - mv "$TMP_BIN" "$BIN_DIR/satra" + # Unlink existing binary first to avoid ETXTBSY if currently running + rm -f "$BIN_DIR/satra" + mv -f "$TMP_BIN" "$BIN_DIR/satra" chmod +x "$BIN_DIR/satra" - echo "✅ Installed successfully to $BIN_DIR/satra" + NEW_VER=$("$BIN_DIR/satra" --version 2>/dev/null || echo "") + if [ "$IS_UPDATE" = true ]; then + echo "✅ Satra updated successfully! ($NEW_VER)" + else + echo "✅ Satra installed successfully! ($NEW_VER)" + fi else echo "Error: Downloaded file is not a valid binary." exit 1 @@ -39,9 +54,14 @@ if curl -sSfL "$URL" -o "$TMP_BIN" 2>/dev/null; then else echo "Notice: Prebuilt release binary not found at $URL" if command -v cargo >/dev/null 2>&1; then - echo "==> Compiling and installing from source using cargo..." - cargo install --git https://github.com/TattvaOrg/Satra.git --root "${BIN_DIR%/bin}" - echo "✅ Compiled and installed successfully via cargo to $BIN_DIR/satra" + echo "==> Compiling and updating from source using cargo..." + cargo install --force --git https://github.com/TattvaOrg/Satra.git --root "${BIN_DIR%/bin}" + NEW_VER=$("$BIN_DIR/satra" --version 2>/dev/null || echo "") + if [ "$IS_UPDATE" = true ]; then + echo "✅ Satra updated successfully via cargo! ($NEW_VER)" + else + echo "✅ Satra installed successfully via cargo! ($NEW_VER)" + fi else echo "Error: Could not download prebuilt binary and 'cargo' is not installed." echo "Please install Rust (https://rustup.rs) or check https://github.com/TattvaOrg/Satra/releases" diff --git a/src/main.rs b/src/main.rs index 346b16b..a1db887 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,28 @@ fn main() -> Result<(), io::Error> { let args: Vec = std::env::args().collect(); if args.len() > 1 { match args[1].as_str() { + "update" => { + println!("==> Checking for updates and updating Satra..."); + let status = std::process::Command::new("bash") + .arg("-c") + .arg("curl -sSL https://raw.githubusercontent.com/TattvaOrg/Satra/main/install.sh | bash") + .status(); + + match status { + Ok(s) if s.success() => { + println!("==> Update completed successfully."); + return Ok(()); + } + Ok(s) => { + eprintln!("Error: Update process exited with code: {:?}", s.code()); + std::process::exit(s.code().unwrap_or(1)); + } + Err(e) => { + eprintln!("Error running update: {}", e); + std::process::exit(1); + } + } + } "-v" | "--version" => { println!("satra {}", env!("CARGO_PKG_VERSION")); return Ok(()); @@ -22,7 +44,10 @@ fn main() -> Result<(), io::Error> { "-h" | "--help" => { println!("Satra - A lightweight terminal-based process launcher and tracker"); println!(); - println!("Usage: satra [OPTIONS]"); + println!("Usage: satra [COMMAND] [OPTIONS]"); + println!(); + println!("Commands:"); + println!(" update Update Satra to the latest version"); println!(); println!("Options:"); println!(" -h, --help Print help information");