go-updater

Crates.iogo-updater
lib.rsgo-updater
version0.1.0
created_at2025-12-18 05:57:35.222145+00
updated_at2025-12-18 05:57:35.222145+00
descriptionSimple CLI to check and update Go (Golang) installations on Linux.
homepagehttps://github.com/christiandoxa/go-updater
repositoryhttps://github.com/christiandoxa/go-updater
max_upload_size
id1991766
size94,544
Christian Doxa Hamasiah (christiandoxa)

documentation

README

πŸ¦€ Go Updater (Rust CLI)

Build Coverage License: MIT

A simple Rust CLI to check and update Go (Golang) on Linux automatically. The program will:

  1. Fetch the latest stable releases from https://go.dev/dl/?mode=json
  2. Compare with the local Go version (go version)
  3. If the local version is older, download the latest release to /tmp
  4. Verify the SHA256 checksum
  5. Install to /usr/local/go (via sudo/pkexec/su)
  6. Re-verify the installation (go version)

Rust edition: 2024


πŸš€ Features

  • Auto-detect installed Go version
  • Download + SHA256 verification
  • Automatic privilege escalation (sudo β†’ pkexec β†’ su)
  • Post-install verification
  • Auto architecture mapping (x86_64β†’amd64, aarch64β†’arm64)

🧩 Requirements

  • Linux / Unix-like
  • Rust & Cargo
  • Internet connection
  • sudo access to install to /usr/local

πŸ› οΈ Build & Run

git clone https://github.com/christiandoxa/go-updater.git
cd go-updater
cargo build --release
./target/release/go-updater

Sample output:

Latest stable release on go.dev: go1.25.2
Local Go version: go1.24.8
Will update to go1.25.2 with: go1.25.2.linux-amd64.tar.gz
Downloaded: /tmp/go1.25.2.linux-amd64.tar.gz
SHA256 OK (...)
Running install: rm -rf /usr/local/go && tar -C /usr/local -xzf /tmp/go1.25.2.linux-amd64.tar.gz
Verification OK: go1.25.2
Done. Make sure PATH includes /usr/local/go/bin

🧰 Project Structure

go-updater/
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs         # core logic
β”‚   └── main.rs        # thin entrypoint (calls cli_main)
└── tests/
    β”œβ”€β”€ main_bin.rs                # integration test for the binary
    β”œβ”€β”€ real_impls.rs              # RealHttp/RealSys/RealFs
    β”œβ”€β”€ real_sys_run_root.rs       # sudo/pkexec/su
    β”œβ”€β”€ real_sys_run_root_missing.rs
    β”œβ”€β”€ semver_eq_cmp.rs
    β”œβ”€β”€ fallback_and_mismatch.rs
    β”œβ”€β”€ map_arch.rs
    └── *.rs

βš™οΈ PATH

If go is not found after installation:

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc

πŸ§ͺ Testing

All tests live under tests/ (integration + unit via the public API).

cargo test

Notes:

  • Tests do not require real network/root access: use the env overrides below when testing:

    • GO_UPDATER_JSON_INLINE β†’ inject release JSON inline
    • GO_UPDATER_ASSUME_ROOT=1 β†’ treat process as root on certain paths
    • GO_UPDATER_SUDO, GO_UPDATER_PKEXEC, GO_UPDATER_SU β†’ point to fake binaries to test escalation fallback

βœ… Coverage (with cargo-llvm-cov)

Run locally

  1. Install:
cargo install cargo-llvm-cov
  1. Generate report & open HTML:
cargo llvm-cov clean --workspace
cargo llvm-cov --workspace --all-features --html --open
  1. (Optional) Gate coverage with a threshold:
# fail if line coverage < 100%
cargo llvm-cov --workspace --all-features --fail-under-lines 100

Tip: if you also want an LCOV file for external tooling:

cargo llvm-cov --workspace --all-features --lcov --output-path lcov.info

πŸ”’ Env Overrides (for tests/CI)

  • GO_UPDATER_JSON_INLINE β€” release JSON string to replace the HTTP fetch
  • GO_UPDATER_JSON_URL β€” alternative URL (default: https://go.dev/dl/?mode=json)
  • GO_UPDATER_ASSUME_ROOT=1 β€” force is_root() true
  • GO_UPDATER_SUDO, GO_UPDATER_PKEXEC, GO_UPDATER_SU β€” alternative paths for escalation binaries

πŸͺͺ License

MIT Β© 2025 β€” Christian Doxa Hamasiah

Commit count: 0

cargo fmt