]> gitweb.morketsmerke.org Git - idle.git/commitdiff
Dodanie nowej funkcji do idle.sh: idle-list-containers
authorxf0r3m <jakubstasinski@protonmail.com>
Fri, 14 Jul 2023 18:23:44 +0000 (20:23 +0200)
committerxf0r3m <jakubstasinski@protonmail.com>
Fri, 14 Jul 2023 18:23:44 +0000 (20:23 +0200)
idle.sh

diff --git a/idle.sh b/idle.sh
index f8d09e3fcb9f1f3e7cc1430a6e34f6235f355afa..6abb9812a826566e0df91568cd06d177df2fb579 100644 (file)
--- a/idle.sh
+++ b/idle.sh
@@ -1,6 +1,9 @@
 #!/bin/bash
 
 export DATABASE=/usr/share/idle/database.csv;
+RED="\e[31m";
+GREEN="\e[32m";
+ENDCOLOR="\e[0m";
 
 function idle-size() {
        total=0;
@@ -36,7 +39,18 @@ function idle-lxd-init() {
   cat $HOME/idle/idle_preseed.yaml | sudo lxd init --preseed;
 }
 
-#function idle-list-containers() {
-#  for container in $(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}'); do
-#  done
-#}
+function idle-list-containers() {
+  if ! lxc profile show default | grep -q 'idle'; then
+    echo -e "${RED}LXD isn't initialized. You must run 'idle-lxd-init' firs${ENDCOLOR}";
+    exit 1;
+  else
+    for container in $(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}'); do
+      if lxc info $container >> /dev/null; then
+        installed="\e[32m\u2714\e[0m";
+      else
+        installed="\e[31m\u2716\e[0m";
+      fi
+      echo -e "$container $installed"; 
+    done
+  fi
+}