From 51d537e03ad877566f00af3c6a1c00340512ac65 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Thu, 12 Mar 2026 18:48:40 +0530 Subject: Using spaces instead of tabs --- modules/scripts/default.nix | 62 +++++++++++++------------- modules/scripts/system-monitor.sh | 2 +- modules/scripts/warp-start.sh | 94 +++++++++++++++++++-------------------- modules/scripts/warp-stop.sh | 90 ++++++++++++++++++------------------- 4 files changed, 124 insertions(+), 124 deletions(-) (limited to 'modules/scripts') diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index 21b8399..c90703c 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -1,35 +1,35 @@ { config, lib, pkgs, ... }: { - config = { - home.sessionPath = [ - "${config.home.homeDirectory}/scripts" - ]; - - home.file = let - shellScript = path: { - text = '' -#!${pkgs.bash}/bin/bash -${builtins.readFile path} -''; - executable = true; - }; - in { - "scripts/system-monitor" = - lib.mkIf - (config.tools.bottom.enable && - config.tools.nvtop.enable && - config.tools.tmux.enable && - config.tools.kitty.enable) - (shellScript ./system-monitor.sh); - "scripts/warp-start" = - lib.mkIf - config.tools.cloudflare-warp.enable - (shellScript ./warp-start.sh); - "scripts/warp-stop" = - lib.mkIf - config.tools.cloudflare-warp.enable - (shellScript ./warp-stop.sh); - }; - }; + config = { + home.sessionPath = [ + "${config.home.homeDirectory}/scripts" + ]; + + home.file = let + shellScript = path: { + text = '' + #!${pkgs.bash}/bin/bash + ${builtins.readFile path} + ''; + executable = true; + }; + in { + "scripts/system-monitor" = + lib.mkIf + (config.tools.bottom.enable && + config.tools.nvtop.enable && + config.tools.tmux.enable && + config.tools.kitty.enable) + (shellScript ./system-monitor.sh); + "scripts/warp-start" = + lib.mkIf + config.tools.cloudflare-warp.enable + (shellScript ./warp-start.sh); + "scripts/warp-stop" = + lib.mkIf + config.tools.cloudflare-warp.enable + (shellScript ./warp-stop.sh); + }; + }; } diff --git a/modules/scripts/system-monitor.sh b/modules/scripts/system-monitor.sh index fed9ce9..951428c 100644 --- a/modules/scripts/system-monitor.sh +++ b/modules/scripts/system-monitor.sh @@ -3,7 +3,7 @@ SESSION="system-monitor" kitty @ set-font-size -- -4 cleanup() { - kitty @ set-font-size -- +4 + kitty @ set-font-size -- +4 } trap cleanup EXIT INT TERM diff --git a/modules/scripts/warp-start.sh b/modules/scripts/warp-start.sh index a1f3c76..bafbe84 100644 --- a/modules/scripts/warp-start.sh +++ b/modules/scripts/warp-start.sh @@ -4,68 +4,68 @@ LOGFILE="/var/log/warp-svc.log" DAEMON_TIMEOUT=30 # seconds start_daemon() { - if ! pgrep -x warp-svc >/dev/null 2>&1; then - echo "Starting warp-svc daemon..." - sudo nohup warp-svc >>"$LOGFILE" 2>&1 & - else - echo "warp-svc already running." - fi + if ! pgrep -x warp-svc >/dev/null 2>&1; then + echo "Starting warp-svc daemon..." + sudo nohup warp-svc >>"$LOGFILE" 2>&1 & + else + echo "warp-svc already running." + fi } wait_for_daemon() { - echo "Waiting for warp-svc to become ready..." - for ((i=1; i<=DAEMON_TIMEOUT; i++)); do - if warp-cli status >/dev/null 2>&1; then - echo "warp-svc is ready." - return 0 - fi - sleep 1 - done - - echo "ERROR: warp-svc did not become ready within ${DAEMON_TIMEOUT}s" >&2 - exit 1 + echo "Waiting for warp-svc to become ready..." + for ((i=1; i<=DAEMON_TIMEOUT; i++)); do + if warp-cli status >/dev/null 2>&1; then + echo "warp-svc is ready." + return 0 + fi + sleep 1 + done + + echo "ERROR: warp-svc did not become ready within ${DAEMON_TIMEOUT}s" >&2 + exit 1 } is_registered() { - if warp-cli status 2>&1 | grep -qi "Registration missing"; then - return 1 - fi - return 0 + if warp-cli status 2>&1 | grep -qi "Registration missing"; then + return 1 + fi + return 0 } register_client() { - echo "Registering client..." - sudo warp-cli registration new + echo "Registering client..." + sudo warp-cli registration new } connect_client() { - echo "Connecting to WARP..." - sudo warp-cli connect + echo "Connecting to WARP..." + sudo warp-cli connect } main() { - [[ "${EUID:-$(id -u)}" -eq 0 ]] || { - if [[ -t 2 ]]; then - echo -e "\e[31mERROR:\e[0m Must be run as root" >&2 - else - echo "ERROR: Must be run as root" >&2 - fi - exit 1 - } - - start_daemon - wait_for_daemon - - if ! is_registered; then - register_client - else - echo "Client already registered." - fi - - connect_client - - echo "Current status:" - warp-cli status + [[ "${EUID:-$(id -u)}" -eq 0 ]] || { + if [[ -t 2 ]]; then + echo -e "\e[31mERROR:\e[0m Must be run as root" >&2 + else + echo "ERROR: Must be run as root" >&2 + fi + exit 1 + } + + start_daemon + wait_for_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 index 9fdf238..95fdc7e 100644 --- a/modules/scripts/warp-stop.sh +++ b/modules/scripts/warp-stop.sh @@ -1,57 +1,57 @@ set -euo pipefail stop_daemon() { - echo "Stopping warp-svc process..." - - if pgrep -x warp-svc >/dev/null 2>&1; then - sudo pkill -x warp-svc - else - echo "warp-svc is not running." - return 0 - fi - - echo "Waiting for warp-svc to stop..." - for _ in {1..30}; do - if ! pgrep -x warp-svc >/dev/null 2>&1; then - echo "warp-svc stopped." - return 0 - fi - sleep 1 - done - - echo "ERROR: warp-svc did not stop in time" >&2 - exit 1 + echo "Stopping warp-svc process..." + + if pgrep -x warp-svc >/dev/null 2>&1; then + sudo pkill -x warp-svc + else + echo "warp-svc is not running." + return 0 + fi + + echo "Waiting for warp-svc to stop..." + for _ in {1..30}; do + if ! pgrep -x warp-svc >/dev/null 2>&1; then + echo "warp-svc stopped." + return 0 + fi + sleep 1 + done + + echo "ERROR: warp-svc did not stop in time" >&2 + exit 1 } 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 + 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() { - [[ "${EUID:-$(id -u)}" -eq 0 ]] || { - if [[ -t 2 ]]; then - echo -e "\e[31mERROR:\e[0m Must be run as root" >&2 - else - echo "ERROR: Must be run as root" >&2 - fi - exit 1 - } - - disconnect_client - stop_daemon - - echo "Final status:" - warp-cli status || true - - echo "Flushing DNS and restarting systemd-resolved..." - sudo systemd-resolve --flush-caches - sudo systemctl restart systemd-resolved + [[ "${EUID:-$(id -u)}" -eq 0 ]] || { + if [[ -t 2 ]]; then + echo -e "\e[31mERROR:\e[0m Must be run as root" >&2 + else + echo "ERROR: Must be run as root" >&2 + fi + exit 1 + } + + disconnect_client + stop_daemon + + echo "Final status:" + warp-cli status || true + + echo "Flushing DNS and restarting systemd-resolved..." + sudo systemd-resolve --flush-caches + sudo systemctl restart systemd-resolved } main "$@" -- cgit v1.2.3