diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2026-01-04 22:59:49 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2026-01-04 22:59:49 +0530 |
| commit | 0b3f6a14ea950529efd8a298b5939481744c0ecc (patch) | |
| tree | d21e3bc3eab12b636f96e4412fb77c07803a3b70 | |
| parent | 6b2cb30a1ae24149d0059e6441296a20d0528adb (diff) | |
| download | home-manager-config-0b3f6a14ea950529efd8a298b5939481744c0ecc.tar.gz home-manager-config-0b3f6a14ea950529efd8a298b5939481744c0ecc.zip | |
Added convenience to automatically start and stopped cloudflare warp
| -rw-r--r-- | modules/scripts/default.nix | 20 | ||||
| -rw-r--r-- | modules/scripts/warp-start.sh | 48 | ||||
| -rw-r--r-- | modules/scripts/warp-stop.sh | 38 |
3 files changed, 96 insertions, 10 deletions
diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index 8cf1447..c460658 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -6,18 +6,18 @@ "${config.home.homeDirectory}/scripts" ]; - home.file."scripts/system-monitor" = - lib.mkIf - (config.tools.bottom.enable && - config.tools.nvtop.enable && - config.tools.tmux.enable && - config.tools.kitty.enable) - { - text = '' + home.file = let + shellScript = path: { + text = '' #!${pkgs.bash}/bin/bash -${builtins.readFile ./system-monitor.sh} +${builtins.readFile path} ''; - executable = true; + executable = true; + }; + in { + "scripts/system-monitor" = shellScript ./system-monitor.sh; + "scripts/warp-start" = shellScript ./warp-start.sh; + "scripts/warp-stop" = shellScript ./warp-stop.sh; }; }; } diff --git a/modules/scripts/warp-start.sh b/modules/scripts/warp-start.sh new file mode 100644 index 0000000..28b9457 --- /dev/null +++ b/modules/scripts/warp-start.sh @@ -0,0 +1,48 @@ +set -euo pipefail + +# Optional: where to log the daemon +LOGFILE="/var/log/warp-svc.log" + +start_daemon() { + if ! pgrep -x warp-svc >/dev/null 2>&1; then + echo "Starting warp-svc daemon..." + sudo nohup warp-svc >>"$LOGFILE" 2>&1 & + sleep 2 + else + echo "warp-svc already running." + fi +} + +is_registered() { + if warp-cli status 2>&1 | grep -qi "Registration missing"; then + return 1 + fi + return 0 +} + +register_client() { + echo "Registering client..." + warp-cli registration new +} + +connect_client() { + echo "Connecting to WARP..." + warp-cli connect +} + +main() { + start_daemon + + if ! is_registered; then + register_client + else + echo "Client already registered." + fi + + connect_client + + echo "Current status:" + warp-cli status +} + +main "$@" diff --git a/modules/scripts/warp-stop.sh b/modules/scripts/warp-stop.sh new file mode 100644 index 0000000..c374c8a --- /dev/null +++ b/modules/scripts/warp-stop.sh @@ -0,0 +1,38 @@ +set -euo pipefail + +stop_daemon() { + if systemctl list-unit-files | grep -q '^warp-svc\.service'; then + echo "Stopping warp-svc via systemd..." + sudo systemctl stop warp-svc.service + return + fi + + if pgrep -x warp-svc >/dev/null 2>&1; then + echo "Killing warp-svc process..." + sudo pkill -x warp-svc + else + echo "warp-svc is not running." + fi +} + +disconnect_client() { + echo "Disconnecting from WARP..." + if warp-cli status 2>&1 | grep -qi "Connected"; then + sudo warp-cli disconnect + echo "Disconnected." + else + echo "WARP is already disconnected." + fi +} + +main() { + disconnect_client + stop_daemon + + echo "Final status:" + warp-cli status || true + sudo systemd-resolve --flush-caches + sudo systemctl restart systemd-resolved +} + +main "$@" |
