Use all your internet connections at once on Windows, macOS, Linux and Android: per-connection load balancing over Wi-Fi, Ethernet, mobile data and phone tethers
Go androidbandwidth-aggregationdownloadergolanglinuxload-balancingmacosnet-mergenetworkingtetheringtunwifiwindowswintun
One-line install for macOS, Linux and Windows (#18)
Rohit Mahto6093879958c5
diff --git a/.github/workflows/verify-repos.yml b/.github/workflows/verify-repos.ymlindex 42beb4b..05cf907 100644--- a/.github/workflows/verify-repos.yml+++ b/.github/workflows/verify-repos.yml@@ -1,18 +1,81 @@name: verify-repos-# Installs net-merge from the real published repositories, with the commands from the README, on-# every distribution and on both x86-64 and ARM64. Run it after a release (Actions > verify-repos >-# Run workflow); it also runs every Monday to catch a broken key or repository.+# Installs net-merge for real from what is published: with install.sh / install.ps1 on every system,+# and with the README's commands from the signed repositories, on x86-64 and ARM64. Runs on changes to+# the install scripts, every Monday, and by hand (Actions > verify-repos > Run workflow) after a release.on:workflow_dispatch:schedule:- cron: '23 5 * * 1'+ pull_request:+ paths: [install.sh, install.ps1, .github/workflows/verify-repos.yml]env:BASE: https://rohit267.github.io/net-mergeFPR: 0168C7AB77721656904811AE904F61E7F4F1C2A1jobs:- install:+ # curl ... install.sh | sh, in a fresh container of each distribution+ script-linux:+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, ubuntu-24.04-arm]+ distro: [ubuntu, debian, fedora, rocky, opensuse, alpine, arch, tarball]+ include:+ - {distro: ubuntu, image: 'ubuntu:24.04', prep: 'apt-get update -qq && apt-get install -y -qq curl ca-certificates >/dev/null'}+ - {distro: debian, image: 'debian:stable', prep: 'apt-get update -qq && apt-get install -y -qq curl ca-certificates >/dev/null'}+ - {distro: fedora, image: 'fedora:latest', prep: 'true'}+ - {distro: rocky, image: 'rockylinux:9', prep: 'true'}+ - {distro: opensuse, image: 'opensuse/tumbleweed', prep: 'true'}+ - {distro: alpine, image: 'alpine:3.22', prep: 'true'} # no curl: the script falls back to wget+ - {distro: arch, image: 'archlinux:latest', prep: 'sed -i "s/^#\\?DisableSandbox.*/DisableSandbox/" /etc/pacman.conf; grep -q ^DisableSandbox /etc/pacman.conf || sed -i "/^\\[options\\]/a DisableSandbox" /etc/pacman.conf'}+ - {distro: tarball, image: 'ubuntu:24.04', prep: 'apt-get update -qq && apt-get install -y -qq curl ca-certificates libcap2-bin >/dev/null', method: tarball}+ exclude:+ - {os: ubuntu-24.04-arm, distro: arch} # Arch Linux has no ARM container image+ name: install.sh ${{ matrix.distro }} (${{ matrix.os }})+ runs-on: ${{ matrix.os }}+ steps:+ - uses: actions/checkout@v4+ - run: |+ docker run --rm --cap-add NET_ADMIN --cap-add NET_RAW -v "$PWD:/src:ro" -e NET_MERGE_NO_START=1 \+ -e NET_MERGE_METHOD=${{ matrix.method || 'auto' }} '${{ matrix.image }}' sh -ec '+ ${{ matrix.prep }}+ sh /src/install.sh+ sh /src/install.sh # again: an upgrade must work too+ net-merge version'++ script-macos:+ strategy:+ fail-fast: false+ matrix:+ method: [auto, tarball] # auto: Homebrew is on the runner+ name: install.sh macOS ${{ matrix.method }}+ runs-on: macos-latest+ steps:+ - uses: actions/checkout@v4+ - env:+ NET_MERGE_NO_START: '1'+ NET_MERGE_METHOD: ${{ matrix.method }}+ run: |+ sh install.sh+ net-merge version+ /usr/local/bin/net-merge version+ sudo test -f /etc/sudoers.d/net-merge+ sudo -n -l "$(readlink -f /usr/local/bin/net-merge)" tray++ script-windows:+ name: install.ps1 Windows+ runs-on: windows-latest+ steps:+ - uses: actions/checkout@v4+ - shell: pwsh+ run: |+ $env:NET_MERGE_NO_START = '1'+ ./install.ps1+ & "$env:ProgramFiles\net-merge\net-merge.exe" version++ # the README's own commands, one system at a time+ readme-commands:strategy:fail-fast: falsematrix:@@ -27,8 +90,8 @@ jobs:- {distro: alpine, image: 'alpine:3.22', family: apk}- {distro: arch, image: 'archlinux:latest', family: pacman}exclude:- - {os: ubuntu-24.04-arm, distro: arch} # Arch Linux has no ARM container image- name: ${{ matrix.distro }} (${{ matrix.os }})+ - {os: ubuntu-24.04-arm, distro: arch}+ name: README ${{ matrix.distro }} (${{ matrix.os }})runs-on: ${{ matrix.os }}steps:- name: Install net-merge@@ -40,26 +103,22 @@ jobs:echo "deb [signed-by=/usr/share/keyrings/net-merge.gpg] $BASE/apt stable main" | sudo tee /etc/apt/sources.list.d/net-merge.listsudo apt update && sudo apt install -y net-merge' ;;dnf) script='- curl -fsSL -o /etc/yum.repos.d/net-merge.repo $BASE/rpm/net-merge.repo- dnf install -y net-merge' ;;+ dnf install -y sudo >/dev/null+ sudo curl -fsSL -o /etc/yum.repos.d/net-merge.repo $BASE/rpm/net-merge.repo && sudo dnf install -y net-merge' ;;zypper) script='- zypper --non-interactive addrepo $BASE/rpm/net-merge.repo- zypper --non-interactive --gpg-auto-import-keys refresh- zypper --non-interactive install net-merge' ;;+ zypper --non-interactive install sudo >/dev/null+ sudo zypper addrepo $BASE/rpm/net-merge.repo && sudo zypper --gpg-auto-import-keys install -y net-merge' ;;apk) script='- apk add --no-cache sudo wget >/dev/null+ apk add --no-cache sudo >/dev/nullsudo wget -O /etc/apk/keys/net-merge.rsa.pub $BASE/apk/net-merge.rsa.pub- echo $BASE/apk | sudo tee -a /etc/apk/repositories- sudo apk add net-merge' ;;+ echo $BASE/apk | sudo tee -a /etc/apk/repositories && sudo apk add net-merge' ;;pacman) script='pacman-key --init- curl -fsSL $BASE/apt/key.asc | pacman-key --add -- pacman-key --lsign-key $FPR+ curl -fsSL $BASE/apt/key.asc | pacman-key --add - && pacman-key --lsign-key $FPRprintf "\n[net-merge]\nSigLevel = Required\nServer = $BASE/arch/\$arch\n" >> /etc/pacman.confpacman --disable-sandbox -Sy --noconfirm net-merge' ;;esacdocker run --rm --cap-add NET_ADMIN --cap-add NET_RAW -e BASE -e FPR '${{ matrix.image }}' sh -ec "$scriptnet-merge version- command -v getcap >/dev/null && getcap /usr/bin/net-merge || truetest -f /usr/share/applications/io.github.rohit267.net-merge.desktop"diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 990f49f..3e46666 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,20 @@ entry here before pushing a version tag.## [Unreleased]+### Added+- **One-line install.** `curl -fsSL https://raw.githubusercontent.com/rohit267/net-merge/main/install.sh | sh` on+ macOS and Linux (it uses Homebrew, apt, dnf, zypper, apk or pacman when it can, the release tarball+ otherwise, and starts the tray), and `irm https://raw.githubusercontent.com/rohit267/net-merge/main/install.ps1 | iex`+ in PowerShell on Windows.+- Releases also carry the downloads under names without the version (`net-merge-setup.exe`,+ `net-merge-macos-universal.tar.gz`, `net-merge-linux-$(uname -m).tar.gz`), so+ `releases/latest/download/...` links always give the newest one.++### Fixed+- `sudo net-merge install` refused on Macs where `/usr/local/bin` is writable by your user (Intel Macs+ with Homebrew). It now puts its root-owned copy in `/opt/net-merge/bin` there, and links `net-merge` into+ `/usr/local/bin`.+## [0.3.0] - 2026-10-17### Addeddiff --git a/README.md b/README.mdindex 7403fb4..5cfced8 100644--- a/README.md+++ b/README.md@@ -59,111 +59,110 @@ spread over all your links.## Install-### Windows+**macOS and Linux**: paste this into a terminal.-1. Download `net-merge-setup-x.y.z.exe` from the [releases page](../../releases) and run it. It needs admin.-2. Windows may warn you because the app is not signed yet. Click *More info*, then *Run anyway*.-3. Open **net-merge** from the Start menu. A tray icon appears. If you do not see it, it is behind the- `^` arrow next to the clock.--There is also a portable zip on the releases page.--### macOS (Apple Silicon and Intel)+```+curl -fsSL https://raw.githubusercontent.com/rohit267/net-merge/main/install.sh | sh+```-1. Download `net-merge-x.y.z-macos-universal.tar.gz` from the [releases page](../../releases).-2. Open Terminal in that folder and run:+**Windows**: paste this into PowerShell.```-tar xzf net-merge-*-macos-universal.tar.gz-xattr -d com.apple.quarantine net-merge # only if macOS says it can't open it-sudo ./net-merge install # once: lets the tray start without a password-net-merge tray # a green/grey icon appears in the menu bar+irm https://raw.githubusercontent.com/rohit267/net-merge/main/install.ps1 | iex```-3. Optional: `net-merge autostart on` to start it when you log in.+That's it: net-merge is installed and its icon appears in the menu bar or tray. On Linux the script+uses your package manager (apt, dnf, zypper, apk or pacman) and on macOS Homebrew when you have it, so+net-merge updates with the rest of your system. To start it at sign-in: `net-merge autostart on`.++<details>+<summary><strong>Rather type the commands yourself?</strong> One block per system, each ready to paste.</summary>+<br>-With Homebrew instead: `brew install rohit267/tap/net-merge`, then `sudo "$(brew --prefix)/bin/net-merge" install`-and `net-merge tray` (run `install` again after each `brew upgrade net-merge`).+**Homebrew** (macOS):-`install` adds one small rule so that only `net-merge tray` can run as root without a password. To remove-it all: `net-merge autostart off` and `sudo net-merge uninstall`.+```+brew install rohit267/tap/net-merge && sudo "$(brew --prefix)/bin/net-merge" install && net-merge tray+```-### Linux+**macOS without Homebrew**:-net-merge is packaged for the main distributions and for these CPUs: x86-64, ARM64, ARMv7, ARMv6-(Raspberry Pi), x86 32-bit, RISC-V, PowerPC (ppc64le), s390x and LoongArch. Pick yours. Each way keeps-net-merge up to date through your normal package manager.+```+curl -fsSL https://github.com/rohit267/net-merge/releases/latest/download/net-merge-macos-universal.tar.gz | tar -xz -C /tmp net-merge && sudo /tmp/net-merge install && net-merge tray+```**Debian, Ubuntu, Linux Mint, Pop!_OS, Raspberry Pi OS** (apt):```curl -fsSL https://rohit267.github.io/net-merge/apt/key.gpg | sudo tee /usr/share/keyrings/net-merge.gpg >/dev/nullecho "deb [signed-by=/usr/share/keyrings/net-merge.gpg] https://rohit267.github.io/net-merge/apt stable main" | sudo tee /etc/apt/sources.list.d/net-merge.list-sudo apt update && sudo apt install net-merge+sudo apt update && sudo apt install -y net-merge```**Fedora, RHEL, Rocky, Alma** (dnf):```-sudo curl -fsSL -o /etc/yum.repos.d/net-merge.repo https://rohit267.github.io/net-merge/rpm/net-merge.repo-sudo dnf install net-merge+sudo curl -fsSL -o /etc/yum.repos.d/net-merge.repo https://rohit267.github.io/net-merge/rpm/net-merge.repo && sudo dnf install -y net-merge```**openSUSE** (zypper):```-sudo zypper addrepo https://rohit267.github.io/net-merge/rpm/net-merge.repo-sudo zypper --gpg-auto-import-keys refresh-sudo zypper install net-merge+sudo zypper addrepo https://rohit267.github.io/net-merge/rpm/net-merge.repo && sudo zypper --gpg-auto-import-keys install -y net-merge```**Arch, Manjaro, EndeavourOS** (pacman):```-curl -fsSL https://rohit267.github.io/net-merge/apt/key.asc | sudo pacman-key --add --sudo pacman-key --lsign-key 0168C7AB77721656904811AE904F61E7F4F1C2A1+curl -fsSL https://rohit267.github.io/net-merge/apt/key.asc | sudo pacman-key --add - && sudo pacman-key --lsign-key 0168C7AB77721656904811AE904F61E7F4F1C2A1printf '\n[net-merge]\nSigLevel = Required\nServer = https://rohit267.github.io/net-merge/arch/$arch\n' | sudo tee -a /etc/pacman.conf-sudo pacman -Sy net-merge+sudo pacman -Sy --noconfirm net-merge```**Alpine** (apk):```sudo wget -O /etc/apk/keys/net-merge.rsa.pub https://rohit267.github.io/net-merge/apk/net-merge.rsa.pub-echo https://rohit267.github.io/net-merge/apk | sudo tee -a /etc/apk/repositories-sudo apk add net-merge+echo https://rohit267.github.io/net-merge/apk | sudo tee -a /etc/apk/repositories && sudo apk add net-merge```-**Homebrew** (Linux and macOS): `brew install rohit267/tap/net-merge`, then, once and again after each-`brew upgrade net-merge`: `sudo setcap cap_net_admin,cap_net_raw+ep "$(readlink -f "$(command -v net-merge)")"`.--Then open **net-merge** from your app menu, or run `net-merge tray`. The packages give net-merge the-network rights it needs, so there is no password prompt. You can also download the `.deb`, `.rpm`, `.apk`-or `.pkg.tar.zst` for your CPU from the [releases page](../../releases) and install it by hand-(`sudo apt install ./net-merge_*.deb`, `sudo dnf install ./net-merge-*.rpm`, `sudo apk add --allow-untrusted ./net-merge_*.apk`,-`sudo pacman -U ./net-merge-*.pkg.tar.zst`).+**Homebrew** (Linux):-**Any other distribution** (tarball):+```+brew install rohit267/tap/net-merge && sudo setcap cap_net_admin,cap_net_raw+ep "$(readlink -f "$(brew --prefix)/bin/net-merge")"+```-1. Download the `net-merge-x.y.z-linux-<cpu>.tar.gz` for your CPU from the [releases page](../../releases):- `x86_64`, `aarch64`, `armv7`, `armv6`, `i686`, `riscv64`, `ppc64le`, `s390x` or `loongarch64`.-2. Run:+**Any other Linux** (any CPU):```-tar xzf net-merge-*-linux-*.tar.gz-sudo install -m 755 net-merge /usr/local/bin/-sudo setcap cap_net_admin,cap_net_raw+ep /usr/local/bin/net-merge-net-merge tray+curl -fsSL https://github.com/rohit267/net-merge/releases/latest/download/net-merge-linux-$(uname -m).tar.gz | tar -xz -C /tmp net-merge && sudo install -m 755 /tmp/net-merge /usr/local/bin/ && sudo setcap cap_net_admin,cap_net_raw+ep /usr/local/bin/net-merge```-The `setcap` line lets net-merge work without root. The tray icon needs a desktop that supports-StatusNotifierItem: KDE, XFCE, Cinnamon, LXQt, Budgie, or GNOME with the *AppIndicator and-KStatusNotifierItem Support* extension (Ubuntu already has it). If your firewall blocks unknown traffic,-trust the `net-merge` interface (for example `firewall-cmd --zone=trusted --add-interface=net-merge`).+**Windows by hand**: download [net-merge-setup.exe](https://github.com/rohit267/net-merge/releases/latest/download/net-merge-setup.exe)+and run it. Windows may warn because the app is not signed yet: click *More info*, then *Run anyway*.+There is also a [portable zip](https://github.com/rohit267/net-merge/releases/latest/download/net-merge-portable.zip).++Then start it with `net-merge tray` (Linux, macOS) or from the Start menu (Windows).+</details>-The apt, dnf, zypper and Arch repositories are signed with the key in-[`packaging/apt-signing-key.asc`](packaging/apt-signing-key.asc), fingerprint-`0168 C7AB 7772 1656 9048 11AE 904F 61E7 F4F1 C2A1`.+<details>+<summary><strong>Good to know</strong></summary>+<br>++- **Which CPUs:** x86-64, ARM64 and Apple Silicon, ARMv7, ARMv6 (Raspberry Pi), x86 32-bit, RISC-V,+ PowerPC (ppc64le), s390x and LoongArch.+- **No password prompts:** the Linux packages give net-merge the network rights it needs (`setcap`), and on+ macOS `net-merge install` adds one rule so that only `net-merge tray` can run as root without a password.+- **Linux tray icon:** needs a desktop with StatusNotifierItem support: KDE, XFCE, Cinnamon, LXQt, Budgie,+ or GNOME with the *AppIndicator and KStatusNotifierItem Support* extension (Ubuntu already has it).+- **Firewall:** if it blocks unknown traffic, trust the `net-merge` interface+ (for example `firewall-cmd --zone=trusted --add-interface=net-merge`).+- **Signed repositories:** apt, dnf, zypper and pacman use the key in+ [`packaging/apt-signing-key.asc`](packaging/apt-signing-key.asc), fingerprint+ `0168 C7AB 7772 1656 9048 11AE 904F 61E7 F4F1 C2A1`.+- **Uninstall:** your package manager (`sudo apt remove net-merge`, `brew uninstall net-merge`, ...) or+ Windows' *Installed apps*. On macOS also `net-merge autostart off` and `sudo net-merge uninstall`.+</details>### NixOSdiff --git a/install.ps1 b/install.ps1new file mode 100644index 0000000..e23a58b--- /dev/null+++ b/install.ps1@@ -0,0 +1,27 @@+# Installs net-merge on Windows. In PowerShell:+#+# irm https://raw.githubusercontent.com/rohit267/net-merge/main/install.ps1 | iex+#+# Downloads the newest installer, runs it silently (Windows asks once for admin rights), then starts+# the tray. Set $env:NET_MERGE_NO_START = '1' first to leave the tray off.+$ErrorActionPreference = 'Stop'+$ProgressPreference = 'SilentlyContinue' # the progress bar makes downloads very slow in Windows PowerShell+[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12++$url = 'https://github.com/rohit267/net-merge/releases/latest/download/net-merge-setup.exe'+$setup = Join-Path $env:TEMP 'net-merge-setup.exe'+Write-Host '==> Downloading net-merge'+Invoke-WebRequest $url -OutFile $setup -UseBasicParsing+Write-Host '==> Installing'+$p = Start-Process $setup -ArgumentList '/SILENT', '/SUPPRESSMSGBOXES', '/NORESTART' -Verb RunAs -Wait -PassThru+Remove-Item $setup -ErrorAction SilentlyContinue+if ($p.ExitCode -ne 0) { throw "the installer failed (exit code $($p.ExitCode))" }++$dir = Join-Path $env:ProgramFiles 'net-merge'+Write-Host "==> Installed $(& (Join-Path $dir 'net-merge.exe') version)"+if ($env:NET_MERGE_NO_START -eq '1') {+ Write-Host '==> Start it from the Start menu: net-merge'+} else {+ Start-Process (Join-Path $dir 'net-merge-tray.exe')+ Write-Host '==> Started: the icon is in the tray (maybe behind the ^ arrow next to the clock)'+}diff --git a/install.sh b/install.shnew file mode 100755index 0000000..9dbb049--- /dev/null+++ b/install.sh@@ -0,0 +1,146 @@+#!/bin/sh+# Installs net-merge on macOS or Linux, the easiest way the machine allows:+#+# curl -fsSL https://raw.githubusercontent.com/rohit267/net-merge/main/install.sh | sh+#+# Linux: the system's package manager (apt, dnf, yum, zypper, apk, pacman) from net-merge's signed+# repositories, so it updates with everything else; otherwise Homebrew; otherwise the release tarball.+# macOS: Homebrew if it is installed, otherwise the release tarball.+# Then it starts the tray. NET_MERGE_METHOD=tarball skips the package managers, NET_MERGE_NO_START=1+# leaves the tray off.+set -eu++REPO=https://github.com/rohit267/net-merge+BASE=https://rohit267.github.io/net-merge+FPR=0168C7AB77721656904811AE904F61E7F4F1C2A1++say() { printf '\033[1;32m==>\033[0m %s\n' "$*"; }+die() { printf 'net-merge install: %s\n' "$*" >&2; exit 1; }+have() { command -v "$1" >/dev/null 2>&1; }+fetch() { # fetch URL: the body on stdout+ if have curl; then curl -fsSL "$1"; elif have wget; then wget -qO- "$1"; else die "needs curl or wget"; fi+}++if [ "$(id -u)" = 0 ]; then SUDO=+elif have sudo; then SUDO=sudo+elif have doas; then SUDO=doas+else die "run it as root, or install sudo"; fi++tmp=$(mktemp -d)+trap 'rm -rf "$tmp"' EXIT++# ---- the release tarball, for any CPU net-merge is built for+tarball() {+ if [ "$(uname -s)" = Darwin ]; then+ name=macos-universal+ else+ case $(uname -m) in+ i?86) name=linux-i686 ;;+ armv8l) name=linux-armv7l ;;+ *) name=linux-$(uname -m) ;;+ esac+ fi+ say "Downloading net-merge ($name)"+ fetch "$REPO/releases/latest/download/net-merge-$name.tar.gz" | tar -xz -C "$tmp" net-merge ||+ die "no download for $name; see $REPO/releases"+ if [ "$(uname -s)" = Darwin ]; then+ $SUDO "$tmp/net-merge" install # copies it to /usr/local/bin, lets the tray start without a password+ else+ $SUDO install -D -m 755 "$tmp/net-merge" /usr/local/bin/net-merge+ if have setcap; then+ $SUDO setcap cap_net_admin,cap_net_raw+ep /usr/local/bin/net-merge+ else+ say "setcap not found: install libcap, then run: sudo setcap cap_net_admin,cap_net_raw+ep /usr/local/bin/net-merge"+ fi+ fi+}++# ---- Homebrew (as the user: brew refuses root)+homebrew() {+ say "Installing with Homebrew"+ brew install rohit267/tap/net-merge+ bin=$(brew --prefix)/bin/net-merge+ if [ "$(uname -s)" = Darwin ]; then+ $SUDO "$bin" install+ else+ $SUDO setcap cap_net_admin,cap_net_raw+ep "$(readlink -f "$bin")"+ fi+}++# ---- the system package manager, from the signed repositories+apt_install() {+ say "Installing with apt"+ fetch "$BASE/apt/key.gpg" > "$tmp/key.gpg"+ $SUDO install -D -m 644 "$tmp/key.gpg" /usr/share/keyrings/net-merge.gpg+ echo "deb [signed-by=/usr/share/keyrings/net-merge.gpg] $BASE/apt stable main" | $SUDO tee /etc/apt/sources.list.d/net-merge.list >/dev/null+ $SUDO apt-get update -qq+ $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq net-merge+}+rpm_install() { # rpm_install dnf|yum+ say "Installing with $1"+ fetch "$BASE/rpm/net-merge.repo" > "$tmp/net-merge.repo"+ $SUDO install -m 644 "$tmp/net-merge.repo" /etc/yum.repos.d/net-merge.repo+ $SUDO "$1" install -y net-merge+}+zypper_install() {+ say "Installing with zypper"+ $SUDO zypper --non-interactive lr net-merge >/dev/null 2>&1 || $SUDO zypper --non-interactive addrepo "$BASE/rpm/net-merge.repo"+ $SUDO zypper --non-interactive --gpg-auto-import-keys refresh net-merge+ $SUDO zypper --non-interactive install net-merge+}+apk_install() {+ say "Installing with apk"+ fetch "$BASE/apk/net-merge.rsa.pub" > "$tmp/net-merge.rsa.pub"+ $SUDO install -m 644 "$tmp/net-merge.rsa.pub" /etc/apk/keys/net-merge.rsa.pub+ grep -qx "$BASE/apk" /etc/apk/repositories || echo "$BASE/apk" | $SUDO tee -a /etc/apk/repositories >/dev/null+ $SUDO apk add net-merge+}+pacman_install() {+ say "Installing with pacman"+ # a fresh system may have no local pacman key yet, which signing ours needs+ $SUDO pacman-key --list-secret-keys 2>/dev/null | grep -q '^sec' || $SUDO pacman-key --init+ if ! $SUDO pacman-key --list-keys "$FPR" >/dev/null 2>&1; then+ fetch "$BASE/apt/key.asc" > "$tmp/key.asc"+ $SUDO pacman-key --add "$tmp/key.asc"+ $SUDO pacman-key --lsign-key "$FPR"+ fi+ grep -q '^\[net-merge\]' /etc/pacman.conf ||+ printf '\n[net-merge]\nSigLevel = Required\nServer = %s/arch/$arch\n' "$BASE" | $SUDO tee -a /etc/pacman.conf >/dev/null+ $SUDO pacman -Sy --needed --noconfirm net-merge+}++# ---- pick the way+method=${NET_MERGE_METHOD:-auto}+if [ "$(uname -s)" = Darwin ]; then+ # a running tray holds the old binary: stop it before replacing it+ pgrep -qf 'net-merge tray' && { net-merge quit 2>/dev/null || true; sleep 2; }+ $SUDO mkdir -p /usr/local/bin # where `net-merge install` puts its root-owned copy+ if [ "$method" = auto ] && have brew && [ "$(id -u)" != 0 ]; then homebrew; else tarball; fi+elif [ "$(uname -s)" = Linux ]; then+ if [ -f /etc/NIXOS ]; then+ die "on NixOS use the module instead: $REPO#nixos"+ elif [ "$method" != auto ]; then tarball+ elif have apt-get && have dpkg && case $(dpkg --print-architecture) in amd64|arm64|armhf|i386|loong64|ppc64el|riscv64|s390x) true ;; *) false ;; esac; then apt_install+ elif have dnf; then rpm_install dnf+ elif have yum; then rpm_install yum+ elif have zypper; then zypper_install+ elif have apk; then apk_install+ elif have pacman; then pacman_install+ elif have brew && [ "$(id -u)" != 0 ]; then homebrew+ else tarball; fi+else+ die "this script is for macOS and Linux; on Windows run in PowerShell: irm https://raw.githubusercontent.com/rohit267/net-merge/main/install.ps1 | iex"+fi++have net-merge || PATH=$PATH:/usr/local/bin+say "Installed $(net-merge version)"++# ---- start the tray: on a Mac, or on a Linux desktop session that isn't root's+if [ "${NET_MERGE_NO_START:-}" = 1 ]; then+ say "Start it with: net-merge tray"+elif [ "$(uname -s)" = Darwin ] || { [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ] && [ "$(id -u)" != 0 ]; }; then+ nohup net-merge tray >/dev/null 2>&1 &+ say "Started: look for the net-merge icon in the menu bar or tray. To start it at sign-in: net-merge autostart on"+else+ say "Start it with: net-merge tray (from your desktop session), or net-merge run (any terminal, as root)"+fidiff --git a/internal/platform/autostart_darwin.go b/internal/platform/autostart_darwin.goindex b0aa96c..47cf83d 100644--- a/internal/platform/autostart_darwin.go+++ b/internal/platform/autostart_darwin.go@@ -52,7 +52,7 @@ func Autostart(action string) error {fmt.Println("autostart is OFF.")return nil}- if exec.Command("/usr/bin/sudo", "-n", "-l", InstalledExe, "tray").Run() != nil {+ if exec.Command("/usr/bin/sudo", "-n", "-l", InstalledExe(), "tray").Run() != nil {return errors.New("the tray can't start at sign-in without the passwordless rule; run once: sudo net-merge install")}home, _ := os.UserHomeDir()@@ -60,7 +60,7 @@ func Autostart(action string) error {<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Label</key><string>` + agentLabel + `</string>-<key>ProgramArguments</key><array><string>/usr/bin/sudo</string><string>-n</string><string>` + InstalledExe + `</string><string>tray</string></array>+<key>ProgramArguments</key><array><string>/usr/bin/sudo</string><string>-n</string><string>` + InstalledExe() + `</string><string>tray</string></array><key>RunAtLoad</key><true/><key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict><key>ThrottleInterval</key><integer>30</integer>diff --git a/internal/platform/install_darwin.go b/internal/platform/install_darwin.goindex 9c19c80..b128b0b 100644--- a/internal/platform/install_darwin.go+++ b/internal/platform/install_darwin.go@@ -25,23 +25,44 @@ func Install(uninstall bool) error {return errors.New("run: sudo net-merge install")}if uninstall {- for _, p := range []string{sudoersPath, InstalledExe} {+ exe := InstalledExe()+ removeOurLink()+ for _, p := range []string{sudoersPath, exePreferred} {+ if p == exePreferred && !rootFile(p) {+ continue // Homebrew's link or someone else's file, not our copy+ }if err := os.Remove(p); err != nil && !os.IsNotExist(err) {return err}}- fmt.Println("removed " + sudoersPath + " and " + InstalledExe + ". Turn off start at sign-in with `net-merge autostart off`.")+ if err := os.RemoveAll(filepath.Dir(filepath.Dir(exeFallback))); err != nil {+ return err+ }+ fmt.Println("removed " + sudoersPath + " and " + exe + ". Turn off start at sign-in with `net-merge autostart off`.")return nil}user := os.Getenv("SUDO_USER")if user == "" || user == "root" || !safeUser.MatchString(user) {return errors.New("run it through sudo from your own account: sudo net-merge install")}- if err := copyRootOwned(InstalledExe); err != nil {+ exe := exePreferred+ if rootOnly(filepath.Dir(exePreferred)) != nil {+ exe = exeFallback+ if err := os.MkdirAll(filepath.Dir(exeFallback), 0o755); err != nil {+ return err+ }+ }+ if err := copyRootOwned(exe); err != nil {return err}+ if exe == exeFallback {+ linkIntoPath()+ } else {+ removeOurLink()+ os.RemoveAll(filepath.Dir(filepath.Dir(exeFallback))) // an older fallback copy would shadow this one+ }rule := fmt.Sprintf("# Written by `net-merge install`: %s may start the tray without a password.\n"+- "%s ALL=(root) NOPASSWD: %s tray, %s cleanup\n", user, user, InstalledExe, InstalledExe)+ "%s ALL=(root) NOPASSWD: %s tray, %s cleanup\n", user, user, exe, exe)tmp := sudoersPath + ".tmp"if err := os.WriteFile(tmp, []byte(rule), 0o440); err != nil {return err@@ -54,14 +75,13 @@ func Install(uninstall bool) error {if err := os.Rename(tmp, sudoersPath); err != nil {return err}- fmt.Printf("installed %s and %s.\nStart the tray with `net-merge tray` (no password), and at sign-in with `net-merge autostart on`.\n", InstalledExe, sudoersPath)+ fmt.Printf("installed %s and %s.\nStart the tray with `net-merge tray` (no password), and at sign-in with `net-merge autostart on`.\n", exe, sudoersPath)return nil}-// copyRootOwned puts this binary at dst, root:wheel 0755, refusing if any directory above it-// could be changed by a non-root user (the copy is run as root, so that would be a root hole).-func copyRootOwned(dst string) error {- for d := filepath.Dir(dst); d != "/"; d = filepath.Dir(d) {+// rootOnly fails if dir or any directory above it could be changed by a non-root user.+func rootOnly(dir string) error {+ for d := dir; d != "/"; d = filepath.Dir(d) {fi, err := os.Stat(d)if err != nil {return err@@ -70,6 +90,47 @@ func copyRootOwned(dst string) error {return fmt.Errorf("%s is writable by non-root users; refusing to install a root-run binary there", d)}}+ return nil+}++// rootFile reports whether p is a regular file owned by root: a copy `net-merge install` made.+func rootFile(p string) bool {+ fi, err := os.Lstat(p)+ if err != nil || !fi.Mode().IsRegular() {+ return false+ }+ st, ok := fi.Sys().(*syscall.Stat_t)+ return ok && st.Uid == 0+}++// linkIntoPath makes `net-merge` in /usr/local/bin point at the fallback copy, unless something+// else (Homebrew's link) is there already. It replaces an old root-owned copy from an earlier install.+func linkIntoPath() {+ if fi, err := os.Lstat(exePreferred); err == nil {+ if target, _ := os.Readlink(exePreferred); fi.Mode()&os.ModeSymlink != 0 && target == exeFallback {+ return+ }+ if !rootFile(exePreferred) {+ return+ }+ os.Remove(exePreferred)+ }+ os.Symlink(exeFallback, exePreferred) // best effort: the tray finds the copy without it+}++// removeOurLink removes the /usr/local/bin link linkIntoPath made.+func removeOurLink() {+ if target, err := os.Readlink(exePreferred); err == nil && target == exeFallback {+ os.Remove(exePreferred)+ }+}++// copyRootOwned puts this binary at dst, root:wheel 0755, refusing if any directory above it+// could be changed by a non-root user (the copy is run as root, so that would be a root hole).+func copyRootOwned(dst string) error {+ if err := rootOnly(filepath.Dir(dst)); err != nil {+ return err+ }src, err := os.Executable()if err != nil {return errdiff --git a/internal/platform/platform_darwin.go b/internal/platform/platform_darwin.goindex 93db50c..8d6da06 100644--- a/internal/platform/platform_darwin.go+++ b/internal/platform/platform_darwin.go@@ -60,8 +60,20 @@ func RedirectStd(f *os.File) {unix.Dup2(int(f.Fd()), 2)}-// InstalledExe is where `net-merge install` puts the root-owned copy that sudoers allows.-const InstalledExe = "/usr/local/bin/net-merge"+// Where `net-merge install` puts the root-owned copy that sudoers allows: /usr/local/bin when only+// root can write there, else /opt/net-merge/bin (Intel Macs, where Homebrew owns /usr/local/bin).+const (+ exePreferred = "/usr/local/bin/net-merge"+ exeFallback = "/opt/net-merge/bin/net-merge"+)++// InstalledExe is the root-owned copy `net-merge install` made.+func InstalledExe() string {+ if _, err := os.Stat(exeFallback); err == nil {+ return exeFallback+ }+ return exePreferred+}// RelaunchElevated replaces this process with itself run as root: sudo in a terminal, the// administrator password dialog otherwise. It only returns on failure.@@ -90,8 +102,8 @@ func RelaunchElevated(args []string, hidden bool) error {// applies when the tray was started without flags.func RelaunchTray(args []string, hidden bool) error {if len(args) == 1 && args[0] == "tray" {- if exec.Command("/usr/bin/sudo", "-n", "-l", InstalledExe, "tray").Run() == nil {- return syscall.Exec("/usr/bin/sudo", []string{"sudo", "-n", InstalledExe, "tray"}, os.Environ())+ if exe := InstalledExe(); exec.Command("/usr/bin/sudo", "-n", "-l", exe, "tray").Run() == nil {+ return syscall.Exec("/usr/bin/sudo", []string{"sudo", "-n", exe, "tray"}, os.Environ())}}return RelaunchElevated(args, hidden)diff --git a/scripts/build-repos.sh b/scripts/build-repos.shindex f8a4f13..bfb5d77 100755--- a/scripts/build-repos.sh+++ b/scripts/build-repos.sh@@ -67,6 +67,9 @@ cat > "$OUT/index.html" <<HTML<h1>net-merge packages</h1><p>Use all your internet connections at once. <a href="https://github.com/rohit267/net-merge">Project on GitHub</a>.Signing key fingerprint: <code>$KEY</code>.</p>+<h2>Any Linux or macOS: one line</h2>+<pre>curl -fsSL https://raw.githubusercontent.com/rohit267/net-merge/main/install.sh | sh</pre>+<p>It uses your package manager when it can. Or set it up by hand:</p><h2>Debian, Ubuntu, Mint, Pop!_OS, Raspberry Pi OS</h2><pre>curl -fsSL $BASE/apt/key.gpg | sudo tee /usr/share/keyrings/net-merge.gpg >/dev/nullecho "deb [signed-by=/usr/share/keyrings/net-merge.gpg] $BASE/apt stable main" | sudo tee /etc/apt/sources.list.d/net-merge.listdiff --git a/scripts/macos-smoke.sh b/scripts/macos-smoke.shindex 5d4e3ef..9cdb876 100755--- a/scripts/macos-smoke.sh+++ b/scripts/macos-smoke.sh@@ -65,6 +65,20 @@ sleep 1sudo "$BIN" cleanup >/dev/null[ "$(scoped_defaults)" = 0 ] && pass "cleanup removed the leftover scoped defaults" || fail "scoped defaults left after cleanup"+# The runner's /usr/local/bin is writable by its user, like an Intel Mac with Homebrew, so this takes+# the /opt/net-merge/bin path.+echo "== install: a root-owned copy and the passwordless rule, then uninstall"+if sudo "$BIN" install; then+ exe=$(readlink -f /usr/local/bin/net-merge)+ sudo -n -l "$exe" tray >/dev/null && pass "passwordless rule for $exe tray" || fail "no passwordless rule for $exe tray"+ [ "$(stat -f %u "$exe")" = 0 ] && pass "the installed copy is owned by root" || fail "the installed copy is not owned by root"+ sudo "$BIN" uninstall >/dev/null+ [ ! -e /etc/sudoers.d/net-merge ] && [ ! -e /opt/net-merge ] && [ ! -L /usr/local/bin/net-merge ] &&+ pass "uninstall removed the rule and the copy" || fail "uninstall left files behind"+else+ fail "sudo net-merge install failed"+fi+echo[ "$fails" -eq 0 ] && echo "ALL CHECKS PASSED" || echo "$fails CHECK(S) FAILED"exit "$fails"