add image install support fkts
This commit is contained in:
parent
66b0b12c1d
commit
c376e31d55
3 changed files with 63 additions and 0 deletions
17
src/dda/image/alpine.clj
Normal file
17
src/dda/image/alpine.clj
Normal file
|
@ -0,0 +1,17 @@
|
|||
(ns dda.image.alpine
|
||||
(:require
|
||||
[babashka.tasks :as tasks]))
|
||||
|
||||
(defn upgrade-system! []
|
||||
(tasks/shell ["apk" "-U" "upgrade"]))
|
||||
|
||||
(defn cleanup-container! []
|
||||
(tasks/shell ["rm" "-f" "/root/.ssh/authorized_keys"])
|
||||
(tasks/shell ["rm" "-f" "/root/.ssh/authorized_keys2"])
|
||||
(tasks/shell ["apk" "cache" "clean"])
|
||||
(tasks/shell ["bash" "-c" "rm -rf /tmp/*"])
|
||||
(tasks/shell ["bash" "-c" "find /var/cache -type f -exec rm -rf {} \\;"])
|
||||
(tasks/shell ["bash" "-c" "find /var/log/ -name '*.log' -exec rm -f {} \\;"]))
|
||||
|
||||
(defn cleanupAmi []
|
||||
(cleanup-container!))
|
24
src/dda/image/install.clj
Normal file
24
src/dda/image/install.clj
Normal file
|
@ -0,0 +1,24 @@
|
|||
(ns dda.image.install
|
||||
(:require [babashka.tasks :as tasks]))
|
||||
|
||||
(defn curl-and-check!
|
||||
[filename artifact-url sha256-url]
|
||||
(let [filepath (str "/tmp/" filename)]
|
||||
(tasks/shell "curl" "-SsLo" filepath artifact-url)
|
||||
(tasks/shell "curl" "-SsLo" "/tmp/checksum" sha256-url)
|
||||
(tasks/shell "bash" "-c" (str "echo \" " filepath "\"|tee -a /tmp/checksum"))
|
||||
;(tasks/shell "sha256sum" "-c" "--status" "/tmp/checksum")
|
||||
))
|
||||
|
||||
(defn tar-install!
|
||||
[filename binname]
|
||||
(let [filepath (str "/tmp/" filename)]
|
||||
(tasks/shell "tar" "-C" "/tmp" "-xzf" filepath)
|
||||
(tasks/shell "install" "-m" "0740" "-o" "root" "-g" "root" (str "/tmp/" binname) "/usr/local/bin/")))
|
||||
|
||||
(defn install!
|
||||
[filename & {:keys [mod target-name] :or {mod "0740"}}]
|
||||
(let [final-target-name (if (some? target-name) target-name filename)]
|
||||
(tasks/shell "install" "-m" mod "-o" "root" "-g" "root"
|
||||
(str "/tmp/" filename)
|
||||
(str "/usr/local/bin/" final-target-name))))
|
22
src/dda/image/ubuntu.clj
Normal file
22
src/dda/image/ubuntu.clj
Normal file
|
@ -0,0 +1,22 @@
|
|||
(ns dda.image.ubuntu
|
||||
(:require [babashka.tasks :as tasks]))
|
||||
|
||||
(defn upgrade-system! []
|
||||
(tasks/shell ["apt" "update"])
|
||||
(tasks/shell ["apt" "-qqy" "upgrade"]))
|
||||
|
||||
(defn cleanup-container! []
|
||||
(tasks/shell ["rm" "-f" "/root/.ssh/authorized_keys"])
|
||||
(tasks/shell ["rm" "-f" "/root/.ssh/authorized_keys2"])
|
||||
(tasks/shell ["apt" "clean"])
|
||||
(tasks/shell ["apt" "-qqy" "autoremove" "--purge"])
|
||||
(tasks/shell ["apt" "-qqy" "autoclean"])
|
||||
(tasks/shell ["rm" "-rf" "/var/lib/apt/lists/"])
|
||||
(tasks/shell ["bash" "-c" "rm -rf /tmp/*"])
|
||||
(tasks/shell ["bash" "-c" "find /var/cache -type f -exec rm -rf {} \\;"])
|
||||
(tasks/shell ["bash" "-c" "find /var/log/ -name '*.log' -exec rm -f {} \\;"]))
|
||||
|
||||
(defn cleanupAmi []
|
||||
(tasks/shell ["rm" "-f" "/home/ubuntu/.ssh/authorized_keys"])
|
||||
(tasks/shell ["rm" "-f" "/home/ubuntu/.ssh/authorized_keys2"])
|
||||
(cleanup-container!))
|
Loading…
Reference in a new issue