1
0
Fork 0

fix git user data

master
Florian Schrofner 2023-12-01 22:02:46 +01:00
parent 1674039e36
commit 67c0a8ded4
Signed by: schrofi
GPG Key ID: 576B512668FB44EE
3 changed files with 43 additions and 28 deletions

View File

@ -1,4 +1,13 @@
#!/usr/bin/env bb
(require
'[clojure.string :as str])
;;executes shell command but throws exception on error ;;executes shell command but throws exception on error
(defn- safe-sh [& commands] (defn- safe-sh [& commands]
(as-> (apply shell/sh commands) $ (as-> (apply shell/sh commands) $
(if (= (:exit $) 0) $ (throw (Exception. (:err $)))))) (if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
;;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))

View File

@ -2,18 +2,17 @@
(require (require
'[babashka.fs :as fs] '[babashka.fs :as fs]
'[clojure.tools.cli :refer [parse-opts]] '[clojure.string :as str])
'[clojure.string :as string])
(def user (System/getenv "SUDO_USER"))
;;todo: import from base.clj ;;todo: import from base.clj
(defn- safe-sh [& commands] (defn- safe-sh [& commands]
(as-> (apply shell/sh commands) $ (as-> (apply shell/sh commands) $
(if (= (:exit $) 0) $ (throw (Exception. (:err $)))))) (if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
(def cli-options (defn- safe-sh-as-user [& commands]
[["-u" "--user USER" "The user to set up"]]) (safe-sh "su" "-c" (str/join " " (map #(if (str/includes? % " ") (str "\"" % "\"") %) commands)) user))
(def options (:options (parse-opts *command-line-args* cli-options)))
(defn- setup-spacemacs [user home] (defn- setup-spacemacs [user home]
;; installing spacemacs ;; installing spacemacs
@ -23,7 +22,12 @@
(safe-sh "chown" (str user ":" user) "-R" (str home "/.emacs.d")) (safe-sh "chown" (str user ":" user) "-R" (str home "/.emacs.d"))
(println "spacemacs set up")) (println "spacemacs set up"))
(if-let [user (:user options)] (defn- setup-android-scripts [user home]
(let [android-scripts-dir (str home "/Projects/android-scripts")]
(fs/create-dirs android-scripts-dir)
(safe-sh "git" "clone" "ssh://git@git.schro.fi:4242/schrofi/android-scripts.git" android-scripts-dir)
(safe-sh "chown" (str user ":" user) "-R" android-scripts-dir)))
(let [home (str "/home/" user)] (let [home (str "/home/" user)]
;;todo: fetch spacemacs ;;todo: fetch spacemacs
;;todo: disable locking when closing lid on ac ;;todo: disable locking when closing lid on ac
@ -35,9 +39,17 @@
(safe-sh "chsh" "-s" "/usr/bin/fish" user) (safe-sh "chsh" "-s" "/usr/bin/fish" user)
(println "changed shell to fish") (println "changed shell to fish")
(safe-sh "git" "config" "--global" "user.name" "Florian Schrofner") (safe-sh-as-user "git" "config" "--global" "user.name" "Florian Schrofner")
(safe-sh "git" "config" "--global" "user.email" "florian@schro.fi") (safe-sh-as-user "git" "config" "--global" "user.email" "florian@schro.fi")
(println "changed git user data") (println "changed git user data")
;;creating projects dir
(let [projects-dir (str home "/Projects")]
(fs/create-dirs projects-dir)
(safe-sh "chown" (str user ":" user) "-R" projects-dir)
(println "created project directory"))
(setup-android-scripts user home)
(println "set up android scripts")
(println "configuration applied")) (println "configuration applied"))
(println "error: must provide a user to set up"))

View File

@ -1,20 +1,14 @@
#!/usr/bin/env bb #!/usr/bin/env bb
(require (require
'[babashka.fs :as fs] '[babashka.fs :as fs])
'[clojure.tools.cli :refer [parse-opts]]
'[clojure.string :as string])
;;todo: import from base.clj ;;todo: import from base.clj
(defn- safe-sh [& commands] (defn- safe-sh [& commands]
(as-> (apply shell/sh commands) $ (as-> (apply shell/sh commands) $
(if (= (:exit $) 0) $ (throw (Exception. (:err $)))))) (if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
(def cli-options (def user (System/getenv "SUDO_USER"))
[["-u" "--user USER" "The user to set up"]])
(def options (:options (parse-opts *command-line-args* cli-options)))
(def user (:user options))
(def home (str "/home/" user)) (def home (str "/home/" user))
(def packages { (def packages {