diff --git a/packaging/choco/echohub.nuspec b/packaging/choco/echohub.nuspec index e4415c7..e908659 100644 --- a/packaging/choco/echohub.nuspec +++ b/packaging/choco/echohub.nuspec @@ -4,21 +4,21 @@ echohub __VERSION__ EchoHub - Hue - Hue + HueByte + HueByte false - https://github.com/HueByte/EchoHub/blob/master/LICENSE - https://github.com/HueByte/EchoHub - https://github.com/HueByte/EchoHub - https://huebyte.github.io/EchoHub - https://github.com/HueByte/EchoHub/issues - https://github.com/HueByte/EchoHub/tree/master/packaging/choco - https://raw.githubusercontent.com/HueByte/EchoHub/master/assets/hue_icon.png + https://github.com/HueByteByte/EchoHub/blob/master/LICENSE + https://github.com/HueByteByte/EchoHub + https://github.com/HueByteByte/EchoHub + https://HueBytebyte.github.io/EchoHub + https://github.com/HueByteByte/EchoHub/issues + https://github.com/HueByteByte/EchoHub/tree/master/packaging/choco + https://raw.githubusercontent.com/HueByteByte/EchoHub/master/assets/HueByte_icon.png EchoHub is a decentralized IRC-style chat application with a terminal user interface (TUI). Connect to any EchoHub server, join channels, and chat — all from your terminal. Features include SignalR real-time messaging, file sharing, custom themes, and IRC gateway compatibility. Decentralized terminal chat client with IRC gateway support chat irc decentralized tui terminal signalr echohub - https://huebyte.github.io/EchoHub/changelog/v__VERSION__.html - Copyright (c) 2026 Hue + https://HueBytebyte.github.io/EchoHub/changelog/v__VERSION__.html + Copyright (c) 2026 HueByte diff --git a/scripts/install.sh b/scripts/install.sh index 82989ad..576c30e 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -130,6 +130,31 @@ download() { fi } +# ── PATH setup ──────────────────────────────────────────────────────────── + +add_to_path() { + dir="$1" + export_line="export PATH=\"${dir}:\$PATH\" # Added by EchoHub" + + added=0 + for profile in "$HOME/.profile" "$HOME/.bashrc" "$HOME/.zshrc"; do + if [ -f "$profile" ]; then + if grep -q "$dir" "$profile" 2>/dev/null; then + continue # Already present + fi + printf '\n%s\n' "$export_line" >> "$profile" + echo " Added to PATH in $(basename "$profile")" + added=1 + fi + done + + # If no profile existed, create .profile + if [ "$added" -eq 0 ]; then + printf '\n%s\n' "$export_line" >> "$HOME/.profile" + echo " Added to PATH in .profile" + fi +} + # ── Main ────────────────────────────────────────────────────────────────── main() { @@ -181,18 +206,17 @@ main() { echo "" - # Verify - if command -v "$BINARY_NAME" >/dev/null 2>&1; then - echo "Installed successfully! Run 'echohub' to start." - else - echo "Installed to: ${install_dir}/${BINARY_NAME}" + # Ensure install directory is on PATH + if ! command -v "$BINARY_NAME" >/dev/null 2>&1; then + add_to_path "$install_dir" + fi + + echo "Installed successfully! Run 'echohub' to start." + echo "" + if ! echo "$PATH" | tr ':' '\n' | grep -qx "$install_dir"; then + echo "NOTE: Restart your shell or run the following to use echohub now:" echo "" - echo "WARNING: ${install_dir} is not in your PATH." - echo "Add it to your shell profile:" - echo "" - echo " echo 'export PATH=\"${install_dir}:\$PATH\"' >> ~/.bashrc" - echo " # or for zsh:" - echo " echo 'export PATH=\"${install_dir}:\$PATH\"' >> ~/.zshrc" + echo " export PATH=\"${install_dir}:\$PATH\"" fi } diff --git a/src/EchoHub.Client/Program.cs b/src/EchoHub.Client/Program.cs index 1394ab2..f86f1c3 100644 --- a/src/EchoHub.Client/Program.cs +++ b/src/EchoHub.Client/Program.cs @@ -77,6 +77,9 @@ Log.Logger = new LoggerConfiguration() Log.Information("EchoHub client starting"); +// == Ensure echohub is on PATH for convenient terminal access ============ +PathSetup.EnsureOnPath(); + // == Post-update detection: stale backup cleanup or flag for rollback menu ================ if (UpdateBackupService.BackupExists()) { diff --git a/src/EchoHub.Client/Services/PathSetup.cs b/src/EchoHub.Client/Services/PathSetup.cs new file mode 100644 index 0000000..c7184d5 --- /dev/null +++ b/src/EchoHub.Client/Services/PathSetup.cs @@ -0,0 +1,102 @@ +using Serilog; + +namespace EchoHub.Client.Services; + +/// +/// Ensures the application's directory is on the system PATH so users +/// can run 'echohub' from any terminal session. +/// +public static class PathSetup +{ + private const string PathMarker = "# Added by EchoHub"; + + /// + /// Checks if the app directory is on PATH; if not, adds it persistently. + /// On Windows: modifies user-level PATH environment variable. + /// On Linux/macOS: appends an export line to shell profile files. + /// + public static void EnsureOnPath() + { + try + { + var appDir = AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + if (IsOnPath(appDir)) + return; + + if (OperatingSystem.IsWindows()) + AddToWindowsPath(appDir); + else + AddToUnixPath(appDir); + } + catch (Exception ex) + { + Log.Debug(ex, "Could not add app directory to PATH"); + } + } + + private static bool IsOnPath(string directory) + { + var pathVar = Environment.GetEnvironmentVariable("PATH") ?? ""; + var separator = OperatingSystem.IsWindows() ? ';' : ':'; + + return pathVar + .Split(separator, StringSplitOptions.RemoveEmptyEntries) + .Any(p => string.Equals( + p.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), + directory, + OperatingSystem.IsWindows() + ? StringComparison.OrdinalIgnoreCase + : StringComparison.Ordinal)); + } + + private static void AddToWindowsPath(string directory) + { + var userPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User) ?? ""; + + // Double-check against user PATH specifically (process PATH includes system + user) + if (userPath.Split(';', StringSplitOptions.RemoveEmptyEntries) + .Any(p => string.Equals(p.TrimEnd('\\', '/'), directory, StringComparison.OrdinalIgnoreCase))) + return; + + var newPath = string.IsNullOrEmpty(userPath) ? directory : userPath + ";" + directory; + Environment.SetEnvironmentVariable("PATH", newPath, EnvironmentVariableTarget.User); + Log.Information("Added {Directory} to user PATH", directory); + } + + private static void AddToUnixPath(string directory) + { + var exportLine = $"export PATH=\"{directory}:$PATH\" {PathMarker}"; + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + + // Target the most common shell profiles + string[] profiles = [ + Path.Combine(home, ".profile"), + Path.Combine(home, ".bashrc"), + Path.Combine(home, ".zshrc") + ]; + + var added = false; + foreach (var profile in profiles) + { + if (!File.Exists(profile)) + continue; + + var content = File.ReadAllText(profile); + if (content.Contains(directory)) + continue; // Already present (manual or previous run) + + File.AppendAllText(profile, $"\n{exportLine}\n"); + added = true; + Log.Information("Added PATH export to {Profile}", profile); + } + + // If no profile existed, create .profile + if (!added) + { + var fallback = Path.Combine(home, ".profile"); + File.AppendAllText(fallback, $"\n{exportLine}\n"); + Log.Information("Created PATH export in {Profile}", fallback); + } + } +}