From c376e31d55231648983861414a8b4806b72d2c19 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 23 Aug 2024 08:44:49 +0200 Subject: [PATCH] add image install support fkts --- src/dda/image/alpine.clj | 17 +++++++++++++++++ src/dda/image/install.clj | 24 ++++++++++++++++++++++++ src/dda/image/ubuntu.clj | 22 ++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/dda/image/alpine.clj create mode 100644 src/dda/image/install.clj create mode 100644 src/dda/image/ubuntu.clj diff --git a/src/dda/image/alpine.clj b/src/dda/image/alpine.clj new file mode 100644 index 0000000..d2a22ec --- /dev/null +++ b/src/dda/image/alpine.clj @@ -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!)) diff --git a/src/dda/image/install.clj b/src/dda/image/install.clj new file mode 100644 index 0000000..35af5bf --- /dev/null +++ b/src/dda/image/install.clj @@ -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)))) diff --git a/src/dda/image/ubuntu.clj b/src/dda/image/ubuntu.clj new file mode 100644 index 0000000..536d5d5 --- /dev/null +++ b/src/dda/image/ubuntu.clj @@ -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!))