diff options
Diffstat (limited to 'QoL')
| -rw-r--r-- | QoL/switch-proxy.clj | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/QoL/switch-proxy.clj b/QoL/switch-proxy.clj new file mode 100644 index 0000000..4911b71 --- /dev/null +++ b/QoL/switch-proxy.clj @@ -0,0 +1,33 @@ +#!/usr/bin/env bb + +(require '[clojure.java.shell :refer [sh]] + '[babashka.process :refer [process tokenize]]) + +(defn process-running? [name] + (let [{:keys [exit]} (sh "pgrep" "-x" name)] + (= exit 0))) + +(defn kill-process [name] + (when (process-running? name) + (println (str "Stopping " name "...")) + (sh "pkill" "-x" name))) + +(defn start-daemon [cmd-str] + (println (str "Starting " cmd-str "...")) + (process (tokenize cmd-str) {:out :discard :err :discard :detach true})) + +(let [sb-running (process-running? "sing-box") + mi-running (process-running? "mihomo")] + + (cond + mi-running + (do + (kill-process "mihomo") + (start-daemon "sing-box run -c /Users/eltrac/.config/sing-box/config.json")) + + :else + (do + (kill-process "sing-box") + (start-daemon "mihomo"))) + + (println "Switch complete.")) |
