1
0
Fork 0
dotfiles/base/base.clj

17 lines
477 B
Clojure
Raw Permalink Normal View History

2023-12-01 16:02:46 -05:00
#!/usr/bin/env bb
(require
'[clojure.string :as str])
2023-12-29 09:23:31 -05:00
(def user (System/getenv "SUDO_USER"))
;;executes shell command but throws exception on error
(defn- safe-sh [& commands]
(as-> (apply shell/sh commands) $
(if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
2023-12-01 16:02:46 -05:00
;;executes command as user calling this script with sudo
(defn- safe-sh-as-user [& commands]
(safe-sh "su" "-c" (str/join " " (map #(if (str/includes? % " ") (str "\"" % "\"") %) commands)) user))
2023-12-29 09:23:31 -05:00