]> gitweb.morketsmerke.org Git - idle.git/commitdiff
Poprawienie błedu związanego z instalacją konkretnego kontenera, dodanie obsługi...
authorxf0r3m <jakubstasinski@protonmail.com>
Sat, 15 Jul 2023 13:40:41 +0000 (15:40 +0200)
committerxf0r3m <jakubstasinski@protonmail.com>
Sat, 15 Jul 2023 13:40:41 +0000 (15:40 +0200)
idle.sh

diff --git a/idle.sh b/idle.sh
index 3f07b9408ae26509751b2071fde40df4f79580f7..f76325019d86671c8a2744211653ca167ab1357f 100644 (file)
--- a/idle.sh
+++ b/idle.sh
@@ -58,30 +58,52 @@ function idle-list-containers() {
 
 function idle-fetch-containers() {
 
+  rpmGrepOpts='-E rpm.sh|fedora.sh|opensuse.sh|alt.sh';
+  debGrepOpts='deb.sh';
+  otherGrepOpts='-v -e rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh';
+
   function create-container() {
     containerName=$1;
-    containerImagePath=$(grep $containerName $DATABASE | cut -d ";" -f 1);
-    startupScript=$(grep $containerName $DATABASE | cut -d ";" -f 4);
-    echo "lxc launch $containerImagePath $containerName";
-    echo "lxc file push ${HOME}/idle/$startupScript ${containerName}/root/${startupScript}";
-    echo "lxc exec $containerName /bin/bash /root/${startupScript}";
-    echo "Container is ready for work.";
+    if grep -q $containerName $DATABASE; then 
+      containerImagePath=$(grep $containerName $DATABASE | cut -d ";" -f 1);
+      startupScript=$(grep $containerName $DATABASE | cut -d ";" -f 4);
+      echo "lxc launch $containerImagePath $containerName";
+      echo "lxc file push ${HOME}/idle/$startupScript ${containerName}/root/${startupScript}";
+      echo "lxc exec $containerName /bin/bash /root/${startupScript}";
+      echo "Container is ready for work.";
+    else
+      echo "Given container name doesn't exist in project database";
+    fi
   }
   
   function list-containers() {
-    for contName in $(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do
+    containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
+    for contName in $containerNameList; do
       echo -e "    $contName";
     done
   }
 
+  function mass-create-container() {
+    containerNameList=$(grep $@ $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}');
+    for contName in $containerNameList; do
+      create-container $contName;
+    done 
+  }
+
   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 $debGrepOptions;
+    elif [ "$1" = "--rpm" ]; then
+      mass-create-container $rpmGrepOptions;
+    elif [ "$1" = "--other" ]; then
+      mass-create-container $otherGrepOptions;
     else
-      $contName=$1;
+      contName=$1;
       create-container $contName;
     fi 
   else
@@ -98,20 +120,13 @@ function idle-fetch-containers() {
     echo;
     echo "Groups:";
     echo -e "  --deb - based on APT package manager";
-    grepOpts="deb.sh";
-    list-containers $grepOpts;
-    #for contName in $(grep 'deb.sh' $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do
-    #  echo -e "\t\t $contName";
-    #done
+    list-containers $debGrepOpts;
     echo -e "  --rpm - based on RPM package manager";
     grepOpts='-E rpm.sh|fedora.sh|opensuse.sh|alt.sh';
-    list-containers $grepOpts;
-    #for contName in $(grep -E 'rpm.sh|fedora.sh|opensuse.sh|alt.sh' $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do
-    #  echo -e "\t\t $contName";
-    #done
+    list-containers $rpmGrepOpts;
     echo -e "  --other - other containers not fit to above groups:";
-    grepOpts='-v -E rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh';
-    list-containers $grepOpts;
+    grepOpts='-v -e rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh';
+    list-containers $otherGrepOpts;
     return 1;
   fi
 }