]> gitweb.morketsmerke.org Git - idle.git/commitdiff
Włącznie do idle.sh get_image_size jako idle-size
authorxf0r3m <jakubstasinski@protonmail.com>
Fri, 14 Jul 2023 15:37:50 +0000 (17:37 +0200)
committerxf0r3m <jakubstasinski@protonmail.com>
Fri, 14 Jul 2023 15:37:50 +0000 (17:37 +0200)
get_image_size [deleted file]
idle.sh [new file with mode: 0644]

diff --git a/get_image_size b/get_image_size
deleted file mode 100755 (executable)
index 07ee8b3..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-
-filename=$1;
-
-function get_image_size() {
-       total=0;
-       size_suffix="MB";
-       for remote in $(cut -d ";" -f 1 $1 | awk '{printf $1" "}'); do
-               image_size=$(/usr/bin/lxc image info $remote | grep '^Size' | awk '{printf $2" "}')
-               float_size=$(echo $image_size | grep -o '^[0-9*\.]*');
-               total=$(echo "$total + $float_size" | bc -l);   
-               echo "$remote = $image_size";
-       done
-       csize_total=$(echo "$(cut -d ";" -f 2 $1 | grep '^[0-9\.]*' | awk '{printf $1" "}' | sed -s 's/ /+/g')0" | bc -l);
-       if [ $(echo $total | cut -d "." -f 1) -gt 1024 ]; then
-               total=$(echo "$total / 1024" | bc -l | cut -c 1-4);
-               csize_total=$(echo "$csize_total / 1024" | bc -l | cut -c 1-4);
-               size_suffix="GB";
-       fi
-       echo "Total: ${total}${size_suffix}";
-       echo "Aprox. container size: ${csize_total}${size_suffix}";
-}
-
-get_image_size $filename;
-#ile będą wazyc kontenery:
-#1. Trzeba pobrać jeden kontenr i sprawdzić jego rozmiar
-#2. Następnie od rozmiaru kontenera odjąć romiar obrazu
-#3. Ile procent wielkości obrazu wynosi różnica tych wartości
-#4. Następnie dodać ten % do wielkości obrazu
diff --git a/idle.sh b/idle.sh
new file mode 100644 (file)
index 0000000..df6e3ab
--- /dev/null
+++ b/idle.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+export DATABASE=/usr/share/idle/database.csv;
+
+function idle-size() {
+       total=0;
+       size_suffix="MB";
+       for remote in $(cut -d ";" -f 1 $DATABASE | awk '{printf $1" "}'); do
+               image_size=$(/usr/bin/lxc image info $remote | grep '^Size' | awk '{printf $2" "}')
+               float_size=$(echo $image_size | grep -o '^[0-9*\.]*');
+               total=$(echo "$total + $float_size" | bc -l);   
+               echo "$remote = $image_size";
+       done
+       csize_total=$(echo "$(cut -d ";" -f 2 $DATABASE | grep -o '^[0-9\.]*' | awk '{printf $1" "}' | sed -s 's/ /+/g')0" | bc -l);
+       if [ $(echo $total | cut -d "." -f 1) -gt 1024 ]; then
+               total=$(echo "$total / 1024" | bc -l | cut -c 1-4);
+               csize_total=$(echo "$csize_total / 1024" | bc -l | cut -c 1-4);
+               size_suffix="GB";
+       fi
+       echo "Total: ${total}${size_suffix}";
+       echo "Aprox. containers size: ${csize_total}${size_suffix}";
+}
+