1
0
Fork 0
dotfiles/configs/configs.clj

91 lines
3.3 KiB
Clojure
Raw Normal View History

#!/usr/bin/env bb
(require
'[babashka.fs :as fs]
2023-12-29 09:23:31 -05:00
'[clojure.string :as str]
'[clojure.tools.cli :refer [parse-opts]])
(def parsed-params (parse-opts *command-line-args* {}))
(def script-base-dir (first (:arguments parsed-params)))
(if (nil? script-base-dir)
(throw (Exception. "error: script base dir needs to be provided as first arg!")))
2023-12-01 16:02:46 -05:00
(def user (System/getenv "SUDO_USER"))
2023-12-29 09:23:31 -05:00
(if (nil? user)
(throw (Exception. "error: script needs to be executed with sudo!")))
(def home (str "/home/" user))
;;todo: import from base.clj
(defn- safe-sh [& commands]
(as-> (apply shell/sh commands) $
(if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
2023-12-01 16:02:46 -05:00
(defn- safe-sh-as-user [& commands]
(safe-sh "su" "-c" (str/join " " (map #(if (str/includes? % " ") (str "\"" % "\"") %) commands)) user))
(defn- setup-spacemacs []
;; installing spacemacs
(println "setting up spacemacs..")
(-> (fs/file (str home "/.emacs.d")) (fs/delete-tree))
2023-12-15 07:39:04 -05:00
(safe-sh-as-user "git" "clone" "https://github.com/syl20bnr/spacemacs" (str home "/.emacs.d"))
(println "spacemacs set up"))
(defn- setup-android-scripts []
2023-12-01 16:02:46 -05:00
(let [android-scripts-dir (str home "/Projects/android-scripts")]
(-> (fs/file android-scripts-dir) (fs/delete-tree))
2023-12-01 16:02:46 -05:00
(fs/create-dirs android-scripts-dir)
2023-12-29 09:23:31 -05:00
(safe-sh "chown" "-R" (str user ":" user) android-scripts-dir)
(safe-sh-as-user "git" "clone" "ssh://git@git.schro.fi:4242/schrofi/android-scripts.git" android-scripts-dir)))
2023-12-01 16:02:46 -05:00
2024-11-17 07:25:48 -05:00
(defn- link-config-files []
(println "setting gtk theme..")
2023-12-29 09:23:31 -05:00
(safe-sh-as-user "ln" "-fs" (str script-base-dir "/configs/config-files/gtk-config") "~/.gtkrc-2.0")
(println "linking wallpaper..")
(safe-sh-as-user "ln" "-fs" (str script-base-dir "/configs/config-files/wallpaper.jpg") "~/Pictures/wallpaper.jpg")
2024-11-17 07:41:55 -05:00
(safe-sh-as-user "ln" "-fs" (str script-base-dir "/configs/config-files/bspwm-config") "~/.config/bspwm/bspwmrc")
(safe-sh-as-user "ln" "-fs" (str script-base-dir "/configs/config-files/picom-config") "~/.config/picom/picom.conf")
(safe-sh-as-user "ln" "-fs" (str script-base-dir "/configs/config-files/alacritty-config") "~/.config/alacritty/alacritty.toml")
(safe-sh-as-user "ln" "-fs" (str script-base-dir "/configs/config-files/sxhkd-config") "~/.config/sxhkd/sxhkdrc"))
2023-12-29 09:23:31 -05:00
(defn- setup-system-services []
(println "setting up system services..")
2024-01-05 07:54:42 -05:00
;;todo: user services
(safe-sh "ln" "-fs" "/etc/sv/bluetoothd" "/var/service")
2024-01-05 07:54:42 -05:00
(safe-sh "usermod" "-a" "-G" "bluetooth" user))
2023-12-01 16:02:46 -05:00
2024-11-17 07:25:48 -05:00
(defn- install-fish-functions []
;;todo: symlink files in fish-functions to .config/fish/functions
)
2023-12-01 16:02:46 -05:00
2024-11-17 07:25:48 -05:00
(println "applying configuration..")
2024-01-05 07:54:42 -05:00
(setup-spacemacs)
;;change shell to fish
(safe-sh "chsh" "-s" "/usr/bin/fish" user)
(println "changed shell to fish")
2024-11-17 07:25:48 -05:00
(println "setting up fish functions..")
(install-fish-functions)
(safe-sh-as-user "git" "config" "--global" "user.name" "Florian Schrofner")
(safe-sh-as-user "git" "config" "--global" "user.email" "florian@schro.fi")
(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)
(println "set up android scripts")
2024-01-05 07:54:42 -05:00
(setup-system-services)
(println "set up system services")
2024-11-17 07:25:48 -05:00
(link-config-files)
(println "configuration applied")