Simple CLI to manage your systemd clash.service and config subscriptions on Linux.

Overview

clashrup

CI Release GitHub release (latest by date)

Simple CLI to manage your systemd clash.service and config subscriptions on Linux.

  • Setup, update, apply overrides, and manage via systemctl. No more, no less.
  • Systemd configuration is created with reference from Running Clash as a service.
  • No root privilege is required. clash.service is created under user systemd by default.
  • clashrup got its name from clashup, a friendly Python alternative.

clashrup setup and update

Installation

Using a one-liner installation script

To install clashrup, inside your terminal, run:

curl -fsSL https://raw.githubusercontent.com/spencerwooo/clashrup/main/install.sh | sh -

By default, this installs the executable to ~/.local/bin/clashrup. Add ~/.local/bin to $PATH if needed.

Downloading clashrup manually

Download prebuilt binary for Linux from releases. Move under /usr/local/bin (system-wide), ~/.local/bin (user) or any other directory in your $PATH. Example:

curl -LO https://github.com/spencerwooo/clashrup/releases/download/{VERSION}/clashrup-{TARGET_ARCH}.tar.gz
tar -xvzf clashrup-{TARGET_ARCH}.tar.gz
mv clashrup ~/.local/bin/clashrup

Building from source

Alternatively, clone the repo and install from source:

cargo install --path .

Usage

Note: Run clashrup --help to see a list of available commands.

To setup and start clash as a systemd service on a new Linux device, run:

clashrup setup

clashrup will first attempt to read from ~/.config/clashrup.toml for config. If not found, it will generate a default one and abort. You would then need to edit the config file and run clashrup setup again. See Configuration for more details.

With a valid config, rerun clashrup setup to download clash binary and remote config.

Ultimately, clashrup setup will attempt to:

  • Download clash binary from remote_clash_binary_url and extract it to clash_binary_path.
  • Download clash remote config from remote_config_url, apply overrides, and save it under clash_config_root.
  • Create a user systemd service file clash.service under user_systemd_root.
  • Enable and start clash.service with systemctl.

You can then check the status of the newly created clash.service running in the background with:

clashrup status

clashrup status

If something doesn't work as expected, you can check the logs with:

clashrup log

clashrup log

To update clash's config from remote and restart clash.service, run:

clashrup update

clashrup update

If you modified config overrides in ~/.config/clashrup.toml, you can apply them to clash's config (~/.config/clash/config.yaml) and restart clash.service with:

clashrup apply

Finally, to stop clash.service and uninstall clash and config, run:

clashrup uninstall

Additionally, you would often need to set environment variables to proxy your traffic through clash within your current terminal session. clashrup provides a convenient command to generate command for exporting environment variables (http_proxy, https_proxy, and all_proxy) for your current session:

clashrup proxy export

Note: For more proxy export commands, check clashrup proxy --help.

Configuration

clashrup stores its config at ~/.config/clashrup.toml by default.

Default config is generated upon setup (with command setup) as:

# ~/.config/clashrup.toml
remote_clash_binary_url = ""
remote_config_url = ""
remote_mmdb_url = "https://cdn.jsdelivr.net/gh/Dreamacro/maxmind-geoip@release/Country.mmdb"
clash_binary_path = "~/.local/bin/clash"
clash_config_root = "~/.config/clash"
user_systemd_root = "~/.config/systemd/user"

[clash_config]
port = 7890
socks_port = 7891
allow_lan = false
bind_address = "*"
mode = "rule"
log_level = "info"
ipv6 = false
external_controller = "127.0.0.1:9090"
# external_ui = "folder"
# secret = ""

where,

  • Field remote_clash_binary_url should point to a downloadable gzipped clash binary URL (example).
  • Field remote_config_url should point to your subscription provider's config URL, which will be downloaded to {clash_config_root}/config.yaml during setup and update.
  • Field clash_config holds a subset of supported config overrides for clash's config.yaml. Inside, port, socks_port, mode, and log_level are required. Other fields are optional. For a full list of configurable clash config.yaml fields, see clash - Configuration.

If clash binary already exists at clash_binary_path, then remote_clash_binary_url will be ignored and setup will skip downloading and setting up clash binary. (In this case, remote_clash_binary_url can be left empty.)

Other fields should be self-explanatory.

Manage clash's settings

We recommend setting external_controller and secret for clash's RESTful API, which can be used to manage clash via external dashboards like yacd.

If you are using this on a remote Linux server, edit ~/.config/clashrup.toml and set external_controller to :9090:

-external_controller = "127.0.0.1:9090"
+external_controller = ":9090"

to allow external access. Run clashrup apply to apply the changes to clash and restart clash. You can now use http://{YOUR_SERVER_IP}:9090 to access the API and control clash's settings.

Warning: Set secret if external access is granted to prevent unauthorized access to your clash API.

Shell completions

clashrup has built-in support for generating shell completion information for the CLI. clashrup will output to stdout completions with clashrup completions <shell>. bash, zsh, and fish are currently supported.

bash

mkdir -p ~/.local/share/bash-completion/completions
clashrup completions bash > ~/.local/share/bash-completion/completions/clashrup

zsh

mkdir -p ~/.local/share/zsh/site-functions
clashrup completions zsh > ~/.local/share/zsh/site-functions/_clashrup

Additionally, add directory ~/.local/share/zsh/site-functions to your fpath where completions are loaded from. Ideally, above where compinit is called in your ~/.zshrc:

+fpath=(~/.local/share/zsh/site-functions $fpath)
 autoload -Uz compinit
 compinit -u

fish

clashrup completions fish > ~/.config/fish/completions/clashrup.fish

License

MIT

Comments
  • After close the SSH connection, the clash service will automatically close

    After close the SSH connection, the clash service will automatically close

    I use this on RaspPie 3 (OS: RHEL Branch), which severs as a proxy server. Following the instructions and setting up, all things run smoothly as expected. However, after closing the SSH connection, the service automatically turns to loaded status. Manually re-login and executiveing the clashrup start , it starts working. Closing the SSH connection, it downs again. I'm wondering how to fix that. BTW, how to enable clashrup start when the system boots? I've tried systemctl enable clash but it returned clash.service not found. Thanks πŸ˜΅β€πŸ’«

    bug 
    opened by LeeSpo 10
  • Support for proxy export for different shell

    Support for proxy export for different shell

    Currently command clashrup proxy export and clashrup proxy export-lan output hard-coded environment variable-based exports, which are specific to bash and related. fish, pwsh and others need different command.

    help wanted good first issue 
    opened by spencerwooo 1
  • Support update / download Country.mmdb

    Support update / download Country.mmdb

    If no Country.mmdb exists, clash will auto-download this file and will not update it.

    Downloading the file from mirror and updating it periodically is necessary.

    enhancement 
    opened by felinae98 1
  • fix(deps): update rust crate clap to 4.1.4

    fix(deps): update rust crate clap to 4.1.4

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | clap | dependencies | patch | 4.1.3 -> 4.1.4 |


    Release Notes

    clap-rs/clap

    v4.1.4

    Compare Source

    Fixes
    • (help) Respect disable_colored_help when using arg_required_else_help
    Performance
    • Speed up compiling arg! macro

    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate toml to 0.6.0

    Update Rust crate toml to 0.6.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | toml | dependencies | minor | 0.5.11 -> 0.6.0 |


    Release Notes

    toml-rs/toml

    v0.6.0

    Compare Source


    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate clap_complete to 4.1.1

    Update Rust crate clap_complete to 4.1.1

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | clap_complete | dependencies | patch | 4.1.0 -> 4.1.1 |


    Release Notes

    clap-rs/clap

    v4.1.1

    Compare Source

    Fixes
    • (bash) Mark cmd variable as local

    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate clap to 4.1.3

    Update Rust crate clap to 4.1.3

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | clap | dependencies | patch | 4.1.1 -> 4.1.3 |


    Release Notes

    clap-rs/clap

    v4.1.3

    Compare Source

    Fixes
    • (error) Improve suggested flag/value/subcommand when two share a long preifx
    • (error) When suggesting one of several subcommands, use the plural subcommands, rather than subcommand

    v4.1.2

    Compare Source

    Fixes
    • In documentation, refer to get_flag, rather than get_one::<bool>

    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate toml to 0.5.11

    Update Rust crate toml to 0.5.11

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | toml | dependencies | patch | 0.5.10 -> 0.5.11 |


    Release Notes

    toml-rs/toml

    v0.5.11

    Compare Source


    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate serde_yaml to 0.9.17

    Update Rust crate serde_yaml to 0.9.17

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | serde_yaml | dependencies | patch | 0.9.16 -> 0.9.17 |


    Release Notes

    dtolnay/serde-yaml

    v0.9.17

    Compare Source

    • Improve Debug representation of some error messages

    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate clap to 4.1.1

    Update Rust crate clap to 4.1.1

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | clap | dependencies | patch | 4.1.0 -> 4.1.1 |


    Release Notes

    clap-rs/clap

    v4.1.1

    Compare Source

    Fixes
    • (error) Small softening attempt for "unexpected argument" error

    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate clap to 4.1.0

    Update Rust crate clap to 4.1.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | clap | dependencies | minor | 4.0.32 -> 4.1.0 |


    Release Notes

    clap-rs/clap

    v4.1.0

    Compare Source

    Compatibility

    MSRV changed to 1.64.0

    For apps with custom --help and --version flags:

    • Descriptions for --help and --version changed

    When apps have errors imitating clap's error style:

    • Error message style was changed, including
      • Moving away from "did you mean" to tips
      • Leading letter is lower case
      • "For more" added some punctuation
    Features
    • ArgMatches::get_occurrences support for argument values to be grouped by their occurrence
    Fixes
    • (derive) Allow upgrade_from when arguments / subcommands are explicitly marked as required
    • (help) Try be more clearer and succinct with --help and --version (also helps with overflow)
    • (error) Try to be more clearer and succinct with error messages
    • (error) Officially adopt an error style guide

    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • fix(deps): update rust crate tokio to 1.25

    fix(deps): update rust crate tokio to 1.25

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | tokio (source) | dependencies | minor | 1.24 -> 1.25 |


    Release Notes

    tokio-rs/tokio

    v1.25.0: Tokio v1.25.0

    1.25.0 (January 28, 2023)
    Fixed
    Added
    Changed
    • fs: increase maximum read buffer size to 2MiB (#​5397)

    v1.24.1: Tokio v1.24.1

    Compare Source

    This release fixes a compilation failure on targets without AtomicU64 when using rustc older than 1.63. (#​5356)


    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • fix(deps): update rust crate toml to 0.7.0

    fix(deps): update rust crate toml to 0.7.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | toml | dependencies | minor | 0.6.0 -> 0.7.0 |


    Release Notes

    toml-rs/toml

    v0.7.0

    Compare Source


    Configuration

    πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    Open

    These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

    Detected dependencies

    cargo
    Cargo.toml
    • clap 4.1.4
    • clap_complete 4.1.1
    • colored 2.0.0
    • serde 1.0.152
    • toml 0.6.0
    • flate2 1.0
    • shellexpand 3.0.0
    • openssl 0.10
    • serde_yaml 0.9.17
    • local-ip-address 0.5.1
    • reqwest 0.11
    • futures-util 0.3
    • indicatif 0.17
    • tokio 1.24
    github-actions
    .github/workflows/ci.yml
    • actions/checkout v3
    • Swatinem/rust-cache v2
    .github/workflows/release.yml
    • ClementTsang/cargo-action v0.0.3
    • svenstaro/upload-release-action v2

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
Releases(v0.2.6)
Owner
Spencer (Shangbo Wu)
πŸŽ“ PhD Student at Beijing Institute of Technology
Spencer (Shangbo Wu)
Fake rest is a fake API generator using a config file to help you develop clients.

About Fake-Rest is a fake API generator using a config file to help you develop clients. It's EASY AS HELL. Usage It's very simple to use. just create

Benyamin Eskandari 9 Feb 1, 2023
IDP2P is a peer-to-peer identity protocol which enables a controller to create, manage and share its own proofs as well as did documents

IDP2P Experimental, inspired by ipfs, did:peer and keri Background See also (related topics): Decentralized Identifiers (DIDs) Verifiable Credentials

null 5 Oct 31, 2022
wireguard tool to manage / generate configuration. Maintain one yaml configuration file to quickly build wireguard network.

wgx wireguard tool to manage / generate configuration. Maintain one yaml configuration file to quickly build wireguard network. Usage wgx --h USAGE:

yinheli 6 Nov 3, 2022
ZeroNS: a name service centered around the ZeroTier Central API

ZeroNS: a name service centered around the ZeroTier Central API ZeroNS provides names that are a part of ZeroTier Central's configured networks; once

ZeroTier, Inc. 327 Dec 20, 2022
Modular IPC-based desktop launcher service

Pop Launcher Modular IPC-based desktop launcher service, written in Rust. Desktop launchers may interface with this service via spawning the pop-launc

Pop!_OS 125 Dec 23, 2022
Open Internet Service to store transaction history for NFTs/Tokens on the Internet Computer

CAP - Certified Asset Provenance Transaction history & asset provenance for NFT’s & Tokens on the Internet Computer CAP is an open internet service pr

Psychedelic 42 Nov 10, 2022
Cover is an open internet service for canister code verification on the Internet Computer

Cover Cover (short for Code Verification) is an open internet service that helps verify the code of canisters on the Internet Computer. Visit our webs

Psychedelic 14 Oct 31, 2022
Prometheus instrumentation service for the NGINX RTMP module.

nginx-rtmp-exporter Prometheus instrumentation service for the NGINX RTMP module. Usage nginx-rtmp-exporter [OPTIONS] --scrape-url <SCRAPE_URL> O

kaylen ✨ 2 Jul 3, 2022
A BitTorrent V1 engine library for Rust (and currently Linux)

cratetorrent Cratetorrent is a Rust crate implementing the BitTorrent version 1 protocol. It can be used as a library and also provides a simple examp

null 401 Dec 28, 2022
Acts as an IRC server and a nostr client. Connect with your IRC client using your nostr private key as the password.

nostr-irc Acts as an IRC server and a nostr client. Connect with your IRC client using your nostr private key as the password. Experimental code, use

null 11 Dec 26, 2022
BLEZ - Asynchronous Bluetooth Low Energy on Linux for Rust

BLEZ - Asynchronous Bluetooth Low Energy on Linux for Rust This library provides an asynchronous, fully featured interface to the Bluetooth Low Energy

Sebastian Urban 40 Oct 21, 2021
Listen to bluetooth headphone keys (Linux only)

What Take action when you use your bluetooth headphone to indicate pause, play, next or previous. For Linux only. Why You can bind global keys to XF86

依云 8 Dec 30, 2022
pam-send-slack-message is a program that publishes messages on slack when a linux server is accessed through ssh.

pam-send-slack-message pam-send-slack-message is a program that publishes messages on slack when the linux server is accessed through ssh. Installatio

Iuri Diniz 2 Aug 17, 2022
Interactive bind/reverse PTY shell with Windows&Linux support implementation by Rust.

Cliws Lightweight interactive bind/reverse PTY shell with Windows&Linux support implementation by Rust. Features WebSocket Full pty support: VIM, SSH,

b23r0 215 Dec 3, 2021
A metrics collection application for Linux machines. Created for MSCS 710 Project at Marist College.

Linux-Metrics-Collector A metrics collection application for Linux machines. Created for MSCS 710 Project at Marist College. Development Environment S

Christopher Ravosa 2 May 2, 2022
Asynchronous Linux SocketCAN - Broadcast Manager support (BCM) with tokio

tokio-socketcan-bcm The Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in k

Marcel 4 Nov 8, 2022
A transparent QUIC to SOCKSv5 proxy on Linux, UDP/QUIC verison of moproxy.

quproxy A transparent QUIC to SOCKSv5 proxy on Linux, UDP/QUIC verison of moproxy. ?? WORKING IN PROGRESS ?? Features: Transparent forward QUIC to ups

Shell Chen 4 Dec 15, 2022
Library + CLI-Tool to measure the TTFB (time to first byte) of HTTP requests. Additionally, this crate measures the times of DNS lookup, TCP connect and TLS handshake.

TTFB: CLI + Lib to Measure the TTFB of HTTP/1.1 Requests Similar to the network tab in Google Chrome or Mozilla Firefox, this crate helps you find the

Philipp Schuster 24 Dec 1, 2022
Tiny CLI application in rust to scan ports from a given IP and find how many are open. You can also pass the amount of threads for that scan

Port Scanner A simple multi-threaded port scanner written in Rust. Usage Run the port scanner by providing the target IP address and optional flags. $

nicolas lopes 4 Aug 29, 2023