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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 28 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash
set -e

echo "==> Installing Satra..."

ARCH=$(uname -m)
case $ARCH in
x86_64)
Expand All @@ -21,27 +19,49 @@ 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
fi
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"
Expand Down
27 changes: 26 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,39 @@ fn main() -> Result<(), io::Error> {
let args: Vec<String> = 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(());
}
"-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");
Expand Down
Loading