]> gitweb.morketsmerke.org Git - idle.git/commitdiff
Dodanie funkcji 'idle-fetch-container' do skryptu 'idle.sh'
authorxf0r3m <jakubstasinski@protonmail.com>
Sat, 15 Jul 2023 10:51:49 +0000 (12:51 +0200)
committerxf0r3m <jakubstasinski@protonmail.com>
Sat, 15 Jul 2023 10:51:49 +0000 (12:51 +0200)
idle.sh

diff --git a/idle.sh b/idle.sh
index dd80dc4da1a5d1cbceedbfaaeeb0cccbacf312fd..b867f4bc7eb74997334a79a255f374969d325c4e 100644 (file)
--- a/idle.sh
+++ b/idle.sh
@@ -55,3 +55,63 @@ function idle-list-containers() {
     done
   fi
 }
+
+function idle-fetch-containers() {
+
+  function create-container() {
+    containerName=$1;
+    containerImagePath=$(grep $name $DATABASE | cut -d ";" -f 1);
+    startupScript=$(grep $name $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.";
+  }
+  
+  function list-containers() {
+    for contName in $(grep $1 $DATABASE | cut -d ";" -f 3 | awk '{printf $1" "}'); do
+      echo -e "\t\t $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
+    else
+      $contName=$1;
+      create-container $contName;
+    fi 
+  else
+    echo "idle-fetch-containers - fetch IDLE containers";
+    echo "IDLE Project @ 2023 morketsmerke.org";
+    echo;
+    echo "Usage: ";
+    echo "$ idle-fetch-containers <--all/container_name/group_containers>";
+    echo;
+    echo "Containers name:";
+    for contName in $(cut -d ";" -f 1 $DATABASE | awk '{printf $1" "}'); do
+      echo -e "\t${contName}";
+    done
+    echo;
+    echo "Groups:";
+    echo -e "\t --deb - based on APT package manager (like Debian or Ubuntu)";
+    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
+    echo -e "\t --rpm - based on RPM package manager (like CentOS or Fedora)";
+    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
+    echo -e "\t --other - other containers not fit to above group (like Arch or Gentoo)";
+    grepOpts="-v -E 'rpm.sh|fedora.sh|opensuse.sh|alt.sh|deb.sh'";
+    list-containers $grepOpts;
+    return 1;
+  fi
+}