]> gitweb.morketsmerke.org Git - idle.git/commitdiff
Wdrożenie funkcji 'idle-get-container-name-list' zwracającej listę nazw kontenerów...
authorxf0r3m <jakubstasinski@protonmail.com>
Wed, 9 Aug 2023 08:58:13 +0000 (10:58 +0200)
committerxf0r3m <jakubstasinski@protonmail.com>
Wed, 9 Aug 2023 08:58:13 +0000 (10:58 +0200)
idle.sh

diff --git a/idle.sh b/idle.sh
index cb556900b4c16efffacb58f5ad49d07ec48c6a82..da590503d776ab673bce4b6c0f58867d015ee4df 100644 (file)
--- a/idle.sh
+++ b/idle.sh
@@ -39,12 +39,31 @@ function idle-lxd-init() {
   cat $HOME/idle/idle_preseed.yaml | sudo lxd init --preseed;
 }
 
+
+function idle-get-container-name-list() {
+  rpmGrepOpts='-E rocky.sh|fedora.sh|opensuse.sh';
+  debGrepOpts='deb.sh';
+  otherGrepOpts='-v -E rocky.sh|fedora.sh|opensuse.sh|deb.sh';
+  if [ "$1" = "--deb" ]; then
+    echo $(grep $debGrepOpts $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
+  elif [ "$1" = "--rpm" ]; then
+    echo $(grep $rpmGrepOpts $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
+  elif [ "$1" = "--other" ]; then
+    echo $(grep $otherGrepOpts $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
+  elif [ "$1" = "--all" ]; then
+    echo $(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}');
+  elif echo $1 | grep -q '\,'; then
+    echo $(echo $1 | sed 's/,/ /g');
+  fi
+}
+
 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
+    containerNameList=$(idle-get-container-name-list --all);
+    for container in $containerNameList; do
       if lxc info $container >> /dev/null 2>&1; then
         installed="\e[32m\u2714\e[0m";
       else
@@ -88,18 +107,16 @@ function idle-fetch-containers() {
   }
   
   function list-containers() {
-    containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
+    containerNameList=$(idle-get-container-name-list $1);
     for contName in $containerNameList; do
       echo -e "    $contName";
     done
   }
 
+
+
   function mass-create-container() {
-    if echo $1 | grep -q '\,'; then
-      containerNameList=$(echo $1 | sed 's/,/ /g');
-    else
-      containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
-    fi
+    containerNameList=$(idle-get-container-name-list $1);
     for contName in $containerNameList; do
       create-container $contName;
     done 
@@ -115,18 +132,7 @@ function idle-fetch-containers() {
     exit 1;
   else
     if [ "$1" ]; then
-      if [ "$1" = "--all" ]; then
-        containerNameList=$(cut -d ";" -f 3 $DATABASE | awk '{printf $1" "}');
-        for contName in $containerNameList; do
-          create-container $contName; 
-        done
-      elif [ "$1" = "--deb" ]; then
-        mass-create-container $debGrepOpts;
-      elif [ "$1" = "--rpm" ]; then
-        mass-create-container $rpmGrepOpts;
-      elif [ "$1" = "--other" ]; then
-        mass-create-container $otherGrepOpts;
-      elif echo $1 | grep -q '\,'; then
+      if echo $1 | grep -q '\-\-'; then
         mass-create-container $1;
       else
         contName=$1;
@@ -175,3 +181,5 @@ function idle-rm-container() {
   containerName=$1;
   lxc delete -f $containerName;
 }
+
+