diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 298cdfe..93224dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,14 @@ on: jobs: check: - runs-on: windows-latest + strategy: + matrix: + os: + - windows-latest + - ubuntu-latest + + runs-on: ${{ matrix.os }} + steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b01dd6c..1385e66 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,5 @@ name: release + on: push: tags: ["v*"] @@ -17,10 +18,32 @@ jobs: run: | v="${GITHUB_REF_NAME#v}" grep -q "^version = \"$v\"" Cargo.toml - - run: cargo build --release --locked - - uses: softprops/action-gh-release@v2 + - name: Build + run: cargo build --release --locked + - name: Upload release assets + uses: softprops/action-gh-release@v2 with: generate_release_notes: true files: | target/release/pogly.exe target/release/pogly-cli.exe + + release-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Verify tag matches workspace version + shell: bash + run: | + v="${GITHUB_REF_NAME#v}" + grep -q "^version = \"$v\"" Cargo.toml + - name: Build + run: cargo build --release --locked + - name: Upload release assets + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + files: | + target/release/pogly + target/release/pogly-cli diff --git a/README.md b/README.md index 8edba49..7b87434 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pogly-cli -A Windows command-line tool for managing a [Pogly](https://pogly.gg) overlay through its HTTP API — and an open-source reference for building your own API integrations. +A Windows and Linux command-line tool for managing a [Pogly](https://pogly.gg) overlay through its HTTP API — and an open-source reference for building your own API integrations. ``` pogly elements add text --text "New follower!" --size 64 --color "#82a5ff" --x 200 --y 150 @@ -21,23 +21,49 @@ iwr https://cli.pogly.gg -useb | iex This downloads the [latest release](https://github.com/PoglyApp/pogly-cli/releases), installs it to `%LOCALAPPDATA%\Pogly\cli`, and adds it to your `PATH`. The script it runs is [install.ps1](install.ps1) if you'd rather read it first. +Quick install (Bash): + +```bash +curl -fsSL https://cli.pogly.gg/install.sh | bash +``` + +This downloads the [latest release](https://github.com/PoglyApp/pogly-cli/releases), installs it to `~/.local/share/Pogly/cli` (or `$XDG_DATA_HOME/Pogly/cli`), and adds it to your `PATH` via `~/.bashrc` or `~/.zshrc`. The script it runs is [install.sh](install.sh) if you'd rather read it first. + ### Manual install -1. Download `pogly.exe` and `pogly-cli.exe` from the [latest release](https://github.com/PoglyApp/pogly-cli/releases). +1. Download `pogly` and `pogly-cli` (Linux) or `pogly.exe` and `pogly-cli.exe` (Windows) from the [latest release](https://github.com/PoglyApp/pogly-cli/releases). 2. Place them like this (`` is the release version, e.g. `0.1.0`): + + **Windows:** ``` %LOCALAPPDATA%\Pogly\cli\pogly.exe %LOCALAPPDATA%\Pogly\cli\bin\\pogly-cli.exe ``` -3. Add `%LOCALAPPDATA%\Pogly\cli` to your `PATH`. + + **Linux:** + ``` + ~/.local/share/Pogly/cli/pogly + ~/.local/share/Pogly/cli/bin//pogly-cli + ``` + (or under `$XDG_DATA_HOME/Pogly/cli` if that's set) + +3. On Linux, `chmod +x` both binaries. +4. Write the version string (no trailing newline) to `version` next to `pogly`/`pogly.exe`. +5. Add that directory to your `PATH`. ### Uninstall -Run [uninstall.ps1](uninstall.ps1) — it removes the binaries, version store, and PATH entry. Your overlay profiles are kept unless you pass `-PurgeConfig`. +**Windows:** run [uninstall.ps1](uninstall.ps1) — it removes the binaries, version store, and PATH entry. Your overlay profiles are kept unless you pass `-PurgeConfig`. + +**Linux:** +```bash +curl -fsSL https://cli.pogly.gg/uninstall.sh | bash +``` +Or run [uninstall.sh](uninstall.sh) directly if you already have it locally. It removes the binaries, version store, and PATH entry; overlay profiles are kept unless you pass `--purge-config`. ### Version management -`pogly.exe` is a small launcher that runs the selected `pogly-cli.exe`, so multiple versions can live side by side: +`pogly` (`pogly.exe` on Windows) is a small launcher that runs the selected `pogly-cli` (`pogly-cli.exe` on Windows), so multiple versions can live side by side: ``` pogly version # show the current version @@ -70,7 +96,7 @@ pogly elements delete 42 | --- | --- | | `ping` | Check that the overlay API is reachable (no token needed) | | `whoami` | Show the token's label, identity, and permissions | -| `overlay list\|add\|update\|remove\|set-default` | Manage overlay profiles (stored in `%APPDATA%\Pogly\cli\config.toml`) | +| `overlay list\|add\|update\|remove\|set-default` | Manage overlay profiles (stored in `%APPDATA%\Pogly\cli\config.toml` on Windows, `~/.config/Pogly/cli/config.toml` on Linux) | | `elements list\|add \|update\|delete` | Manage elements; `add` has `text`, `image`, `widget`, and `media` subcommands | | `elementdata list\|add\|update\|delete` | Manage element data assets | | `layouts list\|add\|duplicate\|rename\|delete\|set-active` | Manage layouts; `set-active` switches the live scene | @@ -91,7 +117,7 @@ The [examples/](examples/) folder shows how to hook the CLI into your stream: St cargo build --release ``` -Produces `target\release\pogly-cli.exe` (the CLI) and `target\release\pogly.exe` (the launcher). Run the CLI directly during development: `cargo run -p pogly-cli -- `. +On Windows this produces `target\release\pogly-cli.exe` (the CLI) and `target\release\pogly.exe` (the launcher). On Linux it produces `target/release/pogly-cli` and `target/release/pogly`. Run the CLI directly during development: `cargo run -p pogly-cli -- `. To test `version upgrade` against a fork, set `POGLY_RELEASES_REPO=/`. diff --git a/crates/cli/src/paths.rs b/crates/cli/src/paths.rs index 5f232d4..3be82a3 100644 --- a/crates/cli/src/paths.rs +++ b/crates/cli/src/paths.rs @@ -1,17 +1,58 @@ use std::path::PathBuf; -fn env_dir(var: &str) -> PathBuf { - std::env::var_os(var) +#[cfg(windows)] +fn config_base_dir() -> PathBuf { + std::env::var_os("APPDATA") .map(PathBuf::from) - .unwrap_or_else(std::env::temp_dir) + .unwrap_or_else(|| { + std::env::var_os("USERPROFILE") + .map(PathBuf::from) + .unwrap_or_else(std::env::temp_dir) + }) +} + +#[cfg(not(windows))] +fn config_base_dir() -> PathBuf { + std::env::var_os("XDG_CONFIG_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| { + std::env::var_os("HOME") + .map(PathBuf::from) + .unwrap_or_else(std::env::temp_dir) + .join(".config") + }) +} + +#[cfg(windows)] +fn local_base_dir() -> PathBuf { + std::env::var_os("LOCALAPPDATA") + .map(PathBuf::from) + .unwrap_or_else(|| { + std::env::var_os("USERPROFILE") + .map(PathBuf::from) + .unwrap_or_else(std::env::temp_dir) + }) +} + +#[cfg(not(windows))] +fn local_base_dir() -> PathBuf { + std::env::var_os("XDG_DATA_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| { + std::env::var_os("HOME") + .map(PathBuf::from) + .unwrap_or_else(std::env::temp_dir) + .join(".local") + .join("share") + }) } pub fn config_dir() -> PathBuf { - env_dir("APPDATA").join("Pogly").join("cli") + config_base_dir().join("Pogly").join("cli") } pub fn local_dir() -> PathBuf { - env_dir("LOCALAPPDATA").join("Pogly").join("cli") + local_base_dir().join("Pogly").join("cli") } pub fn config_file() -> PathBuf { @@ -31,5 +72,5 @@ pub fn bin_dir() -> PathBuf { } pub fn launcher_path() -> PathBuf { - local_dir().join("pogly.exe") + local_dir().join(if cfg!(windows) { "pogly.exe" } else { "pogly" }) } diff --git a/crates/cli/src/versionstore.rs b/crates/cli/src/versionstore.rs index 22e8ad6..c068ec4 100644 --- a/crates/cli/src/versionstore.rs +++ b/crates/cli/src/versionstore.rs @@ -1,17 +1,34 @@ use std::time::Duration; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result}; use serde_json::Value; use ureq::Agent; use crate::paths; +fn cli_binary_name() -> &'static str { + if cfg!(windows) { + "pogly-cli.exe" + } else { + "pogly-cli" + } +} + +fn launcher_binary_name() -> &'static str { + if cfg!(windows) { + "pogly.exe" + } else { + "pogly" + } +} + pub fn installed_versions() -> Vec { + let binary_name = cli_binary_name(); let mut versions: Vec = std::fs::read_dir(paths::bin_dir()) .map(|entries| { entries .flatten() - .filter(|e| e.path().join("pogly-cli.exe").is_file()) + .filter(|e| e.path().join(binary_name).is_file()) .filter_map(|e| e.file_name().into_string().ok()) .collect() }) @@ -70,14 +87,24 @@ fn download(url: &str) -> Result> { } pub fn install_version(version: &str, release: &Value) -> Result<()> { - let url = asset_url(release, "pogly-cli.exe").context("release has no pogly-cli.exe asset")?; + let binary_name = cli_binary_name(); + let url = asset_url(release, binary_name) + .with_context(|| format!("release has no {binary_name} asset"))?; let dir = paths::bin_dir().join(version); std::fs::create_dir_all(&dir)?; - let target = dir.join("pogly-cli.exe"); - let tmp = dir.join("pogly-cli.exe.tmp"); + let target = dir.join(binary_name); + let tmp = dir.join(format!("{binary_name}.tmp")); std::fs::write(&tmp, download(url)?)?; std::fs::rename(&tmp, &target) .with_context(|| format!("failed to install {}", target.display()))?; + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + + let mut permissions = std::fs::metadata(&target)?.permissions(); + permissions.set_mode(0o755); + std::fs::set_permissions(&target, permissions)?; + } Ok(()) } @@ -89,16 +116,36 @@ pub fn replace_launcher(release: &Value) -> Result<()> { if !path.is_file() { return Ok(()); } - let Some(url) = asset_url(release, "pogly.exe") else { + let launcher_name = launcher_binary_name(); + let Some(url) = asset_url(release, launcher_name) else { return Ok(()); }; let bytes = download(url)?; - let old = paths::local_dir().join("pogly.exe.old"); + let old = paths::local_dir().join(if cfg!(windows) { + "pogly.exe.old" + } else { + "pogly.old" + }); + let tmp = paths::local_dir().join(if cfg!(windows) { + "pogly.exe.tmp" + } else { + "pogly.tmp" + }); let _ = std::fs::remove_file(&old); + let _ = std::fs::remove_file(&tmp); + std::fs::write(&tmp, bytes).context("failed to write new launcher")?; + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + + let mut permissions = std::fs::metadata(&tmp)?.permissions(); + permissions.set_mode(0o755); + std::fs::set_permissions(&tmp, permissions)?; + } std::fs::rename(&path, &old).context("failed to move the current launcher aside")?; - if let Err(e) = std::fs::write(&path, bytes) { + if let Err(e) = std::fs::rename(&tmp, &path) { let _ = std::fs::rename(&old, &path); - bail!("failed to write new launcher: {e}"); + return Err(e).context("failed to install new launcher"); } Ok(()) } diff --git a/crates/launcher/src/main.rs b/crates/launcher/src/main.rs index 2871c38..20941eb 100644 --- a/crates/launcher/src/main.rs +++ b/crates/launcher/src/main.rs @@ -2,11 +2,45 @@ use std::path::{Path, PathBuf}; use std::process::Command; fn local_dir() -> PathBuf { - std::env::var_os("LOCALAPPDATA") - .map(PathBuf::from) - .unwrap_or_else(std::env::temp_dir) - .join("Pogly") - .join("cli") + #[cfg(windows)] + { + std::env::var_os("LOCALAPPDATA") + .map(PathBuf::from) + .unwrap_or_else(std::env::temp_dir) + .join("Pogly") + .join("cli") + } + + #[cfg(not(windows))] + { + std::env::var_os("XDG_DATA_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| { + std::env::var_os("HOME") + .map(PathBuf::from) + .unwrap_or_else(std::env::temp_dir) + .join(".local") + .join("share") + }) + .join("Pogly") + .join("cli") + } +} + +fn cli_binary_name() -> &'static str { + if cfg!(windows) { + "pogly-cli.exe" + } else { + "pogly-cli" + } +} + +fn launcher_old_name() -> &'static str { + if cfg!(windows) { + "pogly.exe.old" + } else { + "pogly.old" + } } fn selected_version(dir: &Path) -> Option { @@ -14,14 +48,17 @@ fn selected_version(dir: &Path) -> Option { .ok() .map(|s| s.trim().to_string()) .filter(|s| !s.is_empty()); + if pointer.is_some() { return pointer; } + // No pointer file: fall back to the highest installed version. + let binary_name = cli_binary_name(); let mut versions: Vec = std::fs::read_dir(dir.join("bin")) .ok()? .flatten() - .filter(|e| e.path().join("pogly-cli.exe").is_file()) + .filter(|e| e.path().join(binary_name).is_file()) .filter_map(|e| e.file_name().into_string().ok()) .collect(); versions.sort(); @@ -36,7 +73,7 @@ fn main() { .ok() .and_then(|p| p.parent().map(|p| p.to_path_buf())) { - let _ = std::fs::remove_file(parent.join("pogly.exe.old")); + let _ = std::fs::remove_file(parent.join(launcher_old_name())); } let Some(version) = selected_version(&dir) else { @@ -45,10 +82,13 @@ fn main() { std::process::exit(1); }; - let exe = dir.join("bin").join(&version).join("pogly-cli.exe"); + let exe = dir.join("bin").join(&version).join(cli_binary_name()); if !exe.is_file() { eprintln!("pogly-cli {version} is not installed at {}", exe.display()); - eprintln!("Run `pogly version list` from an installed version, or reinstall from https://github.com/PoglyApp/pogly-cli/releases"); + eprintln!( + "Run `pogly version list` from an installed version, \ + or reinstall from https://github.com/PoglyApp/pogly-cli/releases" + ); std::process::exit(1); } diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..d8f009c --- /dev/null +++ b/install.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -euo pipefail + +repo="PoglyApp/pogly-cli" +root="${XDG_DATA_HOME:-$HOME/.local/share}/Pogly/cli" + +echo "Installing pogly-cli..." + +release=$(curl -fsSL -H "User-Agent: pogly-cli-installer" "https://api.github.com/repos/$repo/releases/latest") +tag=$(echo "$release" | grep -m1 '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') +version="${tag#v}" +bin_dir="$root/bin/$version" + +mkdir -p "$bin_dir" + +echo "Downloading pogly-cli $tag..." +curl -fsSL -o "$bin_dir/pogly-cli" "https://github.com/$repo/releases/download/$tag/pogly-cli" +chmod +x "$bin_dir/pogly-cli" + +launcher="$root/pogly" +echo "Downloading launcher..." +if ! curl -fsSL -o "$launcher" "https://github.com/$repo/releases/download/$tag/pogly"; then + mv -f "$launcher" "$launcher.old" 2>/dev/null || true + curl -fsSL -o "$launcher" "https://github.com/$repo/releases/download/$tag/pogly" +fi +chmod +x "$launcher" + +printf '%s' "$version" > "$root/version" + +case "$(basename "${SHELL:-bash}")" in + zsh) + shell_rc="$HOME/.zshrc" + ;; + bash) + shell_rc="$HOME/.bashrc" + ;; + *) + shell_rc="$HOME/.profile" + ;; +esac + +if ! grep -qs "$root" "$shell_rc" 2>/dev/null; then + echo "export PATH=\"$root:\$PATH\"" >> "$shell_rc" + echo "Added $root to your PATH in $shell_rc (open a new terminal if 'pogly' is not found)." +fi + +echo "" +echo "pogly-cli $tag installed." +echo "Get started:" +echo " pogly overlay add --token pgly_..." +echo " pogly help" + diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..ad6c281 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -euo pipefail + +purge_config=false +[ "${1:-}" = "--purge-config" ] && purge_config=true + +root="${XDG_DATA_HOME:-$HOME/.local/share}/Pogly/cli" +config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/Pogly/cli" + +if [ -d "$root" ]; then + rm -rf "$root" + echo "Removed $root" +else + echo "Nothing installed at $root" +fi + +for shell_rc in "$HOME/.bashrc" "$HOME/.zshrc"; do + [ -f "$shell_rc" ] || continue + if grep -qs "$root" "$shell_rc"; then + sed -i.bak "\#export PATH=\"$root:\$PATH\"#d" "$shell_rc" + rm -f "$shell_rc.bak" + echo "Removed $root from PATH in $shell_rc" + fi +done + +if $purge_config; then + if [ -d "$config_dir" ]; then + rm -rf "$config_dir" + echo "Removed overlay profiles at $config_dir" + fi +elif [ -d "$config_dir" ]; then + echo "Overlay profiles kept at $config_dir (rerun with --purge-config to remove them)" +fi + +echo "pogly-cli uninstalled." \ No newline at end of file